From Teesside Hackspace
< Projects
Revision as of 21:08, 28 February 2019 by Jimallanson (talk | contribs) (Jimallanson moved page PrjCorridorLight to Projects/CorridorLight)
Jump to navigation Jump to search

Short description

Replicate functionality of an Arduino project using analog components to create a night light that's photosensitive and detects motion.

A bit of history

Moved to a new place that has a corridor connecting all rooms but no natural lights so when all doors are shut, as it's usually the case for fire safety reasons, it's completely dark and also hard to find the light switches. I wanted to fit a night light that wouldn't be on all the time but also wouldn't be on when I have one of the doors open. My first prototype was based on Arduino Nano connecting three LEDs to three pins and using the analogwrite() function to dim the LEDs when they start up. For the motion detector I used a PIR sensor I bought some time ago and for the light detection I went for a photodiode instead of a light dependent resistor LDR. I had to reverse bias the photodiode and use an analog input on the Arduino Nano to detect when it was dark enough to turn the LEDs on. As for the power supply, I used a phone charger with USB output so that I can unplug and reprogram the Arduino as necessary. It does the job quite nicely and it has been working for three months but...

You could do that with a 555

It's one of the comments that most electronic hackers would make when such simple functionality is required. Indeed, it can be done with a 555, triggered with the two conditions of low light level and motion detection and driving some sort of transistor in case the power required by the LEDs was higher than what the 555 can supply.

What's a 555? And also, is that the right device for the application?

A 555 is basically a timer. It can work as a monostable and astable multivibrator. In plain words: it generates a voltage output that can be maintained for a variable time, can be triggered multiple times and can also be retriggered automatically thus generating a square wave signal (astable configuration). To change the different time constants only a capacitor and a couple of resistors are required so it's quite simple to implement.

I was using the analog output from the Arduino in a similar manner as the 555 could be configured to drive the LEDs but to achieve the same variation of duty cycles on the square wave I would have to change the capacitance or the resistors and that just complicates things. But, how complicated is 'complicated'? What am I trying to do exactly?

Designing an analog circuit from scratch

I use microcontrollers for pretty much every single project, no matter how big or small, and I don't care much about the efficiency of the result as I'm usually going for mains powered solutions. That doesn't mean that I'm not aware of the implications in terms of energy use and cost of components. Yeah, Arduino boards are super cheap and unless you want to run on battery power they don't use much energy but still, could I do better? The first idea was to put the Arduino to sleep with an interrupt but the voltage regulator would still be running so it doesn't really make a huge difference. I'm not the first one to consider this issue (Arduino Low Power).

So, as a challenge, I decided to improve the power consumption and remove the Arduino while keeping the functionality. To do so I would have to use analog circuits and perhaps a logic gate, and if that was the case then it would be my first fully analog circuit. I know the basics but I've been more of an integrator than a designer so perhaps it's a good excuse to follow some methodology that will help reduce the developing time:

  • Describe the functionality and generate a logic diagram
  • Split the functionality into different blocks that can be tested individually
  • Select the components that are required for each block
  • Simulate each block
  • Build the circuit on a protoboard and test functions individually
  • Integrate and stress-test all of them in one circuit
  • Generate a PCB layout
  • Solder the components and build the prototype
  • Write things down on every step!!!

First stage

Started with writing down the way it should operate:

  • Light turns on when it's dark enough and it detects movement
  • It stays on for a certain time
  • Can be retriggered if it detects continous movement
  • It has soft start around two seconds from zero to full brightness
  • It needs to be able to drive three LEDs
  • Low power consumption when idle
  • Powered from a mains socket
  • It has to be small enough and look good when finished

Breaking down the functionality into chunks:

  • Motion sensor
  • Retriggering
  • Light sensor
  • Comparator
  • AND gate
  • Timer
  • LED driver
  • Soft start filter
  • LEDs
  • Power supply
  • Enclosure
  • Plug

In order to select the components I had a look at the box of bits that I've been collecting over time. I started with an individual op-amp and realised that the voltage and current provided by the motion sensor were insufcient to operate the AND gate properly. I tried a few configurations until I found one that worked:

  • Motion sensor, timer and retriggering -> PIR motion sensor HC-SR501
  • Light sensor -> Photodiode
  • Comparator -> Dual operational amplifier MCP6042
  • AND gate -> Two BC639 NPN bipolar transistors in series
  • LED driver -> One BC639 transistor
  • Soft start filter -> RC network with 200uF electrolitic capacitor and 10k potentiometer
  • LEDs -> Three 5mm high brightness white LEDs
  • Power supply -> Hewlett Packard LPS AC/DC Adaptor P/N 157-10157-00
  • Enclosure -> UK single gang surface mount back box 86 x 86 x 32mm
  • Plug -> Flat three pin UK plug (front of a standard plug trimmed to be as flat as possible)
  • Auxiliary -> Wires and resistors

Second stage

Before I started putting everything together I wanted to be sure that the setup was correct so I used a circuit simulator to check the values of the resistors needed. In order to do that I splitted the functions into different circuits and tested each one individually to get more familiar with them:

  • LED driver and soft starter


  • Op-amp as a comparator


  • AND gate with two NPN transistors