Difference between revisions of "Computer controlled Robot with Arduino"
Line 1: | Line 1: | ||
[[Category:Robotics Tutorials]] | [[Category:Robotics Tutorials]] | ||
=Intro= | =Intro= | ||
+ | {{Box|type=l_green_light|text= | ||
For this tutorial we will be using the [[Explore Robo]] kit. You may go ahead and download the schematics and other details from the link. | For this tutorial we will be using the [[Explore Robo]] kit. You may go ahead and download the schematics and other details from the link. | ||
To give a brief the Robo Controller board has a CP2102 USB to UART(Serial) convertor. We give commands to the robot from the terminal and move it. This is a very simple type and you can easily hack it. The controller board also has a atmega8 MCU with Arduino bootloader, hence we can code it from the Arduino IDE | To give a brief the Robo Controller board has a CP2102 USB to UART(Serial) convertor. We give commands to the robot from the terminal and move it. This is a very simple type and you can easily hack it. The controller board also has a atmega8 MCU with Arduino bootloader, hence we can code it from the Arduino IDE | ||
<br /> | <br /> | ||
+ | }} | ||
+ | =Circuit= | ||
+ | {{Box|type=l_green_light|text= | ||
+ | The schematic for this can be downloaded from [[Explore Robo]] page. However what we need to know to make a computer controlled robot is where the motors are connected to the MCU. Note that these first go to a L293D bridge and then to the actual motors. | ||
+ | }} | ||
+ | |||
+ | =Code= | ||
<syntaxhighlight> | <syntaxhighlight> | ||
#include <Firmata.h> | #include <Firmata.h> |
Revision as of 14:16, 27 August 2014
Intro
For this tutorial we will be using the Explore Robo kit. You may go ahead and download the schematics and other details from the link.
To give a brief the Robo Controller board has a CP2102 USB to UART(Serial) convertor. We give commands to the robot from the terminal and move it. This is a very simple type and you can easily hack it. The controller board also has a atmega8 MCU with Arduino bootloader, hence we can code it from the Arduino IDE
Circuit
The schematic for this can be downloaded from Explore Robo page. However what we need to know to make a computer controlled robot is where the motors are connected to the MCU. Note that these first go to a L293D bridge and then to the actual motors.
Code
#include <Firmata.h> int MotorLeft[2] = {A0,A1}; int MotorRight[2] = {A2,A3}; void setup() { Serial.begin(9600); MotorInit(); Serial.print("*Explore Robo Mode Computer: Controlled*\n\r"); Serial.println("Commands:\n W->Forward \n S->Backwards \n A->Left \n D->Right"); } void loop() { int command; command = Serial.read(); switch(command) { case 'w': Robot_Forward(); delay(100); break; case 's': Robot_Backward(); delay(100); break; case 'a': Robot_Left(); delay(100); break; case 'd': Robot_Right(); delay(100); break; //in case the caps lock is ON case 'W': Robot_Forward(); delay(100); break; case 'S': Robot_Backward(); delay(100); break; case 'A': Robot_Left(); delay(100); break; case 'D': Robot_Right(); delay(100); break; default: break; } } //Intialize the motor void MotorInit() { int i; for(i=0 ; i<2; i++) { pinMode(MotorLeft[i],OUTPUT); pinMode(MotorRight[i],OUTPUT); } } //Robot Driving Functions void Robot_Forward() { digitalWrite(MotorLeft[0],0); digitalWrite(MotorLeft[1],1); digitalWrite(MotorRight[0],1); digitalWrite(MotorRight[1],0); } void Robot_Backward() { digitalWrite(MotorLeft[0],1); digitalWrite(MotorLeft[1],0); digitalWrite(MotorRight[0],0); digitalWrite(MotorRight[1],1); } void Robot_Left() { digitalWrite(MotorLeft[0],1); digitalWrite(MotorLeft[1],0); digitalWrite(MotorRight[0],1); digitalWrite(MotorRight[1],0); } void Robot_Right() { digitalWrite(MotorLeft[0],0); digitalWrite(MotorLeft[1],1); digitalWrite(MotorRight[0],0); digitalWrite(MotorRight[1],1); }