4WD Car L298N + HC05 - mcworkshop

MC        WORKSHOP
Vai ai contenuti

Menu principale:

4WD Car L298N + HC05

Projects

Pin to Pin

Wiring diagram
L298N
IN 1 to pin 10 Arduino
IN 2 to pin 11 Arduino
IN 3 to pin 5 Arduino
IN 4 to pin 6 Arduino
+5 to 5V Arduino
GND to GND Arduino
+12 to power supply ext

HC05
TX to RX
RX to TX
VCC to + 5V
GND to GND

clic to enlarge
Logic level 3V3
The HC05 operates with a 3.3 Volt logic level. Arduino works with a logic level of 5 Volts. Although I have repeatedly tested the HC05 by sending a 5Volt logic state without being damaged, it is preferable to insert a voltage divider.
L'HC05 funziona con un livello logico di 3,3 Volt. Arduino funziona con un livello logico di 5 Volt. Anche se ho testato ripetutamente l'HC05 inviando uno stato logico a 5Volt senza subire danni, è preferibile inserire un divisore di tensione.
V2 = V1 * R2 / (R1+R2)
V2 = 5 * (2200 / 3400)
V2 = 5 * 0.647
V2 = 3,235Volt

Reversal formula
R2 = (R1*V2) / (V1-V2)
R1 = (R2*V1)  / V2
V1 = V2 * (R2+R1) / R2

App

Sketch


/*
 Software open source
 by Marco C.
 maggio 2018 / dicembre 2018
 4WD Car
*/
const int motorA1  = 5;
const int motorA2  = 6;
const int motorB1  = 10;
const int motorB2  = 11;
int state;
int vSpeed = 200;   //speed 0 to 255
void setup() {
 pinMode(motorA1, OUTPUT);
 pinMode(motorA2, OUTPUT);
 pinMode(motorB1, OUTPUT);
 pinMode(motorB2, OUTPUT);
 Serial.begin(9600);
}
void loop() {
 if (Serial.available() > 0) {
   state = Serial.read();
   Stop();
 }
 //GO
 /if HC05 has the letter A
 if (state == 'A') {
   analogWrite(motorA1, vSpeed);
   analogWrite(motorA2, 0);
   analogWrite(motorB1, vSpeed);
   analogWrite(motorB2, 0);
 }
 //BACK
 else if (state == 'B') {
   analogWrite(motorA1, 0);
   analogWrite(motorA2, vSpeed);
   analogWrite(motorB1, 0);
   analogWrite(motorB2, vSpeed);
 }
 //LEFT
 else if (state == 'C') {
   analogWrite(motorA1, 200);
   analogWrite(motorA2, 0);
   analogWrite(motorB1, 0);
   analogWrite(motorB2, 200);
 }
 //RIGHT
 else if (state == 'D') {
   analogWrite(motorA1, 0);
   analogWrite(motorA2, 200);
   analogWrite(motorB1, 200);
   analogWrite(motorB2, 0);
 }
 //STOP
 else if (state == 'E') {
   analogWrite(motorA1, 0);
   analogWrite(motorA2, 0);
   analogWrite(motorB1, 0);
   analogWrite(motorB2, 0);
 }
}
void Stop() {
 analogWrite(motorA1, 0);
 analogWrite(motorA2, 0);
 analogWrite(motorB1, 0);
 analogWrite(motorB2, 0);
}

Sketch II


/*
  Marco Cerani
  4WD
  maggio 2018 V3.2 dicembre 2018 V3.3 - codice open source
*/
#include <SoftwareSerial.h>
#define bluetooth Serial
SoftwareSerial mySerial(0, 1);
 const int motorA1  = 4;
 const int motorA2  = 5;
 const int motorB1  = 10;
 const int motorB2  = 11;
 const int led  = 12;
 const int clacson = 6 ;
 int i=0;
 int j=0;
 int state;
 int vSpeed=200;
void setup() {
   pinMode(motorA1, OUTPUT);
   pinMode(motorA2, OUTPUT);
   pinMode(motorB1, OUTPUT);
   pinMode(motorB2, OUTPUT);
   pinMode(led, OUTPUT);
   pinMode(clacson,OUTPUT);
   Serial.begin(9600);
}
void loop() {
   if(Serial.available() > 0){    
     state = Serial.read();  
     Stop();
   }
   if (state == 'A') {
     analogWrite(motorA1, vSpeed);
     analogWrite(motorA2, 0);
     analogWrite(motorB1, vSpeed);      
     analogWrite(motorB2, 0);    
   }
   else if (state == 'B') {
     analogWrite(motorA1, 0);  
     analogWrite(motorA2, vSpeed);
     analogWrite(motorB1, 0);  
     analogWrite(motorB2, vSpeed);
   }
   else if (state == 'C') {
     analogWrite(motorA1, 200);  
     analogWrite(motorA2, 0);
     analogWrite(motorB1, 0);
     analogWrite(motorB2, 200);
   }
   else if (state == 'D') {
     analogWrite(motorA1, 0);  
     analogWrite(motorA2, 200);
     analogWrite(motorB1, 200);  
     analogWrite(motorB2, 0);    
   }
   else if (state == 'E') {
     if (i==0){  
        digitalWrite(led, HIGH);
        i=1;
     }
     else if (i==1){
        digitalWrite(led, LOW);
        i=0;
     }
     state='n';
   }
   else if (state == 'F'){
     if (j==0){  
       digitalWrite(clacson, HIGH);
        j=1;
     }
     else if (j==1){
        digitalWrite(clacson, LOW);
        j=0;
     }
     state='n';  
   }
   else if (state == 'G'){
       analogWrite(motorA1, 0);  
       analogWrite(motorA2, 0);
       analogWrite(motorB1, 0);  
       analogWrite(motorB2, 0);
       digitalWrite(clacson, LOW);
   }  
}
void Stop() {
 analogWrite(motorA1, 0);  
 analogWrite(motorA2, 0);
 analogWrite(motorB1, 0);
 analogWrite(motorB2, 0);
}

Video

 
Copyright 2015. All rights reserved.
Torna ai contenuti | Torna al menu