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

  1. #include <Firmata.h>
  2. int MotorLeft[2] = {A0,A1};
  3. int MotorRight[2] = {A2,A3};
  4. void setup()
  5. {
  6. Serial.begin(9600);
  7. MotorInit();
  8. Serial.print("*Explore Robo Mode Computer: Controlled*\n\r");
  9. Serial.println("Commands:\n W->Forward \n S->Backwards \n A->Left \n D->Right");
  10. }
  11. void loop()
  12. {
  13. int command;
  14. command = Serial.read();
  15. switch(command)
  16. {
  17. case 'w': Robot_Forward(); delay(100); break;
  18. case 's': Robot_Backward(); delay(100); break;
  19. case 'a': Robot_Left(); delay(100); break;
  20. case 'd': Robot_Right(); delay(100); break;
  21. //in case the caps lock is ON
  22. case 'W': Robot_Forward(); delay(100); break;
  23. case 'S': Robot_Backward(); delay(100); break;
  24. case 'A': Robot_Left(); delay(100); break;
  25. case 'D': Robot_Right(); delay(100); break;
  26. default: break;
  27. }
  28. }
  29. //Intialize the motor
  30. void MotorInit()
  31. {
  32. int i;
  33. for(i=0 ; i<2; i++)
  34. {
  35. pinMode(MotorLeft[i],OUTPUT);
  36. pinMode(MotorRight[i],OUTPUT);
  37. }
  38. }
  39. //Robot Driving Functions
  40. void Robot_Forward()
  41. {
  42. digitalWrite(MotorLeft[0],0);
  43. digitalWrite(MotorLeft[1],1);
  44. digitalWrite(MotorRight[0],1);
  45. digitalWrite(MotorRight[1],0);
  46. }
  47. void Robot_Backward()
  48. {
  49. digitalWrite(MotorLeft[0],1);
  50. digitalWrite(MotorLeft[1],0);
  51. digitalWrite(MotorRight[0],0);
  52. digitalWrite(MotorRight[1],1);
  53. }
  54. void Robot_Left()
  55. {
  56. digitalWrite(MotorLeft[0],1);
  57. digitalWrite(MotorLeft[1],0);
  58. digitalWrite(MotorRight[0],1);
  59. digitalWrite(MotorRight[1],0);
  60. }
  61. void Robot_Right()
  62. {
  63. digitalWrite(MotorLeft[0],0);
  64. digitalWrite(MotorLeft[1],1);
  65. digitalWrite(MotorRight[0],0);
  66. digitalWrite(MotorRight[1],1);
  67. }