Simple LED Cube 4x With Arduino/328p

by akki5230 in Circuits > LEDs

21325 Views, 51 Favorites, 0 Comments

Simple LED Cube 4x With Arduino/328p

FormatFactoryDSC02336.jpg
FormatFactoryDSC02334.jpg
FormatFactoryDSC02341.jpg
Photo0050.jpg

Hi!

This is my first Instructable about my 4x4x4 LED Cube. The brain of the cube is Atmega 328p. Atmega 328p is the microcontroller used in Arduino Uno. So either you can use Arduino or just the Atmega 328p.

This instructable will explain the circuit and the programming part in detail.

LEDs, Light Emitting Diodes are soldered in layers of 16 leds. 4 layers are soldered on each other to make a cube.

Each led in this cube can be accessed individually so that you can create any kind of pattern/effect or animation.

Programing part is easy as Arduino is used instead of avr atmegas.

It will cost you around $10.(excluding arduino)

So Lets get started...

Components and Tools

FormatFactoryDSC02257.jpg

The following Components:

1. Arduino Uno or Atmega 328p x1 ($24)

//This will be used to control the cube

2. Arduino or any other programmer

// to program the atmega 328p

3. 64 LEDs + some extra if burnt ($2.5)

// you can get it on ebay at cheap price and high quality

// use any colour or colours of your choice

If you are not using arduino, Then you will need the Following Components to create your own:

4. 28pin DIP IC Socket x1

5. DC Jack or Spring terminals x1

//for power supply input. I used both.

6. Push to ON/OFF button x1

7. 7805 Voltage Regulator x1

8. pushbutton x1

//for reset function

9. 10uF Electrolytic Capacitor x2

10. 22pF ceramic Capacitor x2

11. 10k ohm and 100 ohm Resistor x1

12. 16 MHz Crystal x1

13. An LED for power indicating.

Tools:

1. Wire Stripper/Cuttor

2. Single Strand wire or any other wire to use on pcb.

3. Soldering Iron and Wire.

4. Perfboard or Standard drilled PCB.

5. 5V power supply

//Can use 9V battery or 4x AA Batteries or USB power (5V)

Creating the Cube

Photo0014.jpg
Photo0018.jpg

Creating the cube is the toughest part. You can find various detailed instructables for this soldering work.

I'll recommend the chr's instructable:

Step 1: https://www.instructables.com/id/LED-Cube-4x4x4/ste...

Step 2: https://www.instructables.com/id/LED-Cube-4x4x4/ste...

Step 3: https://www.instructables.com/id/LED-Cube-4x4x4/ste...

Step 4: https://www.instructables.com/id/LED-Cube-4x4x4/ste...

Create the cube and go to next step.

Creating the Circuit

FormatFactoryDSC02263.jpg
FormatFactoryDSC02265.jpg
arduinopins.jpg
FormatFactoryDSC02326.jpg

The next step is to create the circuit for the atmega 328p to work as an arduino.

This circuit contains the 328p, crystal with 22pF caps, reset pushbutton with 10k ohm resistor, and other components are for power supply--the 7805 V.R. with 10uF caps , indicating led, power switch, & input jacks.

  1. Insert the IC socket on the perfboard.
  2. Put the crystal at pin number 9 and 10 of the IC socket.(See picture)
  3. Put two 22pF caps at each pin of the crystal, the other end of the caps are connected to ground.(See picture)
  4. Connect one end 10k ohm resistor to pin 1 of IC socket and the other end to the pushbutton's pin(See Pic)
  5. The pushbutton's other end connects to +5V. (See Picture)
  6. Insert a DC jack and the spring terminal(Optional) in the perfboard.
  7. Put the push to ON/OFF Button near the input jacks. (See Picture)
  8. Put the 7805, add 10uF caps each to the input and the output of 7805 V.R. (See Picture).
  9. The 10uF cap's one positive end connects to the pin 1 of 7805 and negative to pin 2 of 7805.(See Picture)
  10. The other 10uF cap's one positive end connects to pin 3 of 7805 and negative to pin 2 of 7805.(See Pic)
  11. Solder/connect everything and connect the output power, ie. the pin 3 of 7805 to the pin 7 and pin 20 of IC socket.(See Pic)
  12. Connect the pin 2 of 7805 to pin 8 and pin 22 of IC socket ie. Ground (see pic)
  13. The Circuit image will explain everything else better.

