Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
coriscofalfcamilaacirnethiagoh17lainereisss
Published © CC BY-NC-SA

LED Matrix 32x16 RGB & Ultrasonic Sensor

An art experiment with 2 x 16 x 16 RGB LED matrix that lights in random positions and colors when the ultrasonic sensor is triggered.

BeginnerFull instructions provided2,905
LED Matrix 32x16 RGB & Ultrasonic Sensor

Things used in this project

Hardware components

Arduino UNO Wifi Rev.2
Arduino UNO Wifi Rev.2
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
16x16 RGB LED Matrix WS2812B
×2
5V 40A Power Supply
×1
Jumper wires (generic)
Jumper wires (generic)
×8

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

Laser cutter box

Schematics

Circuit View

Code

SYNERGYALEDMATRIX32x16.ino

Arduino
//SYNERGYA 32x16 
//LED MATRIX WITH ULTRASONIC SENSOR
//by Camila Cirne, Francisco Luz, Gislaine Reis, Pedro Coelho and Thiago Arajo

#include <Ultrasonic.h> // Add the Ultrasonic by Erick Simes' library
#include "FastLED.h" // Add FastLED library

#define NUM_LEDS 512 // set the number of LEDS (for 1 matrix 256, for 2 matrices 512 and so on...)
#define DATA_PIN 3 // set the pin number from the Arduino board
CRGB leds[NUM_LEDS];

const int someoneArrivedPin = 7;  // set the TRIG terminal in the Arduino board from the Ultrasonic sensor
const int someoneLeftPin = 6; // set the ECHO terminal in the Arduino board from the Ultrasonic sensor

void setup() {
  delay(2000);
  FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS); // WS2812B is the matrix model were using
  FastLED.setBrightness(150); // Setup the general brightness (0-255)
  FastLED.clear();
  Serial.begin(9600); // Start the serial port to initialize the ultrasonic sensor
  pinMode(someoneArrivedPin, OUTPUT);  // set OUTPUT and INPUT accordingly to the ultrasonic sensor library
  pinMode(someoneLeftPin, INPUT);
}

Ultrasonic ultrasonic(someoneArrivedPin, someoneLeftPin);

int randomInt;
int randomInt2;

void loop() {
  for(int i = 0; i < 10; i++){ // Outerloop
    for(int j = 0; j < 1000; j++){ // TURN LEDS ON - Innerloop
        if (ultrasonic.read() > 10 and ultrasonic.read() <=100){ // Return the distance in cm in the if condition
          randomInt = (rand()%512); // random intenger that chooses the leds which will be turn on
          randomInt2 = (rand()%256); // random intenger that chooses the color Hue of the given leds
          leds[randomInt].setHue(randomInt2);
          FastLED.show();
        }
     } 
    for(int k = 512; k > 0; k--){ // TURN LEDS OFF - 2nd Innerlooop
      leds[k] = CRGB::Black;
      FastLED.show();
    }
  }
}

Credits

corisco
0 projects • 0 followers
falf
0 projects • 0 followers
camilaacirne
0 projects • 0 followers
thiagoh17
0 projects • 0 followers
lainereisss
0 projects • 0 followers

Comments