Session Two
☰ MenuThe aims for this session are:
- Install the Bluetooth module and connect the device with the mobile phone
- Create an APP with MIT App Inventor to control the robot with the mobile
First step: Hardware installation
First of all, it is fundamental to add exta hardware, required to permit the robot to work. The steps to follow to have all prepared are:
- Step 1. Install the Bluetooth module
- Step 2. Install ultrasonic sensor.
After following these steps, the main purposes of the Hardware section of this session have been acomplished as the installation is almost down.
Second step: Software installation
The following code will be sent to the robot through Arduino IDE. With this code, the robot moves depending on the letter it is pressed in the Android App that is going to be built.
//Left Motor connected to 4,5 digitalPins
//Right Motor connected to 10,9 digitalPins
int LMP = 11;
int LMN = 9;
int RMP = 12;
int RMN = 7;
void setup() {
//Motor Pins are OUTPUT
pinMode(LMP, OUTPUT);
pinMode(LMN, OUTPUT);
pinMode(RMP, OUTPUT);
pinMode(RMN, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available()) {
String Direction = Serial.readString();
if (Direction == "F") {
//Move Forward
digitalWrite(LMP, HIGH);
digitalWrite(LMN, LOW);
digitalWrite(RMP, LOW);
digitalWrite(RMN, HIGH);
}
else if (Direction == "B") {
//Move backward
digitalWrite(LMP, LOW);
digitalWrite(LMN, HIGH);
digitalWrite(RMP, HIGH);
digitalWrite(RMN, LOW);
}
else if (Direction == "L") {
//Right Turn
digitalWrite(LMP, LOW);
digitalWrite(LMN, HIGH);
digitalWrite(RMP, LOW);
digitalWrite(RMN, HIGH);
}
else if (Direction == "R") {
//Left Turn
digitalWrite(LMP, HIGH);
digitalWrite(LMN, LOW);
digitalWrite(RMP, HIGH);
digitalWrite(RMN, LOW);
}
else if (Direction == "S") {
//Stop
digitalWrite(LMP, LOW);
digitalWrite(LMN, LOW);
digitalWrite(RMP, LOW);
digitalWrite(RMN, LOW);
}
}
}
Third step: MIT App Inventor
To control the robot with a mobile, it must be created an app
After the App is created, it is installed in an Android device scanning the QR code.
Once it is runned in the mobile, it is able to connect the mobile with the robot (only if the Bluetoth module is working as it is supposed to).