Outdoor Motion Activated LED Light

Following on from my recent wearable project, I was asked to build an outdoor motion activated LED light for the front door. I had briefly read about PIR sensors a few weeks ago, and I was keen to give it a go.

Originally I was going to use some, or perhaps all, of my left over NeoPixel strip, as it has a weatherproof sheath, but I decided that it just wasn’t quite right for the project. Instead I settled on an Adafruit 16 LED NeoPixel Ring, which is crazy bright – don’t look directly at one! Also, I needed a new microcontroller, seeing as I had hard wired the Flora into my wearable project, but this time I wanted to try out the Gemma and the Trinket. For this project I’ll be using a 5V Trinket, but you could just as easily use a Gemma, and probably a Flora too!

Unlike last time, I wasn’t prepared to wait three weeks for delivery from the states, nor was I prepared to play the customs charge lottery, so instead I looked for some UK suppliers, and I was pleasantly surprised at both the range of carried Adafruit tech and the speed at which they arrived at my door.

From Coolcomponents.co.uk I bought:

And from 4tronix.co.uk I bought:

(Of course, all of those products can also be bought from Adafruit if you are in the US. And if you’re not in the US or the UK, click here.)

Combined with the NeoPixel strip I have left over, and the project box I bought from Adafruit but haven’t yet used, this haul should keep me going for a little while.

Arduino IDE

Naturally the first place to start is the Arduino IDE, as in its standard form, it won’t let you programme the Gemma or the Trinket. Adafruit’s learning system has a tutorial on this, but from my experience, it doesn’t completely work. As I expected, the Adafruit issued IDE still doesn’t open, so I have to set up the IDE “The Slow Way”, and what I have found is that if you follow the instructions to the end, it does, for the most part work, right up until you try to verify a sketch. The problem is with the “pins_arduino.h” file, in “/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino”. The IDE seems not to want to look for the appropriate pins file when you change board in the Tools menu, so instead I have to manually change the pins file to the right one, which means my /cores/arduino/ folder look like this:

cores-arduino-pins

As it stands now, I can programme a Trinket or a Gemma. If in the future I want to programme a Flora, I will need to rename the file “pins_arduino.h” to “pins_arduino.gemmah”, and then rename the file “pins_arduino.florah” to “pins_arduino.h”. After that, if I want to programme a Gemma or Trinket again, I have to do that again, but in reverse. I’m not sure exactly why this has happened, but the work around I have come up with works, so that is what I’ll do for the time being.

Code

With the IDE tediousness out of the way, its time to start programming. As a starting point, I took two different Adafruit projects, the Trinket-Powered Conference Room Occupancy Display and the Light-Activated Pixel Heart, and combined them to produce the following code:

#include <Adafruit_NeoPixel.h>
#define PIN 1
Adafruit_NeoPixel strip = Adafruit_NeoPixel(16, PIN, NEO_GRB + NEO_KHZ800);
const int PIRpin = 0; // PIR signal pin on Trinket Pin #0
uint8_t pirState = LOW; // Stores state of the PIR sensor

void setup() {
 pinMode(PIRpin, INPUT); // Initial state is low
 strip.begin();
 strip.show(); // Initialize all pixels to 'off'
}

void loop() {
 int sense = digitalRead(PIRpin); // Read PIR Sensor
 if(sense == HIGH) { // If high and it was low, sensor tripped
 if(pirState == LOW) { // and we display a light
 colorWipe(strip.Color(255, 255, 255), 1); // animate White
 pirState = HIGH;
 }
 } else {
 if(pirState == HIGH) { // If low and state was high, sensor set
 delay(60000);
 colorWipe(strip.Color(0, 0, 0), 1); // animate OFF
 pirState = LOW;
 }
 }

}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
 for(uint16_t i=0; i<strip.numPixels(); i++) {
 strip.setPixelColor(i, c);
 strip.show();
 delay(wait);
 }
}

So with this code, the Trinket will light up the NeoPixel Ring for 60 seconds when the PIR detects movement. (Also, being that it’s a NeoPixel Ring, it will be very easy to reprogramme at Christmas with green and red dancing LEDs, rather than a simple white.)

