Arduino led matrix projects with ir sensor code.
In the video, I will show you how to control an 8x8 led matrix with arduino uno and ir sensor. Display a robot eye on an 8x8 led matrix and control the eye by hand gesture with the help of an ir sensor.
Component requirements:
1. Arduino uno.
2. 8x8 led matrix X 2
3. ir sensor X 3
4. Breadboard.
5. Jumpire wire.
Circuit Diagram:
- Connect 8x8 led matrix VCC pin to Arduino 5v pin and GND pin to Arduino GND pin. There is a mistake in the video on connecting VCC and GND connection.
- Connect led matrix DIN pin to Arduino 13 pin.
- Connect led matrix CS pin to Arduino 12 pin.
- Connect led matrix CLK pin to Arduino 11 pin.
First 8x8 led matrix | Second 8x8 led matrix |
---|---|
VCC | VCC |
GND | GND |
DIN | DIN |
CS | CS |
CLK | CLK |
- Connect IR's sensor GND pin to Arduino GND pin.
- Connect IR's sensor VCC pin to Arduino 5v pin.
- Connect first IR sensor out pin to Arduino pin 7.
- Connect second IR sensor out pin to Arduino pin 6.
- Connect third IR sensor out pin to Arduino pin 5.
5. Now the circuit is completed. Connect the Arduino Uno to the computer via USB cable.
6. Select your COM port and Arduino board.
7. Now, Upload the code and play with it.
Coding:
#include<LedControl.h>
//Define IR sensor
int irL = 7;
int irM = 6;
int irR = 5;
//Define 8x8 led matrix
int dataPin = 13;
int csPin = 12;
int clkPin = 11;
//No. of 8x8 led matrix
int noOFdevices = 2;
//Sleep to wokeup
byte sleep[8] = {B00000000, B00000000, B00000000, B00000000, B00000000, B00000000, B01111110, B00111100};
byte wokeup1[8] = {B00000000, B00000000, B00000000, B00000000, B00000000, B11111111, B01111110, B00111100};
byte wokeup2[8] = {B00000000, B00000000, B00000000, B00000000, B01111110, B10000001, B01000010, B00111100};
byte wokeup3[8] = {B00000000, B00000000, B00000000, B01111110, B10000001, B10011001, B01011010, B00111100};
byte wokeup4[8] = {B00000000, B00000000, B01111110, B10000001, B10011001, B10011001, B01000010, B00111100};
byte wokeup5[8] = {B00000000, B01111110, B10000001, B10011001, B10011001, B10000001, B01000010, B00111100};
byte wokeup6[8] = {B00111100, B01000010, B10000001, B10011001, B10011001, B10000001, B01000010, B00111100};
byte viewright1[8] = {B00111100, B01000010, B10000001, B10001101, B10001101, B10000001, B01000010, B00111100};
byte viewright2[8] = {B00111100, B01000010, B10000001, B10000111, B10000111, B10000001, B01000010, B00111100};
byte viewleft1[8] = {B00111100, B01000010, B10000001, B10110001, B10110001, B10000001, B01000010, B00111100};
byte viewleft2[8] = {B00111100, B01000010, B10000001, B11100001, B11100001, B10000001, B01000010, B00111100};
int eye_status = 0;
bool activate = false;
LedControl lc = LedControl(dataPin, clkPin, csPin, noOFdevices);
void setup() {
// pt your setup code here, to run once:
Serial.begin(9600);
for (int x = 0; x < noOFdevices; x++)
{
lc.shutdown(x, false); //The MAX72XX is in power-saving mode on startup
lc.setIntensity(x, 8); // Set the brightness to default value
lc.clearDisplay(x); // and clear the display
}
printByte(sleep);
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(irL) == 0 && digitalRead(irM) == 0 && digitalRead(irR) == 0 ) {
eye_status = 1;
delay(500);
}
if (digitalRead(irL) == 1 && digitalRead(irM) == 0 && digitalRead(irR) == 1 ) {
printByte(wokeup1);
delay(100);
printByte(wokeup2);
delay(100);
printByte(wokeup3);
delay(100);
printByte(wokeup4);
delay(100);
printByte(wokeup5);
delay(100);
eye_status = 2;
activate = true;
}
if (digitalRead(irL) == 0 && digitalRead(irM) == 1 && digitalRead(irR) == 1 && activate == true) {
printByte(viewleft1);
delay(100);
eye_status = 3;
}
if (digitalRead(irL) == 1 && digitalRead(irM) == 1 && digitalRead(irR) == 0 && activate == true) {
printByte(viewright1);
delay(100);
eye_status = 4;
}
switch (eye_status) {
case 1:
printByte(sleep);
break;
case 2:
printByte(wokeup6);
delay(100);
break;
case 3:
printByte(viewleft2);
delay(100);
break;
case 4:
printByte(viewright2);
delay(100);
break;
default:
printByte(sleep);
break;
}
}
void printByte(byte character [])
{
int i = 0;
for (i = 0; i < 8; i++)
{
lc.setRow(0, i, character[i]);
lc.setRow(1, i, character[i]);
}
}
Watch This Tutorial:
Tags:
arduino 8x8 led matrix eye, arduino matrix projects, arduino led matrix projects Simple arduino projects. #arduinoprojects
arduino 8x8 led matrix eye, arduino matrix projects, arduino led matrix projects Simple arduino projects. #arduinoprojects