Practical No. 6: Interface 4 4 LED Matrix With AVR and Develop A C Program To Display Various Patterns. Aim

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Practical No.

6: Interface 4*4 LED matrix with AVR and develop a C program to display
various patterns.

Aim : To interface a 4x4 LED matrix with an AVR microcontroller and develop a C program to display
various patterns on the matrix.

Objective:

To connect a 4x4 LED matrix to an AVR microcontroller.


To write and compile a C program for controlling the LED matrix.
To display different patterns and animations on the matrix.

Materials Needed:
AVR microcontroller (e.g., ATmega328P)
16 Red LED
16 220 Ω Resistor

Procedure:
Initialization (setup function):

 Set All Pins as Outputs:


o Configure digital pins 0-13 and analog pins A0, A1 as OUTPUT.

Main Loop (loop function):

 Toggle Each Pin Individually:


o For each pin (0-13, A0, A1):
 Set the pin HIGH.
 Wait for a milliseconds.
 Set the pin LOW.
 Wait for a milliseconds.
 Turn All Pins On:
o Set all pins (0-13, A0, A1) HIGH.
o Wait for b milliseconds.
 Turn All Pins Off:
o Set all pins (0-13, A0, A1) LOW.
o Wait for b milliseconds.
 Repeat the On/Off Cycle:
o Turn all pins on again.
o Wait for b milliseconds.
o Turn all pins off again.
o Wait for b milliseconds.
 Loop: Repeat the entire sequence continuously.

.
1 2 3 4 5 6

R1 R2 R4 R3 R6 R7

220 D16 D15 220 D14 220 D13 220 D12 220 220 D11
RED RED RED RED RED RED
A A
U1_D5
U1_D4
U1_D3
U1_D2
U1_TX
U1_RX
U1_GND

U1_GND

U1
VIN RX
B 5V TX B
3.3V D2
D3
AREF D4
IOREF D5
RES D6
D7
A0
Arduino D8
R8 R9 R10 R11
A1
UNO D9
220 220 A2 D10 220 220
D10 D9 D8 D7
RED RED A3 D11 RED RED
A4 D12
A5 D13
SDA
GND SCL

C U1_RX
C
U1_TX
U1_D2
U1_D3
U1_D4
U1_D5
U1_A0
U1_A1

U1_D10
U1_D11
U1_D12
U1_D13

U1_GND
D D

R12 R13 R14 R15 R16 R17

220 D6 220 D5 220 D4 220 D3 220 D1 220 D2


RED RED RED RED RED RED

U1_A0
U1_A1
U1_D13
U1_D12
U1_D11
U1_D10
U1_GND

E E

Title: Interface 4*4 LED matrix

Made with Tinkercad® Date: 8/25/2024, 2:02:21 PM Sheet: 1/1


Setup Diagram:

Flow Chart:
Code:

int a = 100;
int b = 300;
void setup()
{
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
}