During the early stages of the programming, I was using my left over NeoPixel Strip, which is why you will see a Strip in this video and not a Ring, it was during this testing that I decided that the Strip simply wasn’t right for this project. (Also notice that I was using a Gemma, as they are easier to prototype with.)

The Strip served its purpose, and that’s all I wanted. The next step was to play with the PIR. I wanted to see if the sensor would still function if it was placed entirely in the box (it has a transparent top), but it didn’t, so I whipped out the callipers, and ended up with a 25mm hole in the (almost) centre of the top of the box:

ProjectBoxwith25mmHole

If you can find a 24mm Flat Wood drill bit, that would be better. 25mm is just ever so slightly too big, but some Sugru will deal with the gap.

In the video below, you can see how the lens of the PIR fits through the hole, but doesn’t fall through. This allows the PIR to do its job; tell the Trinket when there’s movement, so that the Trinket can light up the ring.

In the image below you can see that the PIR fits snuggly inside the NeoPixel ring (which is really helpful). This is how the ring and PIR will be mounted in the final build. (I’ve already tested that the light from the ring doesn’t affect the PIRs functions.)

PIR and NeoPixel Ring

Solder & Build our outdoor motion activated LED light

Putting all these small pieces together, using very short leads and keeping the whole package nice and tight was a difficult business.

The first step involved soldering the leads onto the Trinket itself. I know that most people will go with the breadboard/perma-prototype solution, but my breadboard was playing up; I just couldn’t get a stable connection out of the Trinket, so I opted for the hard soldering route, and I’m glad I did. It works better than ever now!

This terrible image illustrates the circuit:

PIR Trinket LED Pixel Ring Circuit

I apologise for the crudity of that model, I didn’t have time to draw it to scale or to paint it.

This turns your Trinket into something with six horrible, insect like legs:

Adafruit Trinket 5V solder

After some testing I found that the Trinket worked perfectly, so I soldiered on with the rest of the build. First step was to hot glue-in the PIR lens, as without that, there would be a large gap in the case that would let in moister.  Next step was the make the rest of the connections, and I ended up with something like this:

IMG_3028

(I agree, some of those joints are terrible, but remember, I am still very new to soldering.)

With some Blu Tac holding it in place, the (almost) finished project looks like this:

IMG_3034

Installation

So, on an unusually warm Sunday in March, I set about installing my new light.  Unfortunately, I didn’t take many pictures, so I’ll just Explain briefly using this image:

Outdoor Motion Activated LED LightThe first step was to drill two 5mm holes  for the screw you can see in the red circle on the left (the other hole is diagonally right, near to the red square. The red square itself is a 12mm hole in the right flank of the box for the USB cable to enter the box. (The size of this hole will depend on the size of your USB cable.) After that, two 7mm holes were drilled into the mortar surrounding the central brick, then two rawl plugs, and then the opaque half of the box was screwed into place. The red circle on the right is another 12mm hole, this time in the 116mm deep door frame (took a while to drill that one), for the USB to exit the house from where it gets its power. Once everything is  ready, it’s time to Sugru up all the gaps and holes, et voilà! One Outdoor Motion Activated LED Light.

Outdoor Motion Activated LED Light

Products Used:

  • 1x Adafruit Trinket 5v
  • 1x Adafruit NeoPixel Ring (16LED)
  • 1x PIR Sensor
  • 1x Small Weatherproof Project Box
  • 1x 3m USB cable
  • 1x 3m 1 Gang Power extension cable
  • 1x Analogue Power Socket Timer
  • 3x 8g packets of Sugru

Tools Bought Specially:

  • 1x 5mm Wood Drill Bit
  • 1x 7mm Masonry Drill Bit
  • 1x 12mm Wood/Metal Drill Bit (151mm long)
  • 1x 25mm Flat Wood Drill Bit
  • 10x 1.5″ Wood screws

Necessary Tools:

  • 1x Soldering Iron (plus accoutrements)
  • 1x Safety Glasses (For, among other things, Soldering and drilling masonry above one’s head)

Author: Dan

Share This Post On