Connect 4 Game Using Arduino and Neopixel




About: My goal is to captivate, inspire and engage young engineers through intriguing robotics projects. I use Arduino at my robotics workshops since it is the most cost-effective way to build a robot using commod...

Rather than just giving an off-the-shelf toy gift, I wanted to give my nephews a unique gift that they could put together and (hopefully) enjoy. While the Arduino code for this project may be too difficult for them to understand, the basic concepts of input, output, loops, and conditions used in this code could be explained visually as they play the game of Connect 4.

In this Instructable, I will show you how to put together an Arduino kit that you can assemble and code with your kids to play Connect 4. No soldering is required for this project; just plug and play.

Step 1: Parts

For this project, you will need:

  • Arduino Uno or equivalent
  • 8x8 Neopixel RGB LED
  • Breadboard
  • 3 button switches
  • Jumper wires
  • Screws
  • Case - baseboard & cardboard stand

Tools: Screw driver, glue gun

Step 2: Prepare the Neopixel Display Stand Unit

First, connect 3 jumper wires to Neopixel. I'm using the following wiring color code:

White: GND
Gray: 5V
Purple: Data IN

Then, affix Nelpixel to the display board with hot glue.

Step 3: Prepare the Button Switch Unit

Place button switches on the breadboard and connect jumper wires using the following wiring color code:

Brown:  Left Button
Red:    Left Button
Orange: Center Button
Yellow: Center Button
Green:  Right Button Switch
Blue:   Right Button Switch

Brown, orange, green wires are connected to the (-) rail along with a new black wire.

You may noticed that I'm not using any resistors for these buttons. That's because I will be using Arduino code to use built-in 20K Arduino pin resistors. See my other project on how to use internal resistors using your code to simply your circuit.

Step 4: Attach Arduino and Battery Holder to Baseboard

Use screws (or hot glue) to attach Arduino and the battery holder to the baseboard.

Step 5: Affix Display Unit to Baseboard

Use hot glue to affix the display unit to the baseboard as shown.

Step 6: Connect Jumper Wires to Arduino

Connect all the jumper wires to Arduino according to the following pin assignment:

Red    -> 2
Yellow -> 3
Blue   -> 4
Purple -> 5

Black  -> GND
White  -> GND
Gray   -> 5V

Step 7: Upload Code & Play

I pre-loaded the Arduino with attached code so that as soon as the 9V battery was connected to the Arduino, it started to play the game. The blue buttons are for moving your chip position to left or right column before pressing the yellow button to drop the chip. (See the video)

To enter the demo mode, simply press any button and press & release reset. Once the screen is clear, release the button and you'll see red and blue playing automatically. You'll notice that in the demo mode, red and blue players are simply selecting columns randomly and not using any winning strategy to beat the other player.

To exit the demo mode, just reset the Arduino.

I'm planning to add a single player vs Arduino mode in the future so if you know of a basic algorithm for Connect 4, let me know.

Toys Contest

Participated in the
Toys Contest



    • Beauty Tips Contest

      Beauty Tips Contest
    • Pets Challenge

      Pets Challenge
    • Sensors Contest

      Sensors Contest

    11 Discussions


    Question 7 weeks ago

    Hey, somebody said the fixed the code for zigzag configuration. I was wondering if somebody could send it to me please?


    7 weeks ago on Step 7

    Is it possible to reduce the size of the matrix by changing only the matrix grid that is at the beginning of the code? I would like to reproduce it in 5 X 7 with 35 LEDs. Is this the only change to make?

    1 reply

    Reply 7 weeks ago

    That's not possible. All the board functions assumes not only 64 leds, but it also assumes that the top row starts from 0 to 7 and and the next row is from 8 to 15 so on. You'll have to make changes to pretty much all the functions - moving pieces to checking for a winning move - for the code to work in 5x7.


    5 months ago

    This is a great project. Are you using your Arduino directly to drive 64 neopixels?
    I think there is current limitation in Arduino pin and when all the pixel will be lit up then maximum of 4amp current (60mA for each pixel x 64 pixels = 3840mA) is a requirement. How you are managing to get the required power for your pixels?
    Also in the picture I have seen 9v battery,are you using any voltage regulator for a 5v micro controller? Also neopixels are rated for 5v supply. Also there is no pull-up or pull-down resistance for any button. Can you please explain the circuit a little bit more. I like your project concept but I'm not understanding the method of connection you are using here and the component you are selecting for the protection of the system.
    Please help me to understand here.

    4 replies

    Reply 5 months ago


    1) I'm directly driving 64 neopixels with 5V on Uno. I am aware of current limitation on the pin but I am running neopixels at 10%-20% of intensity/brightness and I'm also purposely using single colors - red or blue - to limit current withdraw (and not mixing RGB colors). As part of the test, I turned on all 64 with 32 red and 32 blue and that didn't fry my Uno.

    2) Uno has a built-in 5v regulator so it can accept 9v. This is a project for kids so I like to keep it simple by using 9v battery holder with 1/4 plug that plugs directly into Uno. (no on/off switch).

    3) For the buttons, I'm using "pull-up" mode in code that uses internal pin resistors. Here is more info on pull-up from the Arduino website.
    "There are 20K pullup resistors built into the Atmega chip that can be accessed from software. These built-in pullup resistors are accessed by setting the pinMode() as INPUT_PULLUP. This effectively inverts the behavior of the INPUT mode, where HIGH means the sensor is off, and LOW means the sensor is on."

    Hope this helps.


    Reply 5 months ago

    Thanks for your reply. OK, the concept of pull up using software is not very promising and it is always better to use a pull-up resistance (say 1k ohm) for the ground connection of all the buttons which will give you the best result.

    Also, the powering concept is not the correct way, as per ADAFRUIT's website Neo pixels wiring required a capacitance (6v 1000muF) in +ve and -ve connection to protect the pixels, also they have suggested a 470 ohm resistance in between Arduino and pixel's data connection. Here is the link please have a look:
    For your setup, I found it is OK as you set the brightness of the pixels are very low (less than 10% of full brightness). I have checked the current requirement using 5V power supply with it and found around 130mA. As the Arduino UNO can handle up to 200mA current flow so you should not fry your microcontroller however the life of the chip will be reduced. So, best way is using two power sources one is for the matrix and another is for the microcontroller. Also, need two on-off switches to start up them.

    OK, I also build the same and faced a problem with your code. My Neo pixel matrix configuration was different. It is not a parallel data flow board rather it is a zigzag data flow board. So, I need to modify your code a little bit. Finally, it works very well.

    However, I should be thankful for your project, it helps me a lot.

    In future I will add music and trying to implement an AI algorithm. I have found a very good website regarding Connect4 game playing with AI which also provide the algorithm of the game. Please have a look here:

    Thank you very much, keep doing your awesome work.


    Reply 8 weeks ago

    Hi! I'm having the same problem with the configuration of my NeoMatrix and was wondering if you could send me a link to the code.


    Reply 5 months ago

    Wow! Thank you for checking everything out and all the recommendations you have made. I will definitely incorporate those changes on my next version. AI/Machine Learning may require more processing power so perhaps I will rebuild this on Raspberry Pi as a project to teach kids on AI. Thanks again!


    5 months ago

    Thank you very much. I agree with the idea of making toys instead of giving away a ready made one. Also when made with Arduino it's way more informative. Keep going. Voted

    1 reply
    DIY Hacks and How Tos

    5 months ago

    This is great! It would be really fun to scale this up and make a giant version.