Maker.io main logo

LED Chaser with an LCD Menu

27

2016-10-26 | By All About Circuits

License: General Public License

Courtesy of All About Circuits

Start illuminating with an LCD and an MCU along with 4017 counters. The internet is overfilled with LED chasers, Knight Riders, and different ways to blink a series of LEDs in various patterns. In this article, we’re going to make yet another LED chaser, or a Knight Rider, but this one has a little twist: we'll make an LCD with a menu that allows you to choose different patterns and speeds.

Required Materials

This project has five PCBs: four PCBs with LEDs and one PCB with a microcontroller. There are two ICs on the LED's PCB: the HCF4017BE Johnson counter. The counter has 10 output pins and one clock input pin. For each high pulse that the clock pin receives, the next output pin will be set high, starting with output pin 0. You can read more about the IC in the link above.

The last PCB has a PIC16F877A microcontroller. I've connected a few switches to this microcontroller: a potentiometer and an LCD. Each counter IC’s microcontroller clock is in a different order. The counter ICs can also be reset by the microcontroller clock. There's a menu in the software that allows you to choose between some predefined patterns. One of the switches is used to navigate the menu and another is used to enter your menu choice. The third switch is the reset switch. One of the patterns allows you to use the potentiometer to change the speed for the "running" LEDs. You can do this with the microcontroller's built-in ADC module. However, we won’t cover ADC in this project.

Hardware

In order to get the LEDs to "run" back and forth, I used two 4017s for every eight LEDs. The first 4017 IC was connected in numerical order: Q1 to LED one, Q2 to LED two and so on. The second 4017 IC’s output was connected in reverse numerical order. Q1 to LED eight, Q2 to LED seven, etc.... I made four PCBs based on this schematic:

Scheme-it

I used some SMD components to save space. The capacitors on the microcontroller's crystal are 0603 size. I was surprised how easy it was since I’d never soldered anything that tiny. It took a little practice, but I got it. If you’re worried that your soldering skill isn’t up to snuff, you can use a breadboard. Apart from the obvious throughhole ones, the other SMD components are 0805 size.

Parts List

Here's an edited part list generated by Scheme-IT, you can view it by clicking the “Bill of Materials” tab.

 

Software

I used Microchip's library for the LCD. All of the source code files are copied into one large lcd.c file. The lcd.h file is edited to match our connections. The menu was built using two switch-case loops. The first loop updates the LCD with appropriate text, then assigns a variable with a value (MenuItem). When the MENUENTER switch is pressed, the value in MenuItem will be passed on to the next switch-case loop, which will execute the desired option.

The 4017 has a clock pin and a reset pin. All of the 4017’s clock pins are connected to different pins on the microcontroller. All of the reset pins are tied together and connected to a single pin on the microcontroller. With this configuration, we can clock individual 4017 ICs. Because all of the reset pins are tied to a single pin on the microcontroller, I only have to pulse that pin high to reset all of the 4017 ICs.

A push button is used to navigate through the menu. To us, one push might just look like one push, but to the microcontroller, that's a different story. The switch will bounce, which causes the microcontroller to think that you are pushing the button many times. This is called switch bouncing. You can learn more about switch bouncing here: Switch Bounce and How to Deal with It.

The software gives you 14 different patterns. Here is the string that makes the menu options:

Copy Code
                   // MENUOPTION STRINGS
char prg1[] = "RUN 1. 4017 "; // Clocks the first CD4017
char prg2[] = "RUN 2. 4017 "; // Clocks the second CD4017
char prg3[] = "RUN 3. 4017 "; // ... and so on ...
char prg4[] = "RUN 4. 4017 ";
char prg5[] = "RUN 5. 4017 ";
char prg6[] = "RUN 6. 4017 ";
char prg7[] = "RUN 7. 4017 ";
char prg8[] = "RUN 8. 4017 ";
char prg9[] = "UP - DOWN "; // LEDs "run" up and down endlessly
char prg10[] = "USER SPEED "; // User set the speed
char prg11[] = "RUN ODD "; // Clock only ODD number CD4017 -> 1, 3, 5, 7
char prg12[] = "RUN EVEN "; // Clock only EVEN number CD4017 -> 2, 4, 6, 8
char prg13[] = "RUN EVEN - ODD "; // Clock first EVEN numbers then ODD numbers -> 2, 4, 6, 8, 7, 5, 3, 1
char prg14[] = "RUN ODD - EVEN "; // Clock firs ODD numbers then EVEN numbers -> 7, 5, 3, 1, 2, 4, 6, 8

 

This is how your LCD display should look after the code is implemented:

 

 

You can download the source code from All About Circuits

Conclusion

Here’s yet another LED project on the internet… Hopefully this one provides you with more of a challenge! There are a total of 32 LEDs running up and down, or in other patterns. The microcontroller has some unused pins, which means that you can add even more PCBs with LEDs if you’re up for the challenge!

Pictures and Video

SOT-23 transistor and a 0805-resistor:

LED Chaser with an LCD Menu

I made four of these boards:

LED Chaser with an LCD Menu

This is the controllerboard:

LED Chaser with an LCD Menu

LED Chaser with an LCD Menu

16 x 2 LCD:

LED Chaser with an LCD Menu

 

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.