How to Control Neopixel LED via Rotary encoder

The Neopixel LED module has many attractive features. With a microcontroller base, they can produce millions of different lights. In this tutorial, we are going to change the status of the neopixel LED according to the required colors with the help of the rotary encoder module and Arduino board. In this way, by changing the rotary angle of the encoder in each step, the status of the neopixel LED will also change. Visit CiferTech for more tutorials, and be sure to follow my Instagram page to support me.

 

 


Rotary encoder module


The rotary encoder is a type of position sensor used to determine the angular position of the rotating shaft. Which produces an electrical signal, analog or digital, concerning rotational motion. Due to its robust digital power and control, many projects, including robotics, CNC machines, and printers, use an encoder rotary module. Encoders are available in both absolute and incremental types. The absolute encoder gives us the exact position of the button in degrees, while the incremental encoder reports how many shafts it has moved. Rotary encoders are the digital equivalent of modern potentiometers. They can rotate completely without stopping at the end, while a potentiometer can rotate only about 3/4 of a circle. Inside the encoder, a slotted disc is connected to the common ground pin C and two contact pins A and B, as shown below. When you turn the knob, A and B make contact with the common ground pin C, depending on the direction in which you are turning the knob.

 

Finally, they generate a signal by contacting common points. These signals are transmitted by contacting one pin before the other pin 90 degrees out of phase. This encoding is called quadrature. When you turn the knob clockwise, pin A first connect, then pin B connects. When you turn the knob counterclockwise, pin B is attached first, and then pin A will be attached.

 


Arduino board


The Arduino board is one of the most popular development boards among embedded engineers. They are available in various models such as Micro, pro mini, Nano, Uno, and also Mega. The core of these popular boards consists of the AtMega328 series. Arduino is an open-source hardware and software platform. As mentioned earlier, the Arduino platform includes an open-source single-board microcontroller that forms part of the Arduino hardware. In addition, the Arduino platform includes an Arduino IDE software designed for programming for Arduino boards and a software bootloader that loads on the microcontroller.


Neopixel LED module


Neopixel LEDs are a separate addressable type all on a string that can be controlled from a stand on the microcontroller. This means that a stand can control all the colors of the LEDs and which LEDs are on at any given time. Compared to a regular RGB LED, you will notice that we need 3 pins to control the amount of Red, Green, and Blue, and all LEDs must be on or off. As you can see, using separate addressing can help create some interesting effects. Many companies sell addressable LED strips, but the most popular is neopixel LEDs.Made by Adafruit. Adafruit produces an addressable LED strip line. They have also developed a library to control them, called the Adafruit NeoPixel. Other companies have developed libraries to control these addressable LEDs. However, in my opinion, Adafruits has the best support and is a good choice to start with.


Additional explanation


In the neopixel LED control project, by specifying the values ​​of R, G, and B in the project code, the neopixel status will change by moving each step of the rotary encoder module. In this way, each step of the encoder represents a case in the project code. Each case comes with certain values, which are displayed by changing the status of the encoder. Take a look at the image below.


Items needed


Rotary Encoder

Arduino Nano board

Neopixel LED ring

 


Schematics and connections


First, make the connections for the encoder module as well as the neopixel module. Pins 2 on the Arduino connect to S1 and S2 on the rotary encoder. Also, pin 4 on the Arduino connects to the input of the rotary switch. Then pin 6 on the Arduino connects to the neopixel data input. Both modules are powered by 5 volts.

  • Encoder and Arduino rotary module connections.

 

  • Neopixel and Arduino ring module connections.

 

Schematic of connections related to neopixel LED  control training with Rotary Encoder and Arduino

 


Setup and coding


At this stage, after establishing the connections, it will be the turn of the codes of this project. We will review the different parts of the code step by step. We will first call the libraries needed to launch the neopixel module.

 

In this section, we create three variables for the three primary colors in neopixels.

Also, these three variables are related to the rotary module, which we have specified the pins related to each base.

In this section, apart from the void loop and void setup, we have created another void that is related to Intrapt.

 

Finally, this section is about the existing states for neopixels, which you can change as needed.

 

 

Complete code of neopixel LED control project with rotary encoder and Arduino

 

 


Conclusion


In this tutorial, using neopixel ring modules and rotary encoder as well as Arduino nano board, we created and displayed different modes with neopixels, but you can also change the created modes according to the need.

  • The settings menu of the tools in Arduino software is the same as the image below.

If you encounter any problems in the process of launching and carrying out this project, do not hesitate to ask your question at the end of this post. I will answer your problem as soon as possible. Also, if there is a problem in the code or the execution steps, you can inform in this way.

Leave a Reply

Your email address will not be published. Required fields are marked *