/*
* This Arduino sketch controls a servo motor using commands received via
* a Bluetooth module (HC-05). The Bluetooth module is connected to the
* Arduino's serial pins, and the servo is controlled based on the received
* commands.
*/
#include <Servo.h>
Servo myServo;
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Attach the servo to pin D3
myServo.attach(3);
}
void loop() {
// Check if data is available to read
if (Serial.available() > 0) {
// Read the incoming byte
char command = Serial.read();
// Convert the command to an angle (0-180)
int angle = command - '0';
angle = map(angle, 0, 9, 0, 180);
// Move the servo to the specified angle
myServo.write(angle);
}
}