Last active
April 16, 2020 11:47
-
-
Save Mayoogh/de01a1aa903fe737da34bbf16ab155ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
DIY Simple Arduino Bluetooth Controlled Robot Car | |
Coder - Mayoogh Girish | |
Website - http://mgprojecthub.com/ | |
Download the App : | |
*/ | |
char data = 0; //Variable for storing data | |
int RMA = 8; | |
int RMB = 9; | |
int LMA = 10; | |
int LMB = 11; | |
void setup() | |
{ | |
Serial.begin(9600); //Sets the data rate in bits per second (baud) for serial data transmission | |
pinMode(8, OUTPUT); | |
pinMode(9, OUTPUT); | |
pinMode(10, OUTPUT); | |
pinMode(11, OUTPUT); | |
} | |
void loop() | |
{ | |
if (Serial.available() > 0) | |
{ | |
data = Serial.read(); //Read the incoming data and store it into variable data | |
Serial.print(data); //Print Value of data in Serial monitor | |
Serial.print("\n"); //New line | |
if (data == 'S') | |
stop_(); | |
else if (data == 'F') | |
forward_(); | |
else if (data == 'B') | |
backward_(); | |
else if (data == 'L') | |
left_180(); | |
else if (data == 'R') | |
right_180(); | |
else if (data == 'G') | |
forwardLeft(); | |
else if (data == 'I') | |
forwardRight(); | |
else if (data == 'H') | |
backwardLeft(); | |
else if (data == 'J') | |
backwardRight(); | |
} | |
} | |
void stop_() { | |
Serial.print("STOP"); | |
digitalWrite(LMA, LOW); | |
digitalWrite(LMB, LOW); | |
digitalWrite(RMA, LOW); | |
digitalWrite(RMB, LOW); | |
} | |
void forward_() { | |
Serial.print("FORWARD"); | |
digitalWrite(LMA, HIGH); | |
digitalWrite(LMB, LOW); | |
digitalWrite(RMA, HIGH); | |
digitalWrite(RMB, LOW); | |
} | |
void backward_() { | |
Serial.print("BACKWARD"); | |
digitalWrite(LMA, LOW); | |
digitalWrite(LMB, HIGH); | |
digitalWrite(RMA, LOW); | |
digitalWrite(RMB, HIGH); | |
} | |
void left_180() { | |
Serial.print("LEFT 180"); | |
digitalWrite(LMA, LOW); | |
digitalWrite(LMB, HIGH); | |
digitalWrite(RMA, HIGH); | |
digitalWrite(RMB, LOW); | |
} | |
void right_180() { | |
Serial.print("RIGHT 180"); | |
digitalWrite(LMA, HIGH); | |
digitalWrite(LMB, LOW); | |
digitalWrite(RMA, LOW); | |
digitalWrite(RMB, HIGH); | |
} | |
void forwardLeft() { | |
Serial.print("FORWARD - LEFT"); | |
digitalWrite(LMA, LOW); | |
digitalWrite(LMB, LOW); | |
digitalWrite(RMA, HIGH); | |
digitalWrite(RMB, LOW); | |
} | |
void forwardRight() { | |
Serial.print("FORWARD - RIGHT"); | |
digitalWrite(LMA, HIGH); | |
digitalWrite(LMB, LOW); | |
digitalWrite(RMA, LOW); | |
digitalWrite(RMB, LOW); | |
} | |
void backwardLeft() { | |
Serial.print("BACKWARD - LEFT"); | |
digitalWrite(LMA, LOW); | |
digitalWrite(LMB, LOW); | |
digitalWrite(RMA, LOW); | |
digitalWrite(RMB, HIGH); | |
} | |
void backwardRight() { | |
Serial.print("BACKWARD - RIGHT"); | |
digitalWrite(LMA, LOW); | |
digitalWrite(LMB, HIGH); | |
digitalWrite(RMA, LOW); | |
digitalWrite(RMB, LOW); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment