Devices & Components
Arduino Uno Rev3
DC Motor, Miniature
Jumper wires (generic)
Signal Relay, 5 VDC
Hardware & Tools
Multitool, Screwdriver
Project description
Code
RC Car Code By Aws Alkarmi
arduino
1 2 3int ForwordSignal=A1; 4int BackwordSignal=A4; 5int LEDs=3; 6int ForwordMotor=4; 7int BackwordMotor=12; 8int code1; 9int cod2; 10int FM=0; 11int BM=0; 12int state=0; 13int testRelay=8; 14 15 16 17void setup() { 18 19 Serial.begin(9600); 20 pinMode(ForwordSignal,INPUT); 21 pinMode(BackwordSignal,INPUT); 22 pinMode(ForwordMotor,OUTPUT); 23 pinMode(BackwordMotor,OUTPUT); 24 pinMode(LEDs,OUTPUT); 25 pinMode(testRelay,OUTPUT); 26 27 28} 29 30void loop() { 31 FM=analogRead(ForwordSignal); 32 BM=analogRead(BackwordSignal); 33 34 Serial.println("B"); 35 Serial.println("----"); 36 Serial.println("F"); 37 38 if(FM>200) // 3.3volts ---675 bit 39 { 40 digitalWrite(ForwordMotor,HIGH);// LOW to start the relay 41 digitalWrite(BackwordMotor,LOW); // HIGH to stop the relay 42 digitalWrite(testRelay,LOW); 43 44 state=1; 45 Serial.print("FM is"); 46 Serial.println(FM); 47 48 }else if(BM>200) 49 { 50 digitalWrite(BackwordMotor,HIGH);//very good 51 digitalWrite(ForwordMotor,LOW); 52 ; // HIGH to stop the relay 53 54 Serial.print("BM is"); 55 Serial.println(BM); 56 57 state=2; 58 }else{digitalWrite(ForwordMotor,HIGH); 59 digitalWrite(BackwordMotor,HIGH); 60 digitalWrite(testRelay,HIGH); // HIGH to stop the relay 61 62 }; 63 64 65 66}
Comments
Only logged in users can leave comments