I am currently facing an issue with transferring data from a slider to an Arduino Uno through Bluetooth.
Please help me identify what is wrong with my code or my application.
This is my Arduino coding:
#include <SoftwareSerial.h>
int In3 = 7;
int In4 = 8;
int ENB = 5;
int SPEED = 100;
SoftwareSerial bluetooth(10, 11); // RX, TX
void setup()
{
Serial.begin(9600);
bluetooth.begin(9600);
bluetooth.print("AT+NAME=Handsome"); // Change "MyDevice" to your desired name
delay(500); // Delay for command execution
pinMode(2, OUTPUT);
pinMode(In3, OUTPUT);
pinMode(In4, OUTPUT);
pinMode(ENB, OUTPUT);
digitalWrite(In3, HIGH);
digitalWrite(In4, LOW);
Serial.print("Ready");
}
void loop()
{
if (bluetooth.available() == 1) {
String MOTOR = bluetooth.readString(); // Read the incoming data
if (MOTOR == "N") {
Serial.println("N");
SPEED = 200;
}
if (MOTOR == "F") {
SPEED = 0;
Serial.println("F");
}
analogWrite(ENB, SPEED);
}
if (bluetooth.available() == 2) {
SPEED = bluetooth.read();
analogWrite(ENB, SPEED);
Serial.println(SPEED);
}
delay(50);