Musawer Bidar
![](https://www.google.com/images/icons/product/drive-32.png)
Elevator Pitch
Brief summary of how my project works.
![](https://www.google.com/images/icons/product/drive-32.png)
Demonstration
Demonstration video of my project working.
Bluetooth Modules
To make this project work, I needed a way to send data from my phone to an Arduino. My answer was a Bluetooth Module. These work by transmitting data between two devices, so I could use my phone to send something to an Arduino, which would then take whatever I sent and turn that into a series of actions.
Code
/*
This code is used to control two motors via a wireless bluetooth connection between an android phone and a bluetooth module. The phone sends
a letter which corresponds to a series of movements for the motors
Written by Musawer Bidar
May 28, 2021
Modified code from:
https://www.youtube.com/watch?v=Q36NbjPMV5k
https://learn.adafruit.com/adafruit-arduino-lesson-15-dc-motor-reversing/arduino-code
*/
// Setting variables
int enablePinL = 11;
int in1PinL = 10;
int in2PinL = 9;
int in3PinR = 3;
int in4PinR = 4;
int enablePinR = 5;
// Setting pin modes for each used pin
void setup() {
Serial.begin(9600); // Starts the serial monitor for bluetooth module
pinMode(in1PinL, OUTPUT);
pinMode(in2PinL, OUTPUT);
pinMode(enablePinL, OUTPUT);
pinMode(in3PinR, OUTPUT);
pinMode(in4PinR, OUTPUT);
pinMode(enablePinR, OUTPUT);
}
void loop() {
if(Serial.available()>0)
{
char data= Serial.read(); // reading the data received from the bluetooth module
switch(data)
{
// depending on which pins go high and low change whether the motors spins forward or backward
case 'F': // if letter 'F' received from bluetooth module, do this
analogWrite(enablePinL, 150); // turns on left motor
digitalWrite(in1PinL, LOW);
digitalWrite(in2PinL, HIGH);
analogWrite(enablePinR, 150); // turns on right motor
digitalWrite(in3PinR, LOW);
digitalWrite(in4PinR, HIGH);
break;
case 'B': // if letter 'B' received from bluetooth module, do this
analogWrite(enablePinL, 150); // turns on left motor
digitalWrite(in1PinL, HIGH);
digitalWrite(in2PinL, LOW);
analogWrite(enablePinR, 150); // turns on right motor
digitalWrite(in3PinR, HIGH);
digitalWrite(in4PinR, LOW);
break;
case 'L': // if letter 'L' received from bluetooth module, do this
analogWrite(enablePinL, 150); // turns on left motor
digitalWrite(in1PinL, LOW);
digitalWrite(in2PinL, HIGH);
analogWrite(enablePinR, 150); // turns on right motor
digitalWrite(in3PinR, HIGH);
digitalWrite(in4PinR, LOW);
break;
case 'R': // if letter 'R' received from bluetooth module, do this
analogWrite(enablePinL, 150); // turns on left motor
digitalWrite(in1PinL, HIGH);
digitalWrite(in2PinL, LOW);
analogWrite(enablePinR, 150); // turns on right motor
digitalWrite(in3PinR, LOW);
digitalWrite(in4PinR, HIGH);
break;
default : // if nothing received from bluetooth module
analogWrite(enablePinL, 0); // sets motor to 0 speed, turning it off
digitalWrite(in1PinL, LOW);
digitalWrite(in2PinL, HIGH);
analogWrite(enablePinR, 0); // sets motor to 0 speed, turning it off
digitalWrite(in3PinR, LOW);
digitalWrite(in4PinR, HIGH);
break;
}
}
delay(50);
}