void loop()
{
digitalWrite(0, HIGH);
delay(a);
digitalWrite(0, LOW);
delay(a);
digitalWrite(1, HIGH);
delay(a);
digitalWrite(1, LOW);
delay(a);
digitalWrite(2, HIGH);
delay(a);
digitalWrite(2, LOW);
delay(a);
digitalWrite(3, HIGH);
delay(a);
digitalWrite(3, LOW);
delay(a);
digitalWrite(4, HIGH);
delay(a);
digitalWrite(4, LOW);
delay(a);
digitalWrite(5, HIGH);
delay(a);
digitalWrite(5, LOW);
delay(a);
digitalWrite(6, HIGH);
delay(a);
digitalWrite(6, LOW);
delay(a);
digitalWrite(7, HIGH);
delay(a);
digitalWrite(7, LOW);
delay(a);
digitalWrite(8, HIGH);
delay(a);
digitalWrite(8, LOW);
delay(a);
digitalWrite(9, HIGH);
delay(a);
digitalWrite(9, LOW);
delay(a);
digitalWrite(10, HIGH);
delay(a);
digitalWrite(10, LOW);
delay(a);
digitalWrite(11, HIGH);
delay(a);
digitalWrite(11, LOW);
delay(a);
digitalWrite(12, HIGH);
delay(a);
digitalWrite(12, LOW);
delay(a);
digitalWrite(13, HIGH);
delay(a);
digitalWrite(13, LOW);
delay(a);
digitalWrite(A0, HIGH);
delay(a);
digitalWrite(A0, LOW);
delay(a);
digitalWrite(A1, HIGH);
delay(a);
digitalWrite(A1, LOW);
delay(a);
digitalWrite(A1, HIGH);
delay(a);
digitalWrite(A1, LOW);
delay(a);
digitalWrite(A0, HIGH);
delay(a);
digitalWrite(A0, LOW);
delay(a);
digitalWrite(13, HIGH);
delay(a);
digitalWrite(13, LOW);
delay(a);
digitalWrite(12, HIGH);
delay(a);
digitalWrite(12, LOW);
delay(a);
digitalWrite(11, HIGH);
delay(a);
digitalWrite(11, LOW);
delay(a);
digitalWrite(10, HIGH);
delay(a);
digitalWrite(10, LOW);
delay(a);
digitalWrite(9, HIGH);
delay(a);
digitalWrite(9, LOW);
delay(a);
digitalWrite(8, HIGH);
delay(a);
digitalWrite(8, LOW);
delay(a);
digitalWrite(7, HIGH);
delay(a);
digitalWrite(7, LOW);
delay(a);
digitalWrite(6, HIGH);
delay(a);
digitalWrite(6, LOW);
delay(a);
digitalWrite(5, HIGH);
delay(a);
digitalWrite(5, LOW);
delay(a);
digitalWrite(4, HIGH);
delay(a);
digitalWrite(4, LOW);
delay(a);
digitalWrite(3, HIGH);
delay(a);
digitalWrite(3, LOW);
delay(a);
digitalWrite(2, HIGH);
delay(a);
digitalWrite(2, LOW);
delay(a);
digitalWrite(1, HIGH);
delay(a);
digitalWrite(1, LOW);
delay(a);
digitalWrite(0, HIGH);
delay(a);
digitalWrite(0, LOW);
delay(b);
digitalWrite(0, HIGH);
digitalWrite(1, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(6, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
digitalWrite(A0, HIGH);
digitalWrite(A1, HIGH);
delay(b);
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(6, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
digitalWrite(A0, LOW);
digitalWrite(A1, LOW);
delay(b);
digitalWrite(0, HIGH);
digitalWrite(1, HIGH);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(6, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);
digitalWrite(A0, HIGH);
digitalWrite(A1, HIGH);
delay(b);
digitalWrite(0, LOW);
digitalWrite(1, LOW);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(6, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
digitalWrite(A0, LOW);
digitalWrite(A1, LOW);
delay(b);
}
Results:

Patterns displayed on the LED matrix include:


Sequential blinking from bottom to top.
Sequential blinking from top to bottom
Blinking all pins simultaneously ON and OFF.
Repeat blinking of all pins

Interpretation of Results:

The experiment effectively demonstrated the integration of a 4x4 LED matrix with an AVR
microcontroller. Various patterns such as Sequential blinking from bottom to top, Sequential blinking
from top to bottom, Blinking all pins simultaneously ON and OFF, Repeat blinking of all pins were
displayed accurately. The LED matrix functioned as expected, with clear patterns and minimal issues,
validating the successful implementation of both the hardware and software components.

Conclusion:

The project achieved its goals by successfully interfacing the 4x4 LED matrix with the AVR
microcontroller and displaying various patterns using a C program. This demonstrated the
microcontroller's capability to control visual outputs and provided insights into practical applications.
Future improvements could focus on enhancing display resolution and adding interactive features.

You might also like