Hi Everyone
I have a interest in Arduino and want to start my new project
I have build a rover/tank/bot
my goal is
- change over to Wifi esp8266
- be able to control Speed
- Temperature to be displayed on the app
- be able to see value of Ultrasonic sensor on app
Perhaps someone have built this configuration before and might assist me and possible a app?
Currently im connecting via Bluetooth using Bluetooth rc controller android app
It works however I cannot control the speed and its not wifi
Hardware
• WiFi Serial Transceiver Module ESP8266
• Logic Level Converter Bi-Directional
• L298 Dual H-Bridge Motor Driver
• Arduino Uno
• DHT11 Temperature sensor
• Ultrasonic sensor
or
• Arduino Pro Mini 328
Code
// Bluetooth-bot v1
// Arduino Robotics unofficial chapter 14
// use Bluetooth Mate serial adapter to receive commands from phone
// Arduino decodes commands into motor movements
// Uses keys "F" = forward, "L" = left, "B" = reverse, and "R" = right
// L298 motor control variables
int M1_A = 12;
int M1_PWM = 11;
int M1_B = 10;
int M2_A = 4;
int M2_PWM = 3;
int M2_B = 2;
// variable to store serial data
int incomingByte = 0;
//////////////////////////////
void setup(){
// Start serial monitor at 9600 bps
Serial.begin(9600);
// declare outputs
pinMode(M1_A, OUTPUT);
pinMode(M1_PWM, OUTPUT);
pinMode(M1_B, OUTPUT);
pinMode(M2_A, OUTPUT);
pinMode(M2_PWM, OUTPUT);
pinMode(M2_B, OUTPUT);
}
////////////////////////////////////
void loop(){
// check for serial data
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte);
// delay 10 milliseconds to allow serial update time
delay(10);
// if byte is equal to "70" or "F", go forward
if (incomingByte == 70){
M1_forward();
M2_forward();
delay(25);
}
// if byte is equal to "82" or "R", go right
else if (incomingByte == 82){
M1_reverse();
M2_forward();
delay(25);
}
// if byte is equal to "76" or "L", go left
else if (incomingByte == 76){
M1_forward();
M2_reverse();
delay(25);
}
// if byte is equal to "66" or "b", go reverse
else if (incomingByte == 66){
M1_reverse();
M2_reverse();
delay(25);
}
// otherwise, stop both motors
else {
M1_stop();
M2_stop();
}
}
}
/////////// motor functions ////////////////
void M1_reverse(){
digitalWrite(M1_B, LOW);
digitalWrite(M1_A, HIGH);
analogWrite(M1_PWM, 250);
}
void M1_forward(){
digitalWrite(M1_A, LOW);
digitalWrite(M1_B, HIGH);
analogWrite(M1_PWM, 250);
}
void M1_stop(){
digitalWrite(M1_B, LOW);
digitalWrite(M1_A, LOW);
digitalWrite(M1_PWM, 0);
}
void M2_forward(){
digitalWrite(M2_B, LOW);
digitalWrite(M2_A, HIGH);
analogWrite(M2_PWM, 250);
}
void M2_reverse(){
digitalWrite(M2_A, LOW);
digitalWrite(M2_B, HIGH);
analogWrite(M2_PWM, 250);
}
void M2_stop(){
digitalWrite(M2_B, LOW);
digitalWrite(M2_A, LOW);
digitalWrite(M2_PWM, 0);
}