How to Build a Robot Car? - Part Four
0


Robotic Education: Connect Arduino to a computer. Plug the Arduino circuit into your computer. Open the Arduino software. This allows you to program your car's movements.
- Arduino software is available for free online.
Step 1: Upload the following code. Type the following program into Arduino. Once finished, upload it into your circuit. This code will cause your car to move forward for 5 seconds, take a right turn, and move forward for another 5 seconds:
int Fmotor=10;// initialize all the motors int Bmotor=9; int Rmotor=6; int Lmotor=5; void setup() { // put your setup code here, to run once: pinMode( Fmotor,OUTPUT);// set them as outputs pinMode( Bmotor,OUTPUT); pinMode( Lmotor,OUTPUT); pinMode( Rmotor,OUTPUT); } void loop() { // put your main code here, to run repeatedly: digitalWrite(Fmotor,HIGH);// code for making the car go straight digitalWrite(Lmotor,HIGH); digitalWrite(Rmotor,LOW);// NEVER SET A MOTOR HIGH ON BOTH PINS digitalWrite(Bmotor,LOW); delay(5000); digitalWrite(Rmotor,HIGH);// Take a right turn digitalWrite(Lmotor,LOW); digitalWrite(Bmotor,LOW); digitalWrite(Fmotor,HIGH); delay(800); digitalWrite(Fmotor,HIGH);// code for making the car go straight digitalWrite(Lmotor,HIGH); digitalWrite(Rmotor,LOW); digitalWrite(Bmotor,LOW); delay(5000); }
Step 2: Start the car. Set the car on a flat surface. Put in the batteries and watch it go! If your battery holder has a switch, flick it to turn the car on and off.
- You can add your own switch by connecting the positive wire of the battery holder to the center pin of an SPST (single pole singe throw) switch. Connect the other pin of the switch to the Vin pin on the Arduino.
Labels:
Keywords:
robotic, robotic education, How to Build a Robot Car, cfp
