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