lights Game with Arduino

Inspired by a friend of mine, I have developed a circuit to light a matrix of LEDs. Is it possible that the pastor has requested to repair a votive candle, already provided with the incandescent lights. We made to put the white LEDs in small power. A pass key or sensor of the coins turn on an LED at a time.



The project presented here is unassuming to be fully functional, is solo for educational purposes. In fact there could be some problems to be solved in the final construction of the project.

The bench test demonstrates the feasibility. Then finally in the installation there will be precautions that the length of the connections is not excessive, or that’ power is filtered by any disturbances.

The development comprises an Arduino UNO V3, a LED matrix by 6 lines to 4 column. These LEDs are driven directly dall'Arduino multiplexed.

The program to’ act of activating a button or detection of passage of a coin, begins to flash the LED next to the sequence.
When there is none no active, clear that from the first part.

In the video, that you can see the address below described, a simple wire mo 'button has been used.

The arrangement of the LEDs of the matrix, part from a square that reflects in a certain way the Cartesian axes. Then the ignition sequence starts from the bottom left and follows with the’ increased Y, up to the maximum of the number of a column. Below, moves to the next column. See table below, showing what the ignition sequence. Starting from number one.

LEDs for orientation

























Printed circuit

To simplify development, I organized a single-sided, which provides for the connection of each anode and cathode. The card already provides for a matrix expansion by 6×6. The figure below shows the arrangement of the card. I left the space between anode and cathode of each LED, to allow more tracks. Unfortunately there are some bridges to pass, given that the routing was not possible to reduce them.

One should note that the cathodes are directed towards the resistances ranging all’ Arduino, while the anodes are connected to the collectors of the transistors. So we see the wiring diagram.

Wiring diagram

Note that the’ Arduino can be placed on connectors. I recommend this way, in order to extract it in the event of reprogramming.

In all cases You can see the details downloading package which also contains sketches[*] be loaded on’ Arduino.

[*] A sketch has the period that the LEDs are only switched on and starts to reaching the maximum number of LEDs. This is called matrix_single_time.ino.
The second one, matrix_multiple_time.ino, It works that each LED has a separate period and ends with the assigned time (TIMEOUT). Furthermore, if all the lights saranno burning, andRRA reset the duration of the LED thatVRA the longest period.
A note matrix_multiple_time.ino, starts counting from position 24 all’ back.
There is also a version that uses a MAX7219 with its library, which can handle up to 64 lights. But it is not present in the package.

Program operation

The program allows some customization, which are listed in its first lines. Aside from that to which it is currently designated it may take the’ Arduino and implement a matrix 8 lines to 6 column, with only two correction lines. We see in detail.

The line 5 #define DEBUG defines whether to compile with the serial connected for debugging (Once you try the circuit, better comment out the line). Below, in the sketch, the lines 23 e 24 you can define which feet assign for use with the serial. It takes a USB-RS232 TTL interface as shown. So you can connect to the legs still available depending on how you want to assign.

The line 12 #define INBTN A0, allows us to assign the’ input you want to use to activate the count. At least for this project is expected in the printed circuit a block with screw fastening, to connect the button. But for other use is the ability to assign a new position. Except those on’ Arduino are numbered 0 a 13, which they are those that are used to drive the LEDs matrix.

The line 13 #define TMPRESS 20, serves to define the period that’ input must remain low in order to be validated. You may need the’ adjustment to define the sensitivity. The value is in 2,5 milliseconds. That corresponds to the update period of the LEDs.

The line 14 #define TIMEOUT 7200, It establishes how long they remain all LEDs lit, once who has reached the maximum number of starts. The measure is in seconds, for so hath it has been considered a two-hour period. In the function countdown the delay is 998 milliseconds, that you may need to be adjusted to have the correct period.

The lines 15 e 16 define how many columns NUMCOLS and how many rows NUMROWS that for the project are 4 e 6 respectively.

at the following 3 lines is calculated by the program settings, depending on the values ​​defined for the rows and columns, above. (There are also changing to a different use of the program).

To the line 20 #define NUMBLINKS 8, It can vary the number of times blinking before to remain the LED lit.. Take care that can only be an even number, sentence that ends the count with its LED off.

The line 21 #define COMMON_ANODE, allows us d 'set whether to use high or low levels for the outputs of the rows. For which case you wanted to interpose the buffer transistor orppure circuits integrated as ULN2804, this allows you to vary the compilation and reverse outputs.
If one wanted the active high outputs, just comment out the line,
putting //.

The same also applies for the line 22 #define COL_ACTIVE_LOW, It allows us to invert the outputs of the logic for the columns. I set to pilot the 2N2907A, so they needed active low.

