Introduction: Make Simple Robot
It's easy to make a simple robot that can be controlled with bleutooth, we will use a robot kit, an arduino uno and a l9110 driver, and a bluetooth module for control.
In the end we will download an android application to control the robot.
Step 1: Connect the Robot Parts
All you need is to connect the parts of the robot
Step 2: Programming Step
For programming we use arduino IDE, and we will connect the bluetooth in pins (10, 11) with SoftwareSerial #include <SoftwareSerial.h>
Step 2 is to init driver pins:
#define MOTOR_A_PWM 5 // Motor A PWM Speed
#define MOTOR_A_DIR 7 // Motor A Direction
#define MOTOR_B_PWM 6 // Motor B PWM Speed
#define MOTOR_B_DIR 8 // Motor B Direction
And now we will write functions to control the robot, the functions we need is up, down, left, right, stop each one of them has one parameter (force)
This is an example for up function:
void up(int force){
digitalWrite( MOTOR_A_DIR, HIGH );
analogWrite( MOTOR_A_PWM, -force );
digitalWrite( MOTOR_B_DIR, HIGH );
analogWrite( MOTOR_B_PWM, -force );
}
For decode the received data by the app we will use arduinojson library
First we need to collect the received data :
while (bluetooth.available()) {
char c = bluetooth.read();
if (c == '\n') { break; }
readString += c;
delay(1);
}
now we can decode the data
if (readString.length() >0) {
Serial.println(readString);
JsonObject& root = jsonBuffer.parseObject(readString);
if (!root.success()) {
Serial.println("parseObject() failed");
return;
}
const String angle = root["angle"];
const String _force = root["force"];
}
You can fined the code in https://github.com/Helektrika/BlueControl
for using this code you will download the app in Google Play: https://goo.gl/GHLe4m