Display Interativo de Matriz LED na Porta com Sensor PIR – Saudação de Férias Arduino
Componentes e materiais
| Componente | Quantidade |
|---|---|
| Arduino UNO | 1 |
| Arduino Nano R3 | 1 |
| Sensor de Movimento PIR (genérico) | 1 |
| Relé (genérico) | 1 |
| Fios jumper (genéricos) | 1 |
| Cabo de alimentação PC PSU | 1 |
| Fita LED RGB | 1 |
| Painel Neopixel 8x8 | 3 |
Ferramentas necessárias
- Ferro de solda (genérico)
- Descascador de fios
Sobre o projeto
Este projeto combina 3 matrizes RGB LED WS2812B 8x8 e um sensor de movimento PIR para saudar visitantes com um texto dizendo "Happy Holidays & Happy New Year!" quando estão perto o suficiente da porta e exibir um conjunto de efeitos como um screensaver em monitores quando o sensor não detecta ninguém por perto.
É controlado por um Arduino UNO e alimentado por uma fonte 5V 30A.
Eu combinei 3 conjuntos de códigos. Os da biblioteca FastLED DemoReel100 Example para os Efeitos Idle/Standby. O código do Sensor de Movimento PIR. E o código de configuração do Neopixel, acho. Não tenho mais certeza, tbh, já que foi quase um mês atrás quando misturei os códigos.
Também usei outro sensor PIR conectado a um Relé 5V com uma Fita LED RGB 12V via cabo de extensão e controlado por um Arduino Nano.
A Fita LED, junto com as luzes de natal que também estão conectadas ao cabo de extensão, é ativada quando o 1º sensor PIR detecta movimento. Ele está localizado no teto perto do 1º degrau da escada.
Após alguns degraus subindo, o 2º sensor PIR diz ao UNO para mostrar o display de texto nas matrizes quando alguém está perto o suficiente da porta.
Código
Arduino Holiday
#include
FASTLED_USING_NAMESPACE
#include
#include
#include
#ifndef PSTR
#define PSTR // Make Arduino Due happy
#endif
#define PIN 6
#define DATA_PIN 6
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS 192
CRGB leds[NUM_LEDS];
const uint8_t kMatrixWidth = 24;
const uint8_t kMatrixHeight = 8;
const bool kMatrixSerpentineLayout = true;
#define NUM_LEDS (kMatrixWidth * kMatrixHeight)
#define MAX_DIMENSION ((kMatrixWidth>kMatrixHeight) ? kMatrixWidth : kMatrixHeight)
#define BRIGHTNESS 50
#define FRAMES_PER_SECOND 120
static uint16_t x;
static uint16_t y;
static uint16_t z;
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(24, 8, PIN,
NEO_MATRIX_TOP + NEO_MATRIX_RIGHT + NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE,
NEO_GRB + NEO_KHZ800);
const uint16_t colors[] = {
matrix.Color(255, 0, 0),
matrix.Color(0, 255, 0),
matrix.Color(0, 0, 255),
matrix.Color(0, 255, 255),
matrix.Color(255, 0, 255),
matrix.Color(255, 255, 0),
matrix.Color(255, 255, 255)
};
uint16_t speed = 20;
uint16_t scale = 30;
uint8_t noise[MAX_DIMENSION][MAX_DIMENSION];
CRGBPalette16 currentPalette(PartyColors_p);
uint8_t colorLoop = 1;
int pirSensorPin = 5;
int pirState = true;
int val = 0;
int minimummSecsLowForInactive = 5000;
long unsigned int timeLow;
boolean takeLowTime;
int calibrationTime = 30;
void setup() {
delay(3000);
FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
matrix.setTextWrap(false);
matrix.setBrightness(40);
matrix.setTextColor(colors[0]);
pinMode(pirSensorPin, INPUT);
LEDS.addLeds(leds, NUM_LEDS);
x = random16();
y = random16();
z = random16();
}
int a = matrix.width();
int pass = 0;
typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = {rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm, cylon};
uint8_t gCurrentPatternNumber = 0;
uint8_t gHue = 0;
void fadeall() {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i].nscale8(250);
}
}
void loop() {
val = digitalRead(pirSensorPin);
if (val == HIGH) {
matrix.fillScreen(1);
matrix.setCursor(a, 0);
matrix.print(F("Happy Holidays & Happy New Year!"));
if (--a < -200) {
a = matrix.width();
if (++pass >= 6) pass = 0;
matrix.setTextColor(colors[pass]);
}
matrix.show();
delay(100);
if (pirState) {
pirState = false;
}
takeLowTime = true;
} else {
gPatterns[gCurrentPatternNumber]();
FastLED.show();
FastLED.delay(1000 / FRAMES_PER_SECOND);
EVERY_N_MILLISECONDS(20) { gHue++; }
EVERY_N_SECONDS(10) { nextPattern(); }
}
}
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
void nextPattern() {
gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE(gPatterns);
}
void rainbow() { fill_rainbow(leds, NUM_LEDS, gHue, 7); }
void rainbowWithGlitter() {
rainbow();
addGlitter(80);
}
void addGlitter(fract8 chanceOfGlitter) {
if (random8() < chanceOfGlitter) {
leds[random16(NUM_LEDS)] += CRGB::White;
}
}
void confetti() {
fadeToBlackBy(leds, NUM_LEDS, 10);
int pos = random16(NUM_LEDS);
leds[pos] += CHSV(gHue + random8(64), 200, 255);
}
void sinelon() {
fadeToBlackBy(leds, NUM_LEDS, 20);
int pos = beatsin16(13, 0, NUM_LEDS - 1);
leds[pos] += CHSV(gHue, 255, 192);
}
void bpm() {
uint8_t BeatsPerMinute = 62;
CRGBPalette16 palette = PartyColors_p;
uint8_t beat = beatsin8(BeatsPerMinute, 64, 255);
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette(palette, gHue + (i * 2), beat - gHue + (i * 10));
}
}
void juggle() {
fadeToBlackBy(leds, NUM_LEDS, 20);
byte dothue = 0;
for (int i = 0; i < 8; i++) {
leds[beatsin16(i + 7, 0, NUM_LEDS - 1)] |= CHSV(dothue, 200, 255);
dothue += 32;
}
}
void cylon() {
static uint8_t hue = 0;
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CHSV(hue++, 255, 255);
FastLED.show();
fadeall();
delay(10);
}
for (int i = (NUM_LEDS) - 1; i >= 0; i--) {
leds[i] = CHSV(hue++, 255, 255);
FastLED.show();
fadeall();
delay(10);
}
}
Esquemáticos
Consulte o diagrama de conexões no projeto original.
Processo de manufatura
- Construa Seu Próprio LUMAZOID: Visualizador de Música DIY com Arduino
- Projeto DHT11: Sensor Temperatura/Umidade com LEDs Indicadores e Buzzer
- Monitor de Saúde de Rios: Sistema de Qualidade da Água Baseado em Arduino
- Construa um Sensor de Obstáculos Simples com Arduino – Tutorial Fácil com LED IR e Fotodiodo
- Find Me: Localizador Inteligente de Objetos com Arduino e Bluetooth
- Construa um Robô Quadrúpede Inteligente com Arduino: Guia Passo a Passo
- Pistola de Água Inteligente com Detecção de Movimento usando Arduino Nano
- Medição de Distância em Tempo Real com Sonar Arduino e Visualização no Processing
- Osciloscópio DIY com Arduino Nano (10 Hz–50 kHz) e LCD 128×64
- Relógio Flip Arduino com Matriz LED 8×8 – Projeto DIY de Relógio em Tempo Real