In this tutorial we will look at making a mobile controlled robot with Explore Robo platform and we will be using arduino software to program the board.

Working

Whenever we make a call, and press keys, dtmf tones are generated and transmitted. The tones can be easily decoded using a IC like MT8870. This enables a lot of possibilities for wireless control over mobile and telephone. We will use it to control the Explore Robo with DTMF.

Code

  1. /*
  2. Demonstrates reading DTMF keys from chip like MT8870 and driving motors with the help
  3. of L293d bridge; making a Mobile controlled Robot.
  4. Tones are read from the DTMF decoder and keys 2, 8, 4, 6 are used to move the robot
  5. FORWARD, BACKWARD, LEFT and RIGHT.
  6. The DTMF interrupt (INT1) is used to read a new key.
  7.  
  8. Check the below link for connections and other details
  9. http://exploreembedded.com/wiki/index.php?title=Explore_Robo
  10.  
  11. */
  12.  
  13. int MotorLeft[2] = {A0,A1};//Motor Pins
  14. int MotorRight[2] = {A2,A3};//Motor Pins
  15. int Mobile[5]={4,5,6,7};// DTMF mobile tones
  16.  
  17.  
  18. volatile int NewTone_Flag = 0;
  19. int volatile NewTone = 0;
  20.  
  21.  
  22. void setup()
  23. {
  24. MotorInit();
  25. MobileInit();
  26. attachInterrupt(1, CheckTone, FALLING);
  27. //Serial.begin(9600);
  28. //Serial.println("Mobile controlled Robo");
  29. }
  30.  
  31.  
  32. void loop()
  33. {
  34.  
  35.  
  36. if(NewTone_Flag == 1)
  37. {
  38. NewTone = ReadTone();
  39. NewTone_Flag = 0;
  40. }
  41.  
  42. switch(NewTone)
  43. {
  44. case 2: Robot_Forward();break;
  45. case 8: Robot_Backward(); break;
  46. //Notice that in order to use the delay() we need to disable the interuptts.
  47. case 4: noInterrupts(); Robot_Left();delay(1000); Robot_Stop(); NewTone = 0; interrupts(); break;
  48. case 6: noInterrupts(); Robot_Right();delay(1000); Robot_Stop(); NewTone=0; interrupts(); break;
  49. case 5: Robot_Stop();break;
  50. default:Robot_Stop();
  51. }
  52.  
  53. }
  54.  
  55. void CheckTone()
  56. {
  57. NewTone_Flag = 1;
  58. }
  59.  
  60. int ReadTone()
  61. {
  62. int MobileTone=0,i;
  63.  
  64. for(i=0;i<4;i++)
  65. MobileTone|= digitalRead(Mobile[i])<<i;
  66. //MobileTone = (digitalRead(Mobile[3])*8)+ (digitalRead(Mobile[2])*4)+(digitalRead(Mobile[1])*2)+(digitalRead(Mobile[0])*1);
  67. //Serial.print(MobileTone);
  68. return MobileTone;
  69. }
  70.  
  71. void MobileInit()
  72. {
  73. int i;
  74. for(i=0 ; i<5; i++)
  75. {
  76. pinMode(Mobile[i],INPUT);
  77. }
  78. //first pin will be used as interrupt, hence direction set not required.
  79. }
  80.  
  81. //Initialize the motor
  82.  
  83. void MotorInit()
  84. {
  85. int i;
  86. for(i=0 ; i<2; i++)
  87. {
  88. pinMode(MotorLeft[i],OUTPUT);
  89. pinMode(MotorRight[i],OUTPUT);
  90. }
  91. }
  92.  
  93. //Robot Driving Functions
  94. void Robot_Forward()
  95. {
  96. digitalWrite(MotorLeft[0],0);
  97. digitalWrite(MotorLeft[1],1);
  98. digitalWrite(MotorRight[0],1);
  99. digitalWrite(MotorRight[1],0);
  100. }
  101.  
  102. void Robot_Backward()
  103. {
  104. digitalWrite(MotorLeft[0],1);
  105. digitalWrite(MotorLeft[1],0);
  106. digitalWrite(MotorRight[0],0);
  107. digitalWrite(MotorRight[1],1);
  108. }
  109.  
  110. void Robot_Left()
  111. {
  112. digitalWrite(MotorLeft[0],1);
  113. digitalWrite(MotorLeft[1],0);
  114. digitalWrite(MotorRight[0],1);
  115. digitalWrite(MotorRight[1],0);
  116. }
  117.  
  118. void Robot_Right()
  119. {
  120. digitalWrite(MotorLeft[0],0);
  121. digitalWrite(MotorLeft[1],1);
  122. digitalWrite(MotorRight[0],0);
  123. digitalWrite(MotorRight[1],1);
  124. }
  125.  
  126. void Robot_Stop()
  127. {
  128. digitalWrite(MotorLeft[0],0);
  129. digitalWrite(MotorLeft[1],0);
  130. digitalWrite(MotorRight[0],0);
  131. digitalWrite(MotorRight[1],0);
  132. }