How to Control Neopixel LED via Rotary encoder

Published on

Category

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.

6 thoughts on “How to Control Neopixel LED via Rotary encoder

  1. I believe everything typed made a ton of sense. However, think
    on this, suppose you composed a catchier
    post title? I am not suggesting your information isn’t solid, but suppose you added something to maybe get people’s attention?
    I mean How to Control Neopixel LED via Rotary encoder – CiferTech is kinda boring.

    You could look at Yahoo’s front page and note how they create news titles to get viewers interested.

    You might add a related video or a related picture or two to grab people interested about everything’ve
    got to say. Just my opinion, it would bring
    your posts a little livelier.

  2. Fantastic post however I was wanting to know if
    you could write a litte more on this topic? I’d be very thankful if you could elaborate a little
    bit further. Cheers!

  3. I’m really impressed together with your writing talents and also with the layout
    for your blog. Is that this a paid topic or did you modify it your self?

    Either way stay up the nice high quality writing,
    it’s rare to look a great blog like this one today..

  4. Fascinating blog! Is your theme custom made or did you download it from somewhere?
    A theme like yours with a few simple tweeks would really
    make my blog shine. Please let me know where
    you got your theme. With thanks

  5. casino games

    Very nice article, exactly what I needed.

  6. It’s a shame you don’t have a donate button! I’d definitely
    donate to this fantastic blog! I suppose for now i’ll settle for bookmarking and adding your
    RSS feed to my Google account. I look forward to brand new updates and will share this blog with my Facebook group.
    Chat soon!

Comments are closed.