Need help with ESP32 Servo control app

Hello people,

I am working on a project to automate the wooden train track of my son.
the hardware is all working but now i want to add the ESP32-c to the project to control the servo's for flipping the track over so my son can decide to let the trian go straight or left/right.
I found some projects using a HC-05 or HC-06 module, but the ESP32 has wifi and bluetooth on board so i want to use that.
i started to make this project Control ESP32 over Internet using Android App with MIT App Inventor but i want to replace the leds used in this project for a servo.
My question is : is this possible? and can someone help me out how to make it ?

Many thanks in behave

Greetz Stefan my son 7 years old and Martijn

Yes, possible.
Any progress?
Would be good to know some details. How many, what kind of servos.

Hello @martijn_vd_brakel,
since your son is (most probably :grin:!) impatient to see it working, my hint is to consider to use the BT instead of the WiFi (of the ESP).
I guess you have only one ESP and only one AI2 device (phone or pad, running Android OS) connected each other, so the use of the classic BT (i,e. not BLE) is much esier to use and stable, in terms of communcation protocol and amount of examples you can find "everywhere". Another assumption is that you don't need a long distance between the sender and the receiver (approx. max 10 meters).
That said, you can find a huge amount of examples in the community, and specifically on the web sites of @Juan_Antonio ( and @ChrisWard ( together with tutorials and "step-by-step" instructions.
Nevertheless, whether you need specific details, please let us know (as @Usane has already asked) more details on your project, so the let us help you more efficiently.

Thanks both for your reply :smile:

I am working on a project to make wooden traintracks for kids electronic and they can flip tracks over with an app

I found MIT would be great to make an app for it but i sadly did.not find sample projects for the Esp32 .

What i found was projects with the Hc-05 module but thoose are big and unhandy so i found the ESP32c ..small and really good for this project

What i want is to make an app with MiT that controls a S90 mini servo

I therefore need some knobs/flip buttons or something like that in the app to control the servo.

The servo needs to be set to preset degrees so the track will flip same way every time the knob is used

Each track will get its own Esp32 is the idea so my son can use his device to be a train controller ..

I know the esp can handle bluetooth and wifi so that would be great to use bluetooth might be best i think?

Hope this helps a bit?
Image is work in progress..


Greets Martijn

It could just run until it hit a cut-out button, there may have to be allowance for a little over run of the servo (but not the rail point). If you want to control degrees tightly with only the motor, that is stepper motor territory. A simple sounding task but precision is always difficult.

I am making this project with a man i met online in search of making wooden tracks more "real " for kids
He is a great designer and we are having much fun trying it all out and thinker about how to make it all more and more exciting
I there for came up with the MIT app and tried some things out .. as i mentioned its hard to find esp32 control for servo S90
I think the track can be flipped with preset degrees cause the track has some room for the train to go left or right ( it doesnt have to be really precise)
I indeed thought about stepper motors but they are big and not easy to Insert in the printed part...
So it would be great if someone can help me.out howto make a servo controller thru bluetooth or wifi
(Prefer bluetooth)
And i can make a nice layout for controlling


You might be able to use a couple of solenoids, if you copy the internal toggle mechanism of a wall mounted light switch.


Thought about that option indeed...
But first want to try it out with servo cause they are cheap...


So its possible to help me out?
I am thinking the only things i need.for making the app is how to make the servo connect to the esp and make it work with bluetooth?
Then i need to make the app working so help with both is much appreciated


I mean something like this... Only then with out the blue tooth module and in place there for a Esp32

Yes, there is no need for stepper motor precision, I think the same. I haven't used the bluetooth yet neither on the esp32 or the appinventor, so I cannot help on that, but if you choose the WiFi route I can. Although, indeed the BT would be the easier one.

Dear @martijn_vd_brakel and son ( :grin:), the annexed .aia works for me with an ESP32 and a Xiaomi phone (Android 9).
It operates on classic BT.
The app has 3 buttons and sends accordingly 'A' 'B' 'C' to the ESP via BT.
The .ino file is the ESP32 counterpart.
The ESP shows on the Serial Monitor of PC the received character and sends it back to the app (closed loop). The app shows the feedback character received.
To make it working, first of all you have to "pair" your phone to the ESP32 (in phone's BT settings).
In my app's code the IP address of my ESP32 is fixed as a text constant, you shall substitute this address with the one of your ESP. If you dont know it, you can download the Serial Bluetooth Terminal app from google playstore (free).

Therein, by selecting the menu "devices", you have to find ESP32_BT in the shown list and annotate the address, that you have to copy into the app code instead of my address.
Then recompile the app's code, download the apk to your phone and launch it.
Of course your ESP shall still be connected to your PC with the option Serial Monitor active (baudrate 115200).
That's all !
BT_to_ESP32.aia (24.9 KB)
BT_Send_Monitor.ino (1.8 KB)

Note: whether your Android is (most probably) a newer version, i.e.>= 12, you shall ask for permissions into the initialization event. You can get info about this requirement here:

or here:

About ESP32 and servo, you might have a look at:

Credits: @Taifun for his "TaifunTools" extension used to maintain active the screen and don't allow it to go to sleep, until you exit the app.

Best wishes for your project.

1 Like

found this and here you see the HC-05 in the beginning....
going to read if there is some explanation about how to use the ESP32 instead.

sadly your code for arduino does not work and the app stops working on my phone...

is this code for the HC-05 module ? cause its looking there is some comment in the code about that module...?

Start from the beginning.
About the hardware.
How many servo do you want to controll with the ESP32?
Do you already have the circuit (for example: which pins do you use on the ESP32)? The ESP32 is a 3.3V device. The S90 servo is a 5V device. Not sure if the servo works without level shifter.

First, try to build @Juan_Antonio Wifi example:
Tell us if you need help with this.

ESP32_BT_Monitor.ino (1.4 KB)

OMG I've annexed the wrong file.
This one is for ESP32... :grimacing:

Will take a look at that....
I am going to use the ESP32-C super mini that can handle 5V.
I see this board has a TX and RX pin onboard, maybe its possible to use the code for the HC-05 module ?in the tutorials that i can find about using MIT with esp32 Bluetooth the HC-05 is attachted to that pins ...

hope to hear

Found a simpler solution i hope

This might be a way to try out and see if it works...
Only the thing is i my project to get the module in but for testing learning and playing with MIT app it will be a good way i hope...
Ill keep u posted



Yep, that tutorial seems pretty good.
Just let me highlight that the Tx pin of HC05 shall be connected to the Rx Pin of ESP (and Rx to Tx).
If you use the Super Mini ESP that has I/O at 5 V instead of 3.3, please be careful to connect the HC05 Rx pin with a voltage divider:
(don't care if in the image you see a Nano and a HC06: the same applies to HC05 and any Arduino board featuring a 5V I/O). This requirement is NOT mandatory, but the Rx pin of HC05 will appreciate your care :grin:
Cheers, Ugo.

Where is that came from? I suggest you to read that datasheet again.
BUT if you use the HC05 it does not matter, because that work with 3.3 too.