Smallest LED cube bringing up the Big concepts in Microcontroller Timing cycles.
It consists of 8 LEDs being controlled through microcontroller to give amazing lighting Effects.
A must try DIY project for beginners which can be extended to 4x4x4 or 8x8x8 and further, with 2x2x2 cube as the basic building block.
Components :
· 8051 Microcontroller (AT89S52)- It’s a 40-pin microcontroller with 32 I/O lines. You can also use 20-pin package (AT89S2051) with proper pin connections (refer datasheet).
· 8- LEDs (or More if some get burned while soldering) of any colour
· NPN Transistors (BC547)
· Resistors- 1K, 220E
· Other discrete components such as Crystal, Capacitors etc.
{ · Some wires.
Construction of the cube :
The construction of LED cube is quite simple and easy to grasp.
We have to construct two layers/rows of 4-LEDs in each. These two rows will then be connected together.
Look at the figures below :
Fig. 1: Diagram of Rows for LED Cube
Fig. 2: Diagram of Columns for LED Cube
It is clear that we have 6-control lines which will be responsible for the LED ON/OFF.
Out of these 6, Two lines i.e. Rows (R1,R2) are anodes(+).
The columns are Cathodes(-).
Working: To understand the working, let us consider that we want to ON an LED at position (C0,R1). For this we send a HIGH at R1 Terminal of cube through a transistor (A transistor is used because current through microcontroller is not sufficient to drive more than 1-2 LEDs) and a LOW at C0 terminal. This makes a complete path for the current and LED glows.
Similarly we can control ON/OFF state of all LEDs individually or in a group of two/three/four,etc.
“Delay” will help us to create different patterns.
Calculation of the pins required for cubes:
For 4x4x4 cube
Rows-4 pins
Columns- 4×4=16 pins
{ For 8x8x8 cube
Rows-8 pins
Columns- 8×8=64 pins (however 64 pins are not there in low profile uC, so this can be done through Shift Registers)
Similarly 16x16x16 and further can be constructed.
Current consumption by LEDs :
An important thing which must be kept in mind must be the current consumption by the LEDs.
Below Chart clears this point :
Fig. 3: Table listing Cube Size and LED Requirements
Explanation of the code :
· In the declaration part, we’ve associated Port-1 with rows and columns.
· Delay functions are declared and defined for different values.
· Functions for various patterns have been define under names such as p1(); p2(); p3(); p2f(); etc.
· In the main() part these functions are being called one by one and hence a continuous pattern is generated on the cube.
Screen shots:
Fig. 4: Image of 4-LED Cube
Fig. 5: Image of 4-LED Cube glowing on a breadboard
Fig. 6: Prototype of 4-LED Cube
Project Source Code
###
Code :#include<reg51.h>sbit c0=P1^2; // Column 0sbit c1=P1^3; // Column 1sbit c2=P1^4; //Column 2sbit c3=P1^5; // Column 3sbit r2=P1^1; // Row 2sbit r1=P1^0; // Row 1void delay(int); // Delay function declaration (large delay)void delay1(int); // Delay function declaration (short delay)void p1(); //void p2(); //void p3(); //void p4(); // Functions for various patternsvoid p1f(); //void p2f(); //void p3f(); //void p4f(); //void main() // main(){while(1){c0=c1=c3=c2=0;r1=r2=1;p1();p2();p3();p4();p1f();p2f();p3f();p2f();p1f();p4();p3();p2();p1();}}void delay(int t) // delay definition{int i,j;for(i=0;i<t;i++)for(j=0;j<1000;j++);}void delay1(int t) // delay definition{int i,j;for(i=0;i<t;i++)for(j=0;j<3275;j++);}void p1(){r1=r2=1; //pattern 1c0=0;c1=1;c2=1;c3=1; //delay1(8);c0=1;c1=0; //c2=1;c3=1;delay1(8); //c0=1;c1=1; //c2=0;c3=1;delay1(8); //c0=1;c1=1;c2=1; //c3=0;delay1(8);r1=r2=1; //repeating pattern 1c0=0;c1=1;c2=1;c3=1; //delay1(8);c0=1;c1=0;c2=1; //c3=1;delay1(8);c0=1; //c1=1;c2=0;c3=1;delay1(8); //c0=1;c1=1; //c2=1;c3=0;delay1(8);r1=r2=1; //pattrn 1 Repeatc0=0;c1=1;c2=1; //c3=1;delay1(8);c0=1;c1=0;c2=1;c3=1; //delay1(8);c0=1; //c1=1;c2=0;c3=1; //delay1(8);c0=1; //c1=1;c2=1;c3=0;delay1(8);r1=r2=1; // finishing of pattern 1c0=0;c1=1;c2=1;c3=1;delay1(8);}void p2(){r1=1; //pattern 2r2=0;c0=c1=0;c2=c3=1; //delay1(8);r1=0;r2=1;c0=c1=0;c2=c3=1;delay1(8);r1=0;r2=1;c0=c1=1; //c2=c3=0;delay1(8);r1=1;r2=0;c0=c1=1;c2=c3=0;delay1(8); //r1=1; // pattern 2 repeatr2=0;c0=c1=0;c2=c3=1;delay1(8);r1=0;r2=1; //c0=c1=0;c2=c3=1;delay1(8);r1=0;r2=1;c0=c1=1; //c2=c3=0;delay1(8);r1=1;r2=0;c0=c1=1;c2=c3=0;delay1(8);r1=1; //pattern 2 repeatingr2=0;c0=c1=0;c2=c3=1;delay1(8);r1=0;r2=1;c0=c1=0;c2=c3=1; //delay1(8);r1=0;r2=1;c0=c1=1;c2=c3=0;delay1(8); //r1=1;r2=0;c0=c1=1; //c2=c3=0;delay1(8);r1=1; // pattern 2 repeatr2=0;c0=c1=0;c2=c3=1;delay1(8);r1=0;r2=1; //c0=c1=0;c2=c3=1;delay1(8);r1=0;r2=1;c0=c1=1;c2=c3=0;delay1(8);//r1=1;r2=0;c0=c1=1;c2=c3=0;delay1(8);r1=1; // finishing of patt. 2r2=0;c0=c1=0;c2=c3=1;delay1(8);}void p3(){r1=1;r2=0; // Pattern 3 repeatc0=0;c3=0;c1=c2=1;delay1(8);r2=1;r1=0;c0=c3=0;c1=c2=1;delay1(8);c1=c2=0;c0=c3=1;delay(8);r1=1;r2=0;c1=c2=0;c0=c3=1;delay1(8);r1=1;r2=0; // Pattern 3 repeatc0=0;c3=0;c1=c2=1;delay1(8);r2=1;r1=0;c0=c3=0;c1=c2=1; //delay1(8);c1=c2=0;c0=c3=1;delay(8);r1=1;r2=0; //c1=c2=0;c0=c3=1;delay1(8);r1=1;r2=0; // repeat Pattern 3c0=0;c3=0;c1=c2=1;delay1(8);r2=1;r1=0;c0=c3=0;c1=c2=1;delay1(8);c1=c2=0;c0=c3=1;delay1(8);r1=1;r2=0;c1=c2=0;c0=c3=1;delay1(8);r1=1;r2=0; // finishing Pattern 3c0=0;c3=0;c1=c2=1;delay1(8);}void p4(){r1=0;r2=1; //c0=0;c1=c3=c2=1;delay1(8);r2=0;r1=1;c1=0;c2=c0=c3=1; //delay1(8);r1=0;r2=1;c2=0;c1=c3=c0=1;delay1(8);//r2=0;r1=1;c3=0;c2=c0=c1=1;delay1(8);}void p1f(){r1=r2=1; //pattern 1 FASTc0=0;c1=1;c2=1;c3=1;delay(10);c0=1; //c1=0;c2=1;c3=1;delay(10);c0=1;c1=1;c2=0; //c3=1;delay(10);c0=1;c1=1;c2=1;c3=0;delay(10);r1=r2=1; //pattrn 1 Repeat FASTc0=0;c1=1;c2=1;c3=1;delay(10);c0=1; //c1=0;c2=1;c3=1;delay(10);c0=1;c1=1;c2=0; //c3=1;delay(10);c0=1;c1=1;c2=1;c3=0;delay(10);r1=r2=1; //pattrn 1 Repeatc0=0;c1=1;c2=1;c3=1; //delay(10);c0=1;c1=0;c2=1;c3=1; //delay(10);c0=1;c1=1;c2=0;c3=1;delay(10); //c0=1;c1=1;c2=1;c3=0;delay(10);r1=r2=1; // finishing of pattern 1c0=0;c1=1;c2=1;c3=1;delay(10);}void p2f(){r1=1; //pattern 2 FASTr2=0;c0=c1=0;c2=c3=1;delay(10);r1=0;r2=1;c0=c1=0;c2=c3=1;delay(10);r1=0;r2=1;c0=c1=1;c2=c3=0; //delay(10);r1=1;r2=0; //c0=c1=1;c2=c3=0;delay(10);r1=1; // pattern 2 repeat fastr2=0;c0=c1=0;c2=c3=1;delay(10);//r1=0;r2=1;c0=c1=0;c2=c3=1;delay(10);//r1=0;r2=1;c0=c1=1;c2=c3=0;delay(10);r1=1; //r2=0;c0=c1=1;c2=c3=0;delay(10);r1=1; //pattern 2 repeat FASTr2=0;c0=c1=0;c2=c3=1;delay(10);//r1=0;r2=1;c0=c1=0;c2=c3=1;delay(10);r1=0;r2=1; //c0=c1=1;c2=c3=0;delay(10);r1=1;r2=0;c0=c1=1;c2=c3=0;delay(10);r1=1; // pattern 2 repeat FASTr2=0;c0=c1=0;c2=c3=1;delay(10);r1=0;r2=1;c0=c1=0;c2=c3=1;delay(10); //r1=0;r2=1;c0=c1=1;c2=c3=0;delay(10);r1=1;r2=0;c0=c1=1;c2=c3=0;delay(10);r1=1; // finishing of patt. 2r2=0;c0=c1=0;c2=c3=1;delay(10);}void p3f(){r1=1;r2=0; // Pattern 3 FASTc0=0;c3=0;c1=c2=1;delay(10);r2=1;r1=0;c0=c3=0;c1=c2=1;delay(10);c1=c2=0;c0=c3=1;delay(10);r1=1;r2=0;c1=c2=0;c0=c3=1;delay(10);r1=1;r2=0; // repeat Pattern 3 FASTc0=0;c3=0;c1=c2=1;delay(10);r2=1;r1=0;c0=c3=0;c1=c2=1; //delay(10);c1=c2=0;c0=c3=1;delay(10);r1=1;r2=0;c1=c2=0;c0=c3=1;delay(10);r1=1;r2=0; // Pattern 3 repeat FASTc0=0;c3=0;c1=c2=1; //delay(10);r2=1;r1=0;c0=c3=0;c1=c2=1;delay(10);c1=c2=0; //c0=c3=1;delay(10);r1=1;r2=0;c1=c2=0; //c0=c3=1;delay(10);r1=1;r2=0; // finishing Pattern 3c0=0;c3=0;c1=c2=1;delay(10);}###
Circuit Diagrams
Filed Under: Electronic Projects
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.