Programming in Detail

FormatFactoryDSC02287.jpg

EDIT: If you don't want to write a whole program of your patterns, just check out this application which will generate the pattern code, on this instructable:

https://www.instructables.com/id/LED-CUBE-CODE-4x4x4-Arduino/

Before joining the cube in the circuit, we need to test the cube whether it's working properly, i.e. soldered properly.

For that we need to get into programming first. So let's get started

I'll explain the arduino code. The arduino code is very simple to understand. You just need to know "C" programming language to understand it.

1. int column[16]={13,12,11,10,9,8,7,6,5,4,3,2,1,0,A5,A4};

// initialization and declaration

// we declare an array named 'column' containing 16 elements, i.e.for 16 LEDs of a single layer of the cube

2. int layer[4]={A3,A2,A1,A0};

// declare an array named 'layer' containing 4 elements, i.e for 4 layers of the cube

void setup() // In arduino, this loop is used to tell it which pin is output and which pin is input in simple way

{

// Using a "for loop" to include all the 16 pins in an array for the 16 anodes

for(int i=0; i<16; i++)

{

pinMode(column[i], OUTPUT); // set 16 anodes as output

}

for(int i = 0; i<4; i++)

{

pinMode(layer[i], OUTPUT); // set 4 layers to output

}

//seeding random for random pattern
randomSeed(analogRead(10));

} // closing void loop

void loop() // this loop contains all functions which runs continuously in loop

{

turnEverythingOff(); //turn all off with this function written below
turnEverythingOn(); //turn all on with this function written below

}

//xxxxxxxxxxxxxxxxxxxxFUNCTIONSxxxxxxxxxxxxxxxxxxxxxx//

void turnEverythingOff()
{

for(int i = 0; i<16; i++)

{

digitalWrite(column[i], 1); //digitalWrite ON=1 to all anodes

}

for(int i = 0; i<4; i++)

{

digitalWrite(layer[i], 0); //digitalWrite OFF=0 to all cathodes

}

}

void turnEverythingOn()
{

for(int i = 0; i<16; i++)

{

digitalWrite(column[i], 0);

}

for(int i = 0; i<4; i++)

{

digitalWrite(layer[i], 1);

}

}

// Code ends here

You can create and add more function in the above program. Just create

void function_name()

{

//function data

}

and add function_name(); in the void loop()

I have found a arduino program which contains some more already created functions

If you're not getting this method, try the next method of programming.

Another Way of Programming

If you created a program with the last step, then skip this one...

In this way of programming, we store the patterns in flash by using PROGMEM in arduino

#include // allows use of PROGMEM to store patterns in flash

#define CUBESIZE 4 //cubesize is 4x4x4
#define PLANESIZE CUBESIZE*CUBESIZE //here plane means a layer, i.e 4x4=16 leds in a layer

#define PLANETIME 100 // time each plane is displayed in us -> 100 Hz refresh

#define TIMECONST 20 // multiplies DisplayTime to get ms

// LED Pattern Table in PROGMEM - last column is display time in 100ms units
// TODO this could be a lot more compact but not with binary pattern representation

prog_uchar PROGMEM PatternTable[] = {

//1 //2 //3 //4 //5 //6 //7 //8 //9 //10 /11 //12 //13 //row numbers
B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,B0000,

//14 //15 //16

B0000,B0000,B0000,10, //empty set, all leds are OFF

//Code goes here, i started you off above

// this is a dummy element for end of table (duration=0) aka !!!DO NOT TOUCH!!!

B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, B0000, 0 };

// program not completed

// you need some progmem functions here

To get the full code, and to understand this way of programming, I'll recommend you to check out this instructable:

Write your own LED Cube show for Arduino

Testing the Cube

Photo0027.jpg
arduinopins.jpg

Now that you know how to program the cube, it's time to test it now:

Make the following Connections properly:

Columns
[(x,y)- Ard Pin -IC Pin] // Consider x as horizontal line in x axis and y as horizontal line in y axis

(1,1) - 13 - 19 // 1st led in x axis, 1st led in y axis, the corner one, connect this anode to pin 13 of arduino or

// pin 19 of IC socket

(1,2) -12 -18 // 1st led in x axis, 2nd led in y axis , connect to pin 12 of arduino or pin 18 of IC socket

(1,3) -11 -17 // connect to arduino pin 11 or IC pin 17

(1,4) -10 -16 // connect to arduino pin 10 or IC pin 16

(2,1) -9 -15 // connect to arduino pin 9 or IC pin 15

(2,2) -8 -14 // connect to arduino pin 8 or IC pin 14

(2,3) -7 -13 // connect to arduino pin 7 or IC pin 13

(2,4) -6 -12 // connect to arduino pin 6 or IC pin 12

(3,1) -5 -11 // connect to arduino pin 5 or IC pin 11

(3-2) -4 -6 // connect to arduino pin 4 or IC pin 6

(3-3) -3 -5 // connect to arduino pin 3 or IC pin 5

(3,4) -2 -4 // connect to arduino pin 2 or IC pin 4

(4,1) -1 -3 // connect to arduino pin 1 or IC pin 3

(4,2) -0 -2 // connect to arduino pin 0 or IC pin 2

(4,3) -A5 - 28 // connect to arduino pin A5 or IC pin 28

(4,4) -A4 -27 // connect to arduino pin A4 or IC pin 27

Layers

[layer-Ard Pin-IC Pin]

a -A0 -23 // connect to arduino pin A0 or IC pin 23

b -A1 -24 // connect to arduino pin A1 or IC pin 24

c -A2 -25 // connect to arduino pin A2 or IC pin 25

d -A3 -26 // connect to arduino pin A3 or IC pin 26

Upload the program and check whether every led is working.

Joining Cube to Circuit

FormatFactoryDSC02272.jpg
FormatFactoryDSC02273.jpg
FormatFactoryDSC02274.jpg
FormatFactoryDSC02283.jpg

Now, after testing the working of cube,

Put the cube on the perfboard and solder it.

Solder the connections as below:

  • Connect Pin 19 of IC socket to Anode of LED (1,1) (SEE PICTURE)
  • Pin 18 to LED (1,2)
  • Pin 17 to LED (1,3)
  • Pin 16 to LED (1,4)
  • Pin 15 to LED (2,1)
  • Pin 14 to LED (2,2)
  • Pin 13 to LED (2,3)
  • Pin 12 to LED (2,4)
  • Pin 11 to LED (3,1)
  • Pin 6 to LED (3,2)
  • Pin 5 to LED (3,3)
  • Pin 4 to LED (3,4)
  • Pin 3 to LED (4,1)
  • Pin 2 to LED (4,2)
  • Pin 28 to LED (4,3)
  • Pin 27 to LED (4,4)
  • Pin 23 to cathode of 1st layer, you can choose 1st layer as bottom one or the top one, your choice.
  • Pin 24 to layer 2 or layer b
  • Pin 25 to layer3 or layer c
  • Pin 26 to layer 4 or layer d

Finished!!!

FormatFactoryDSC02286.jpg
FormatFactoryDSC02338.jpg
Photo0049.jpg
FormatFactoryDSC02285.jpg

The circuit will be now ready to be loaded with 328p chip.

If you have arduino, program it, take out the atmega chip from arduino and put in in the IC socket of the perfboard

If you have atmega IC only, then you need a programmer to program it.

Plug in power supply to the input jacks.

Your Cube is ready!!!!

Thanks for reading this instructable!!

Hope you did't get difficulties while making your own Cube!!

If you got some, you can comment ...

Link to Video:

http://www.youtube.com/watch?v=EU96xZylF2I