Devices & Components
Arduino Nano
HC-05 Bluetooth Module
Custom PCB
Dual H-Bridge motor drivers L293D
Resistor 221 ohm
Software & Tools
Arduino IDE
Project description
Code
Arduino Car Code
c_cpp
1int MSP1 = 3; 2int front = 9; 3int back = 10; 4int left = 11; 5int right = 12; 6int MSP2 = 5; 7 8 9String data, dataT; 10 11void setup() { 12 Serial.begin(9600); 13 Serial.setTimeout(3); 14 15 pinMode(front,OUTPUT); 16 pinMode(back,OUTPUT); 17 pinMode(left,OUTPUT); 18 pinMode(right,OUTPUT); 19 pinMode(MSP1,OUTPUT); 20 pinMode(MSP2,OUTPUT); 21} 22 23void loop() { 24 25 if ( Serial.available()) { 26 data = Serial.readStringUntil('\ \ 27'); 28 29 // Convert from String Object to String. 30 char buf[30]; 31 data.toCharArray(buf, sizeof(buf)); 32 char *p = buf; 33 char *dataC; 34 while ((dataC = strtok_r(p, ":", &p)) != NULL) // delimiter is the semicolon 35 { dataT = String(dataC); 36 Serial.println(dataT); 37 } 38 39 //front 40 if(dataT=="y0"){ 41 digitalWrite(front,LOW); 42 digitalWrite(back,LOW); 43 } 44 else if(dataT=="y1"){ 45 analogWrite(MSP1,75); frontM(); 46 } 47 else if(dataT=="y2"){ 48 analogWrite(MSP1,135); frontM(); 49 } 50 else if(dataT=="y3"){ 51 analogWrite(MSP1,195); frontM(); 52 } 53 else if(dataT=="y4"){ 54 analogWrite(MSP1,255); frontM(); 55 } 56 if(dataT=="y-1"){ 57 analogWrite(MSP1,75); backM(); 58 } 59 else if(dataT=="y-2"){ 60 analogWrite(MSP1,135); backM(); 61 } 62 else if(dataT=="y-3"){ 63 analogWrite(MSP1,195); backM(); 64 } 65 else if(dataT=="y-4"){ 66 analogWrite(MSP1,255); backM(); 67 } 68 if(dataT=="x0"){ 69 Serial.println("off"); 70 digitalWrite(left,LOW);digitalWrite(right,LOW); 71 } 72 else if(dataT=="x2"){ 73 leftM(); 74 } 75 else if(dataT=="x-2"){ 76 rightM(); 77 } 78 79 }//if ends 80}//loop 81 82void frontM(){ 83 digitalWrite(front,HIGH); 84 digitalWrite(back,LOW); 85} 86void backM(){ 87 digitalWrite(back,HIGH); 88 digitalWrite(front,LOW); 89} 90void leftM(){ 91 analogWrite(MSP2,255); 92 digitalWrite(left,HIGH); 93 digitalWrite(right,LOW); 94} 95void rightM(){ 96 analogWrite(MSP2,255); 97 digitalWrite(right,HIGH); 98 digitalWrite(left,LOW); 99}
Downloadable files
Schematics
Schematics
Custom PCB for Arduino Car
Custom PCB for Arduino Car
Schematics
Schematics
Custom PCB for Arduino Car
Custom PCB for Arduino Car
Comments
Only logged in users can leave comments