Advertisement
rabirajkhadka

Bluetooth Controlled Wheeled Robot

Sep 25th, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. //This code is tested only for the provided RobotCo App You may need to change the alphabet for the control of the direction of robot.
  2. //Connection: Digital pin 4,5,6,7 to IN1,IN2,IN3,IN4 respectively.
  3.  
  4. char state;
  5. void stp();
  6. void forward();
  7. void left();
  8. void right();
  9. void backward();
  10. void setup()
  11. {
  12. pinMode(4,OUTPUT);
  13. pinMode(5,OUTPUT);
  14. pinMode(6,OUTPUT);
  15. pinMode(7,OUTPUT);
  16. Serial.begin(9600);
  17. }
  18. void loop() {
  19. if(Serial.available() > 0) // Ckeck for command Recieved
  20. {
  21. state = Serial.read();
  22. Serial.println(state);
  23. flag=0;
  24. }
  25. if (state == 's') // Checking Command from User
  26. {
  27. stp();
  28. }
  29. else if (state == 'f')
  30. {
  31. right();
  32. }
  33. else if (state == 'b')
  34. {
  35. left();
  36. }
  37. else if (state == 'l')
  38. {
  39. backward();
  40. }
  41. else if (state == 'r')
  42. {
  43. forward();
  44. }
  45. } //loop() ends here
  46. void forward()
  47. {
  48. digitalWrite(4,HIGH);
  49. digitalWrite(5,LOW);
  50. digitalWrite(6,HIGH);
  51. digitalWrite(7,LOW);
  52. }
  53. void backward()
  54. {
  55. digitalWrite(4,LOW);
  56. digitalWrite(5,HIGH);
  57. digitalWrite(6,LOW);
  58. digitalWrite(7,HIGH);
  59. }
  60. void left()
  61. {
  62. digitalWrite(4,LOW);
  63. digitalWrite(5,HIGH);
  64. digitalWrite(6,HIGH);
  65. digitalWrite(7,LOW);
  66. }
  67. void right()
  68. {
  69. digitalWrite(4,HIGH);
  70. digitalWrite(5,LOW);
  71. digitalWrite(6,LOW);
  72. digitalWrite(7,HIGH);
  73. }
  74. void stp()
  75. {
  76. digitalWrite(4,LOW);
  77. digitalWrite(5,LOW);
  78. digitalWrite(6,LOW);
  79. digitalWrite(7,LOW);
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement