Hello, I am trying to make a small remote controlled Arduino car that connects with bluetooth to the mobile app for the controls. I am using 2 servos attached to the wheels, and a HC-06. Below is what the blocks currently looks like:
However, when i try to press one of the buttons no text is being sent to the Serial Monitor. This is what my code currently looks like:
#include <Servo.h>
Servo leftServo;
Servo rightServo;
void setup() {
Serial.begin(9600); // Initialize the serial communication
leftServo.attach(5); // Attach the left servo to pin
rightServo.attach(6); // Attach the right servo to pin
}
void loop() {
if (Serial.available() > 0) {
String command = Serial.readStringUntil('\n'); // Read the incoming command
// Check the received command and adjust the servos accordingly
if (command == "UP") {
moveForward();
} else if (command == "DOWN") {
moveBackward();
} else if (command == "LEFT") {
turnLeft();
} else if (command == "RIGHT") {
turnRight();
} else if (command == "POWER") {
stopCar();
}
}
}
void moveForward() {
leftServo.write(90); // Adjust the servo angles as needed
rightServo.write(90);
}
void moveBackward() {
leftServo.write(0); // Adjust the servo angles as needed
rightServo.write(0);
}
void turnLeft() {
leftServo.write(0); // Adjust the servo angles as needed
rightServo.write(90);
}
void turnRight() {
leftServo.write(90); // Adjust the servo angles as needed
rightServo.write(0);
}
void stopCar() {
leftServo.write(90); // Set both servos to a neutral position to stop the car
rightServo.write(90);
}
How could I get the buttons to send the text to the Serial Monitor correctly?