Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Tauno Erik
Published © GPL3+

The Lion lamp

Internally illuminated artwork that reacts to people

BeginnerFull instructions provided8 hours1,349

Things used in this project

Hardware components

Adafruit NeoPixel Digital RGB LED Strip 144 LED, 1m White
Adafruit NeoPixel Digital RGB LED Strip 144 LED, 1m White
×1
RCWL-0516 Microwave Radar Motion Detector
×1
Arduino Nano R3
Arduino Nano R3
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Lion Lamp code

Arduino
/*
Lõvi lamp
Tauno Erik
17.02.2023
*/
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>

const uint8_t RADAR_PIN = 4;
const uint8_t RGB_PIN = 3;
const uint8_t NUMPIXELS = 49;

uint8_t r = 0;
uint8_t g = 0;
uint8_t b = 0;

bool is_movement = false;
bool change_color = false;

uint32_t time_px_prev = 0;  // Millis
uint16_t px_interval = 50;  // Millis
const uint16_t OFF_TIME = 30000;
uint32_t no_movment_time = 0;

Adafruit_NeoPixel pixels(NUMPIXELS, RGB_PIN, NEO_GRB + NEO_KHZ800);

// Fill pixels pixels one after another with a color. pixels is NOT cleared
// first; anything there will be covered pixel by pixel. Pass in color
// (as a single 'packed' 32-bit value, which you can get by calling
// pixels.Color(red, green, blue) as shown in the loop() function above),
// and a delay time (in milliseconds) between pixels.
void colorWipe(uint32_t color, int wait) {
  for(int i=0; i<pixels.numPixels(); i++) { // For each pixel in pixels...
    pixels.setPixelColor(i, color);         //  Set pixel's color (in RAM)
    pixels.show();                          //  Update pixels to match
    delay(wait);                           //  Pause for a moment
  }
}


// Rainbow cycle along whole pixels. Pass delay time (in ms) between frames.
void rainbow(int wait) {
  // Hue of first pixel runs 5 complete loops through the color wheel.
  // Color wheel has a range of 65536 but it's OK if we roll over, so
  // just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
  // means we'll make 5*65536/256 = 1280 passes through this loop:
  for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
    // pixels.rainbow() can take a single argument (first pixel hue) or
    // optionally a few extras: number of rainbow repetitions (default 1),
    // saturation and value (brightness) (both 0-255, similar to the
    // ColorHSV() function, default 255), and a true/false flag for whether
    // to apply gamma correction to provide 'truer' colors (default true).
    pixels.rainbow(firstPixelHue);
    // Above line is equivalent to:
    // pixels.rainbow(firstPixelHue, 1, 255, 255, true);
    pixels.show(); // Update pixels with new contents
    delay(wait);  // Pause for a moment
  }
}


void setup() {
  pinMode(RADAR_PIN, INPUT);
  
  pixels.begin();
  pixels.show();            // Turn OFF all pixels ASAP
  pixels.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)

  randomSeed(analogRead(0));
  //rainbow(5);
}

void loop() {
  uint32_t time_now = millis();

  is_movement = digitalRead(RADAR_PIN);

  if (is_movement) {
    change_color = true;
    no_movment_time = time_now;
  } else {
    change_color = false;
  }

   // All LEDs off
  if (time_now - no_movment_time >= OFF_TIME) {
    colorWipe(pixels.Color(0, 0, 0), 0);
  }

  // Colour change routine
  if (time_now - time_px_prev >= px_interval) {
    time_px_prev = time_now;

    if (change_color) {
      r = random(0, 255);
      g = random(0, 255);
      b = random(0, 255);
      colorWipe(pixels.Color(r, g, b), 50); // Blue
      change_color = false;
    }
  }


}

Credits

Tauno Erik

Tauno Erik

24 projects • 57 followers
learning somthing new

Comments