The line 25 #define TIMELAPSE 2500, It is the one that determines the refresh rate of the matrix and the scanning of the columns. The period in microseconds. In fact here the function is called refresh every 2,5 milliseconds. You could adjust, increasing the value, to slightly reduce the brightness of the LEDs, but it risks d 'run into an annoying flicker. I tried with 5 milliseconds and has no flicker. Reducing could further undermine the performance of the other tasks of’ Arduino.

For the rest, you can also adapt the program to drive a numeric display 7 segments, with up to 6 figures. Or a matrix 8×6 column. This is why the program is a commitment to teaching, to learn some programming tricks. One detail to note is to use an interrupt routine to be able to have the’ Updating bright LEDs.
Like when I took the e-journals, almost I never was copying the entire project, I was interested in getting ideas for my ideas.

visual tests

He could not miss the trial by fire.

With the’ intent that can serve the community, enjoy yourselves.

11 replies
  1. Avatar
    And Tel says:

    I successfully managed to get the matrix_single circuit to work. I am having difficulty to get the MAX7219 to work. I have pin 2 as input and DATAIN pin 5, CLK pin 3 ,LOAD pin 4, GND and 5V. Am I missing anything ?
    I also have question for you , can the same concept be applied to using fastLED.h and WS2812B ?

    • Picmicro675
      Picmicro675 says:

      The last sketch should work for the MAX 7219. I repeated the compilation and it compiles just fine. I have tested the sketch only with the simulator.
      For WS2812B it think is rather a different story, but the style to have that effect remain same. You should maintain the arrays to memorize each LED life. I wrote even for that some source for a PIC12F1822/40, in proton basic, but it follows a different style.

      • Avatar
        And Tel says:

        Hi, Thanks for your prompt reply. I am still struggling to get the MAX7219 to work. i am using the MAX7219 Dot Matrix Module Microcontroller LED Module Display Module as a test. Any suggestions ?

        • Picmicro675
          Picmicro675 says:

          You should provide some details about your assembly in order to comment and verify that you didn’t fall into an oversight.
          Using Arduino you may use the specific library as the sketch propose and connect the pins as written in that sketch. No idea if that will run smoothly I currently don’t have the hardware nor time to prove my sketch.
          I suggest you open a new discussion about your making.

  2. Avatar
    And Tel says:

    Excellent and Interesting project using PORTD and PORTB , will attempt on Arduino UNO. do you have schematic to support about 64 LEDs. Keep up good work.

    • Picmicro675
      Picmicro675 says:

      I’m glad that you’re interested on my project. So for the 8×8 schematics it was just a bit of copy-and-paste to add two more columns. I didn’t get into the sketch and PCB layout. So you should try a bit from yourself. In case you are in a bunch of difficulties I’ll get something developed for you. Currently to revise that project into a 8×8 layout I got some development with the MAX7219. That should be already included since the publication.
      The 8×8 you may find it here to download.

      • Avatar
        And Tel says:

        Many thanks for your reply much appreciated. I will first attempt with 24 LEDS the progress to 64. I was not able to get to the download link provided for the 8 x 8 layout.
        To use the 8 x 8 which additional Pins on Arduino are available. Also I would like to add 2 x 8 LCD Dispaly, any ideas?

        • Picmicro675
          Picmicro675 says:

          Sorry about the incorrect link, I got something messy along the way. Now is corrected. You will find the schematics.
          Anyway you may solve the case and use the entire PORTD to address more columns. But as I stated you might opt and use a CD4028 to convert the addressing by using only 3 bits.
          Here the MAX7219 sketch, the latest version.

          Sorry about the comments in Italian.

          • Avatar
            And Tel says:

            Thank you for your time and patience. Your depth of knowledge on this is just amazing. I have ordered the parts and will attempt setup over weekend and let you know the result. The MAX7129 setup is less complicated than the transistor driver circuits.

  3. Picmicro675
    Picmicro675 says:

    In fact I still have adopted the method of using a dual display 7 segments in another project.
    The project is for a timer that has not been proven, but the simulation yes. Should I get a moment to put it to the test.
    In fact it uses all PORTC to write a byte. With the 7-segment, best if you use an array of data that represent the symbols to be displayed.

  4. Amilcare
    Amilcare says:

    No I doubt I liked the idea and even more appreciated the simplicity of implementation. I steal the idea as a starting point for other uses but at the moment I'm busy with charlieplexing will my future study just completed one in progress.


Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Specify Instagram App ID and Instagram App Secret in Super Socializer > Social Login section in admin panel for Instagram Login to work