The circuit in question is designed to control multiple servo motors via an Arduino Mega 2560, which receives commands through a Bluetooth module (HC-05). The circuit also includes a piezo buzzer for audio feedback and is powered by a 12V 7Ah battery, with a voltage regulator to provide the necessary 5V to the components. The servos are controlled by PWM signals from the Arduino, and the Bluetooth module facilitates wireless communication.
#include <Servo.h>
#include <SoftwareSerial.h>
// Create servo objects to control each leg
Servo frontLeftLeg;
Servo frontRightLeg;
Servo backLeftLeg;
Servo backRightLeg;
// Set up the Bluetooth communication
SoftwareSerial bluetoothSerial(10, 11); // RX, TX
void setup() {
// Attach the servos to the servo objects
frontLeftLeg.attach(4); // D4 PWM
frontRightLeg.attach(5); // D5 PWM
backLeftLeg.attach(6); // D6 PWM
backRightLeg.attach(7); // D7 PWM
// Start the Bluetooth communication
bluetoothSerial.begin(9600);
}
void loop() {
if (bluetoothSerial.available()) {
String voiceCommand = bluetoothSerial.readString();
if (voiceCommand == "raise front left") {
frontLeftLeg.write(45);
} else if (voiceCommand == "lower front left") {
frontLeftLeg.write(90);
} else if (voiceCommand == "move forward") {
frontLeftLeg.write(30);
backRightLeg.write(30);
delay(500);
// Step 2: Move front right and back left legs to starting position
frontRightLeg.write(90);
backLeftLeg.write(90);
delay(500);
// Step 3: Move front right and back left legs forward
frontRightLeg.write(30);
backLeftLeg.write(30);
delay(500);
// Step 4: Move front left and back right legs to starting position
frontLeftLeg.write(90);
backRightLeg.write(90);
delay(500);
}
// Add more conditions for other voice commands and servo movements
}
}
This code is designed to be uploaded to the Arduino Mega 2560. It initializes four servo objects and a software serial for Bluetooth communication. In the setup()
function, the servos are attached to their respective pins, and the Bluetooth module is initialized. The loop()
function listens for incoming Bluetooth data and moves the servos based on the received voice commands.