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.
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/
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. 🙂
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
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
From there click on the “Devices” tab.
In the “Devices” tab you now have to click the “Add” button in one of the empty lines.
You will then be automatically redirected to the view shown …
… 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.
In the drop-down list you now select the device “Switch input – Switch”.
You now have to set this device as shown on the left.
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.
When you have made all the settings you can save them by clicking on “Submit”.
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.
To do this, switch to the “Tools” tab and then click the “Log” button.
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.
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. 🙂