Especially if your own circuit has a display to show values, the next step is often to connect an interface option.
You can connect buttons or switches. A relatively cool way to equip your own circuit with an input option is the rotary encoder.
At first glance, a rotary encoder looks like a potentiometer. In contrast to the potentiometer, the rotary encoder can be turned infinitely in both directions. In addition, many models are equipped with a button. Connected to a microcontroller, it can ultimately recognize how far has been turned in which direction and also when the button has been pressed.
Thanks to the matching plug-in, rotary encoders can be read out very easily with the help of ESPEasy and the inputs can be reacted to.
How to connect one (or two) rotary encoder to a Wemos D1 Mini or ESP8266 and configure ESPEasy correctly is described in the following article.
Inhalte
Safety instructions
I know the following hints are always a bit annoying and seem unnecessary. But unfortunately, many people who knew it "better" from carelessness lost their eyes, fingers or other things or hurt themselves. In comparison, a loss of data is almost not worth mentioning, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Even the coolest project is worth no injury or other annoyance. https://www.nerdiy.de/en/sicherheitshinweise/
Affiliate links / advertising links
The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and shop via this link, Nerdiy.de receives a commission from the online shop or provider concerned. The price doesn't change for you. If you do your purchases via these links, you will support Nerdiy.de in being able to offer further useful projects in the future. 🙂
Requirements
Helpful Articles:
You can find additional tips on ESPEasy in the following articles.
- ESPEasy – Execute commands and actions via HTTP, MQTT, UDP and directly
- ESPEasy – Compile firmware, flash it and configure WiFi access data
- ESPEasy/Wemos D1 Mini – Adapt ADC to a different maximum voltage
Required tools:
Required material:
Connect the rotary encoder
In the following you can see two circuit diagrams how you can connect a rotary encoder to the Wemos D1 Mini.


Configuration of the rotary encoder in ESPEasy

First open the web configuration view of your ESPeasy installation.
Information on how you can open this view can also be found in the article ESPEasy – Execute commands and actions via HTTP, MQTT, UDP and directly

… and you can now choose which device you want to create.
Since you want to create a rotary encoder, select the entry “Switch Input – Rotary Encoder”.

This will redirect you to an overview page. Here you can make all settings regarding the rotary encoder.
It is important that you assign a name, tick “Enabled” and configure the GPIOs as shown.
The “GPIO <- A” and “GPIO <- B” settings correspond to the connections of the rotary encoder which are shown in the circuit diagram above by the green and blue lines.
For most rotary encoders you can set the “Mode” setting as shown.
By turning the rotary encoder, a counter is later counted up or down. You can configure its lower and upper limit values with the settings under “Limit min” and “Limit max”.
As soon as you have configured everything correctly, you can save the settings by clicking on “Submit”.

In order to evaluate the key press on the rotary encoder button, you have to create a separate device.
To do this, click on the next “free” “Add” button in the devices overview.

It is also important that the GPIO must be set to pin “D5”. This is the connection pin via which the rotary encoder button is read out.
Test rotary encoder
After you have connected and configured the rotary encoder, you can test the function using the ESPEasy log. Events that have to do with the connected sensors and actuators are also displayed there.

The ESPEasy log output will then be displayed.
If you now turn the rotary encoder, an output with “QEI …” should be visible. The number behind it shows the value of the counter that you count up or down by turning the rotary encoder.
As soon as you press the button on the rotary encoder, an entry should begin with “SW: …” is displayed.
You can then process the keystrokes or actuations of the rotary encoder with the help of the rules and thus trigger actions.
Alternatively, you can also forward them to your SmartHome system via MQTT and, for example, switch a light on or off.
Have fun with the project
I hope everything worked as described. If not or you have any other questions or suggestions, please let me know in the comments. Also, ideas for new projects are always welcome. 🙂
P.S. Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you appreciate it that I share these information with you, I would be happy about a small donation to the coffee box. 🙂
Hallo Fabian
..ich sag mal DANKE – daß es jemanden wie dich gibt – von dem ein “Bastler” wie ich was lernen darf !!
..hab’ hier sehr viel interessantes gelernt und nachgebaut – PWM mit Drehcoder..
Ich verwende z. Zt einen ESP8266 als Thermostat mit 2 Taster (je 1 GPIO) und ESPEASY mit einer (kopierten) Rules. Wenn notwendig, schick ich auch das/mein Rules
..dies würd ich gerne statt der + und – Taste auf den Drehcoder umbauen.
..wenn möglich Drehgeber-Schritt
Leider bin ich in Rules nicht so fit und schaff das nicht .
..kenn‘st du vllt. ein Beispiel / Link – Rules für ESPEASY ?
Gruß aus Wien – fossi1
Hi fossi1,
danke für deine netten Worte. Freue mich, dass meine Tipps brauchbar sind. 🙂
Schreib mir doch gerne mal deine aktuellen Rules. Dann gucke ich mir mal an, ob man die nicht umbauen/ausbauen kann um sie mit einem drehencoder ansteuern zu können. 🙂
Beste Grüße
Fabian
Hallo Fabian
Danke für deine Antwort – ich wünsch’ mal PROSIT NEUJAHR !!
Zu deiner Allg. Info:
..ich hab einige esp für div. Anwendungen kann Hardware, bin in Software (leider z. Zt noch) der “Kopierer” – deshalb bitte nachsehen mit meinen Rules..
..eines meiner Projekte – ich möchte/werde für meinen Freund eine “Smoker-Steuerung” bauen.
Temperaturmessung mit 4 K-Fühler , D1mini mit EspEasy, OLED + LCD, Relais für LüfterSteuerung und 4x MAX31850 (K-Fühler werden 1Wire und in EspEasy unter D18B20 eingelesen)
..die TempMessung der K-Fühler über MAX31850 funktioniert
..die “Grobe” Anzeige der Temperatur des Fühlers X (wird dann erst bestimmt welcher) wird mit Oled Blau, Grün, Rot für zu Kalt i.O, zu warm angezeigt – z. Zt zum Testen der DS18B20
..die echte TempAnzeige erfolgt über Oled und LCD
..die Einstellung der Temp (für den Lüfterlauf) z.Zt über +/- Tasten
..da die Regelung des Lüfterlaufs in Abhängigkeit über einen K-Fühler im TempBereich 100-200 Grad erfolgen soll, ist das mit Tasten sehr “zäh” – dein Drehencoder wäre die komfortablere Lösung.
..mein esp hat deshalb 3 Rules für Neopixel Anzeige,Tastenabfrage, Anzeige
..hier die Rules 2 :
—————————————————————————–
/Tastenabfrage – geändert 06.02.22Fo
//esp8266
//GPIO 0 = Taster Temperatur +
//GPIO 2 = Taster Temperatur –
//GPIO 4 = SDA für Oled
//GPIO 5 = SCL für Oled
//GPIO 12 = Eingang DATA von DS18B20
//GPIO 14 = Ausgang S für Relais
//GPIO 15 = Ausgang für Neopixel
on System#Boot do
TaskValueSet 6,1,25.0 //SetTemp = SOLL Temp
TaskValueSet 6,2,24.5 //TempLow = niedigste Temp
TaskValueSet 6,3,25.5 //TempHigh = höchste Temp
gpio,14,1
endon
//TastenAbfrage zur Temp Einstellung
//UP = Task7 auf D3(GPIO-0) und DOWN = Task7 auf D4(GPOI-2)
on Up#State do
if [Up#State]=1
if [Local#SetTemp]5 //Temp. Einstellbegrenzung ab 5°
TaskValueSet 6,1,[Local#SetTemp]-1.0
TaskValueSet 6,2,[Local#SetTemp]-1.0
TaskValueSet 6,3,[Local#SetTemp]
endif
endif
endon
//Schaltzustand definieren
on T5#temperature do
if [T5#temperature]+1[Local#TempLow]
event,TurnOff
endif
endon
———————————————————
..hab leider keine Mail Adr. von dir, sonst könnt ich das txt File senden
..wennst noch Info’s dazu brauchst, schreib mir event. per Mail
Gruß aus Wien – fossi1
Hi fossi1,
sorry, dass ich mich jetzt erst melde. Ich hatte deine Nachricht über das Kontaktformular bekommen. Da war ich aber noch etwas in den Nachwehen von meinem Umzug und dann kamen die Feiertage dazwischen. :/
Ich versuche mich jetzt aber zeitnah darum zu kümmern. Hab es mir aufgeschrieben. 🙂
Beste Grüße
Fabian