Open Arduino

Enter Your Project for a chance to win a grand prize for the most innovative use of Arduino or a $200 shopping cart! The Birthday Special: Arduino Projects for Arduino Day!

Back to The Project14 homepage

Project14 Home
Monthly Themes
Monthly Theme Poll


This project started as an exercise playing with Neopixels.


We were having issues with the existing Hall Light we have and the constant lamp deaths.

Each time you went to buy a new lamp, a replacement device was cheaper.


I thought about using a cheap PIR coupled with a controller and neopixels.

Normally it would be dull and when triggered would steadily increase in brightness.





Simple choice really use a Digispark

There is only two I/O required, one input for the PIR trigger, and an Output to drive the NeoPixels.


The case was something I had used in a previous Design Challenge eLDERmon  EnOcean Sensors 4 and it still had the PIR.

Recycling or re-purposing has wonderful benefits sometimes.


During that challenge I came up with solution to fit a PIR detector just above a power outlet.




It is a piece of plastic cut to fit behind the power socket, with the housing stuck to it with double sided tape.



Some double sided foam tape help secure the Digispark and Neopixels in place for the trial.

About this stage I was getting the questions from the other half about why do we need this, how is that going to help, etc.





For once the software was relatively easy.

If there is nothing detected then the pixels are red with reduced brightness.


A Heartbeat changes one pixel to white every second and travels across the pixels.


When the PIR detects movement, the pixels change to white and ramp up to full brightness over 8-9 secs.







      Combining a PIR sensor to NeoPixel to produce a night light for the Hallway.
      If the PIR senses movement it slowly ramps up to white.
      Once the trigger disappears it changes to RED.
   Pin assignments
   P0  NeoPixels Data
   P2  PIR sensor
   Created 14 April 2016
   by Mark Beckett
   0.1  Initial Code  started 14 April 2016
   To Do :


  #include <adafruit_neopixel.h>
  #define PIN 0                           // neopixels are on this pin
  #define NUM_LEDS 8                      // How many leds in your strip?
  const int Pir_Trigger = 2;              // PIR output goes high when triggered
  ;const int ledpin = 13;
  int PIRState = 0;
  int ONMode ;                            // 1 = triggered (white), 0 = NIGHT mode (red)
  unsigned long TriggerTime;              // Time when PIR triggered
  unsigned long ONModeTime = 15000;       // Time the NEOPIXEL stays ON in MilliSecs
  unsigned long lastCheckTime;
  byte BrightnessVal = 32;        // (0-255) Brightness setting for NIGHT Mode (255 = full, 128 = half, 64 = 1/4) 
  byte HeartBeatLED = 0;          // (0-255) used to determine which LED to make white for the heartbeat

  // Parameter 1 = number of pixels in strip
  // Parameter 2 = Arduino pin number (most are valid)
  // Parameter 3 = pixel type flags, add together as needed:
  //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
  //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

    IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
    pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
    and minimize distance between Arduino and first pixel.  Avoid connecting
    on a live circuit...if you must, connect GND first.
  void setup() 

    // PIR trigger goes HIGH if it is set off and stays HIGH until it times out.
    pinMode (Pir_Trigger, INPUT);
    digitalWrite (Pir_Trigger, LOW);   // internal pull-down otherwise the pin floats.
    Display_NIGHTMode();               // ensure we start in NIGHT mode

  void loop() 
   // You must read the pin state to know what it is.  
   PIRState = digitalRead(Pir_Trigger);
   if(PIRState == HIGH)               // PIR is triggered
     TriggerTime = millis();
     if(ONMode == 0)
       ONMode = 1;     // Set to ON mode for timeout to work.

   if((PIRState == LOW)&& ONMode == 1)    // PIR not triggered but still not NIGHT mode.
     if ((millis() - TriggerTime) > ONModeTime)
       ONMode = 0;    // Set to NIGHT mode.

    // show that it is working
    if (((millis() - lastCheckTime) > 1000) && ONMode == 0)  // Every second while in NIGHT mode.
     lastCheckTime = millis();
  void Heartbeat()
    strip.setPixelColor(HeartBeatLED, 255,0,0);          // red;
    if (HeartBeatLED < (NUM_LEDS-1))
      HeartBeatLED ++;                          // used to determine which LED is the Heartbeat
      HeartBeatLED = 0;
    strip.setPixelColor(HeartBeatLED, 255,255,255);     // white;
  void Display_ONMode()
    //Brightness setting 255 = full, 128 = half, 64 = 1/4, 32 =1/8, 16 = 1/16
    for (int j=3; j<=255; j=j+4) //steps from 3 to 255 in steps of 4
      for (int i=0; i      {
        strip.setPixelColor(i, 255, 255, 255);          // white
  void Display_NIGHTMode()
    for (int i=0; i    {
      strip.setPixelColor(i, 255, 0, 0);          // red
      strip.setBrightness(BrightnessVal);         // use default setting;






So three cameras later and my D3200 had to be used.

Poor Lighting then bright lights must be the videographers nightmare.




I know it has inspired someone to copy and modify it.

He was rather shocked at how easy it was.