Last active
March 14, 2020 06:40
-
-
Save samilkorkmaz/b5fa46f10869316f74785ee6d3b23785 to your computer and use it in GitHub Desktop.
Bluetooth control of Rodeo robot
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
//Robolink Rodeo robot bluetooth control. | |
//Arduino Bluetooth RC Car app: https://play.google.com/store/apps/details?id=braulio.calle.bluetoothRCcontroller&hl=en | |
//Robot purchase link: https://www.robolinkmarket.com/arama?q=rodeo | |
#include <SoftwareSerial.h> | |
SoftwareSerial myBlue(0, 1); // RX, TX pins of Arduino Nano. | |
const int motorLeftDir = 2; //motorLeft: m1 | |
const int motorRightDir = 7; //motorRight: m2 | |
const int motorLeftEn = 5; | |
const int motorRightEn = 6; | |
int speed = 100; | |
void setup() { | |
pinMode(motorLeftDir, OUTPUT); | |
pinMode(motorRightDir, OUTPUT); | |
pinMode(motorLeftEn, OUTPUT); | |
pinMode(motorRightEn, OUTPUT); | |
myBlue.begin(9600); | |
Serial.begin(9600); //Note that this value has to be the same as blutooth value | |
} | |
void stop() { | |
digitalWrite(motorLeftDir, LOW); | |
analogWrite(motorLeftEn, 0); | |
digitalWrite(motorRightDir, LOW); | |
analogWrite(motorRightEn, 0); | |
} | |
void moveForward() { | |
digitalWrite(motorLeftDir, HIGH); | |
analogWrite(motorLeftEn, speed); | |
digitalWrite(motorRightDir, HIGH); | |
analogWrite(motorRightEn, speed); | |
} | |
void moveBackward() { | |
digitalWrite(motorLeftDir, LOW); | |
analogWrite(motorLeftEn, speed); | |
digitalWrite(motorRightDir, LOW); | |
analogWrite(motorRightEn, speed); | |
} | |
void turnRight() { | |
digitalWrite(motorLeftDir, HIGH); | |
analogWrite(motorLeftEn, speed); | |
digitalWrite(motorRightDir, HIGH); | |
analogWrite(motorRightEn, 0); | |
} | |
void turnLeft() { | |
digitalWrite(motorLeftDir, HIGH); | |
analogWrite(motorLeftEn, 0); | |
digitalWrite(motorRightDir, HIGH); | |
analogWrite(motorRightEn, speed); | |
} | |
void loop() { | |
if(myBlue.available() > 0) { | |
char val = myBlue.read(); | |
Serial.print(val); | |
Serial.print("\n"); | |
if('F' == val) { | |
moveForward(); | |
Serial.println("moveForward."); | |
} else if('B' == val) { | |
moveBackward(); | |
Serial.println("moveBackward."); | |
} else if('R' == val) { | |
turnRight(); | |
Serial.println("turnRight."); | |
} else if('L' == val) { | |
turnLeft(); | |
Serial.println("turnLeft."); | |
} else if('+' == val) { | |
speed += 10; | |
Serial.println("speed +"); | |
} else if('-' == val) { | |
speed -= 10; | |
Serial.println("speed -"); | |
} else if('S' == val) { | |
stop(); | |
Serial.println("stop."); | |
} | |
} | |
delay(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment