Projects/CorridorLight: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 1:
''==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 [https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/ 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.
Line 21:
 
 
''==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 ([http://www.home-automation-community.com/arduino-low-power-how-to-run-atmega328p-for-a-year-on-coin-cell-battery/ Arduino Low Power]).
Line 38:
 
 
''==First stage'': Functionality==
 
Started with writing down the way it should operate:
Line 81:
 
 
''==Second stage'': Simulation==
 
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
[[File:LED soft start.png|thumbnail|left|LED soft start circuit]]
* Op-amp as a comparator
[[File:Opamp as comparator.png|thumbnail|left|Op-amp as comparator]]
* AND gate with two NPN transistors
[[File:AND gate.png|thumbnail|left|AND gate with two NPN transistors]]
 
*Full schematic
[[File:Full schematic.png|thumbnail|left|Complete schematic]]
 
''==Third stage'': PCB Layout==
[[File:Fritzing schematic.png|thumbthumbnail|left|Fritzing model of the PCB]]
 
''==Final stage'': Soldering and testing==
Once I had all the components layed out in Fritzing I moved onto building the board and soldering them. Unfortunately, some of the components at hand didn't have the exact same model so after a little tweaking I managed to get a functioning board and I was able to test the results. One caveat was the potentiometer used to set the level of light which ended up being a multiturn version instead of the one depicted.
 
 
''==Result''==
[[File:Corridor Light Enclosure.jpg|thumbnail|left|Corridor light enclosure]]
[[File:Corridor Light Internal.jpg|thumbnail|left|Internal layout of corridor light]]
 
[[Category:Projects]]