Home automation. In my vacation I wanted to use a servo motor via bluetooth to press a button in my room to turn on the lights. I watched different youtube videos, asked chatGPT but for some reason nothing seemed to work.
Components:
Arduino Uno/Nano (Does it matter?)
HC-05 Bluetooth module
servo motor (Arduino starter kit)
Breadboard
Jumper wires
Connections:
HC-05 to Arduino
VCC to 5v
GND to GND
TXD to RX
RXD to TX
Servo Motor to Arduino
Power to 5v
GND to GND
Signal to digital pin 9
The Baudrate of the HC-05 is set to 9600. I used different apps too. right now I am trying out the "Serial Bluetooth terminal" app on my phone. I have a google pixel 6. I connected all the Hardware, uploaded the code but when I put in a value on the app the servo doesn't move. It says that my phone is connected to the HC-05. I also get no "feedback" from the HC-05 and I think that is a problem, but I am not 100% sure.
Can someone please help me figure out what I am doing wrong and If you have any apps that are better please let me know. (and code)
Thanks.
But as I said before I really don't know what I am supposed to be expecting and I asked ChatGPT for instructions several times and every time similar answers are generated
A button would require a long wire to your switch. I think you can use your smartphone to connect to the HC-05. Here is a beautiful drawing of the information gathered from your question. How it works: Mains power is supplied to an external AC to DC power converter (maybe 12vdc or 5vdc output). That AC-DC converter supplies power to a DC-DC buck converter AND the servo (make sure the servo uses the same voltage potential as the output of the AC-DC power converter). The buck converter also supplies power to the Arduino and the HC05 (make sure the HC05 uses the same voltage as the buck converter output. Setup the HC05 would be best to start. Then write a sketch for the HC-05. Then write a sketch to move the servo. Then merge the sketches. Lights out!
Beautiful drawing but (maybe I missed something) post #1 "implies"
hc-05 uses SoftwareSerial with (on the Arduino side) Rx = Pin 2, Tx = Pin 3
servo signal on pin 9
Connect your Arduino to your computer via USB (make sure there is no power supplies conflict) and add various serial.print() to your code while debugging to visualize what's going on :
#include <SoftwareSerial.h>
#include <Servo.h>
SoftwareSerial bluetooth(2, 3); // RX, TX
Servo myservo;
void setup() {
Serial.begin(115200); // Used to send debugging data to the computer
bluetooth.begin(9600);
myservo.attach(9);
Serial.println("Bluetooth to Servo V1 ready");
}
void loop() {
if (bluetooth.available()) {
int angle = bluetooth.read();
Serial.print("Received from BT: ");
Serial.println(angle);
angle = map(angle, 0, 255, 0, 180);
Serial.print("Sent to servo: ");
Serial.println(angle);
myservo.write(angle);
}
}
I made the line drawing for a different project with the same devices, but using different pins... so it was "ready made" (after making it from scratch).
@xfpd and @Etienne_74 thanks for your help. I got closer, but it's still not working. I connected as told, but now the servo is only making a clicking sound. The app was I think in the beginning giving feedback, but the feedback was just a ? symbol. I don't know if it helps but the HC-05 is blinking twice slowly. I really don't know what I am doing wrong. If you know what I am doing wrong please tell me.