Controlling a Servo Motor via Bluetooth (Arduino UNO/Nano and HC-05)

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

Code:

#include <SoftwareSerial.h>
#include <Servo.h>

SoftwareSerial bluetooth(2, 3); // RX, TX
Servo myservo;

void setup() {
  bluetooth.begin(9600);
  myservo.attach(9);
}

void loop() {
  if (bluetooth.available()) {
    int angle = bluetooth.read();
    angle = map(angle, 0, 255, 0, 180);
    myservo.write(angle);
  }
}

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)

What promt you have given to GPT.

Secondly is your Bluetooth is connecting properly or not Also just try to turn on and off the led to confirm the proper working of the model

1 Like

Standard advice:

Ask the robot again until he has provided the correct result expected by you.
It could be 42.

I just asked Chat GPT for instructions. Step by Step how to do it and followed it. The HC-05 is just blinking on and off

I tried connecting with my phone and then it just disconnects automatically, but the app says that it is connected with the HC-05

But I don't know what to expect. I am relatively new to Arduino and know little. Could you tell me what you mean by 42?

Thanks.:grin::+1:
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

Ya because your final target is one only that why similar answers is bene genrated

Secondly if you are connecting Bluetooth of your hc-05 Do it connect

Which app do you using

Also kindly post the circuit diagram

1 Like

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!

         +---|EXT|--------|USB|---+                    
         |    PWR          A5/SCL |
         |                 A4/SDA | 
         |          UNO      AREF | 
         |                    GND |          ==o===>
         | IOREF          SCK/D13 |        +---|---+
         | RST             DI/D12 |        |SERVO 1|
         | 3V3             DO/D11~|        |    GND|---+
         | +5V                D10~|   +----|SIG VCC|---|-+
         | GND                 D9~|---+    +-------+   | |
   +-----| GND             KEY D8 |------------------+ | |
   |  +--| Vin                 D7 |                  | | |
   |  |  |                     D6~|        +-------+ | | |
   |  |  | A0                  D5~|        | HC-05 | | | |  +---------+   +------+
   |  |  | A1                  D4 |    +---|RXD GND|-|-+ |  |  BUCK   |   |POWER |
   |  |  | A2             INT1/D3 |----+ +-|TXD VCC|-|-|-+  |CONVERTER|   |SUPPLY|
   |  |  | A3             INT0/D2~|-R1k+-+ |STA KEY|-+ | +--|OUT+  IN+|---|+V    |
   |  |  | A4/DA  RS CK DI  TX>D1 |      | +-------+   +-|--|OUT-  IN-|---|-V    |===(mains)===|=
   |  |  | A5/CL  GD D0 5V  RX<D0 |      +-R2k-+       | |  +---------+   +------+
   |  |  +------------------------+      RX=3v3|Vdiv   | |
   +--|----------------------------------------+-------+ | * some HC05 need Vdiv for 3v3 data
      +--------------------------------------------------+

2 Likes

Serial Bluetooth Terminal. The circuit diagram I got from ChatGPT. It doesn't give a photo of it.

Thanks a lot. Could you please give me the code too and which app I should use?

Writing a sketch is for me a problem. I am new to Arduino and can't programm well yet. (Still learning :sweat_smile:)

Do you know which HC-05 you have? Some require a voltage divider on their receive pin.
bluetooth


q

1 Like

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);
  }
}

Yes... I made a mess and will update.... was (0,1) will be changed to (2, 3) and servo was (10) will be (09)

Was it "ready made, to be updated/adapted" or "done from scratch, 10 minute job" ?

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.

Do you have a separate power supply to power the servo or is it powered from the 5V of the Arduino board ? What model of servo is it ?