Introduction: Multifunctional Power Control

A baby lamp with a difference. An original idea of an arduino controlled lamp and bottle warmer for a newly born's bedroom led me to this circuit. I wanted the following features;

1. Automatic dimming.

2. Automatic switch off without dimming.

3. Sound triggered activation with lamp predefined to a set brightness..

A fourth feature, remote playing of a bedtime lullaby has not been included yet as this would limit its use, and I am trying to keep this a 'general' use board people can hack.

So the idea was after putting a baby to bed you could walk away and set the lamp to dim over time. When the baby awoke in the night wanting feeding the lamp would come on at a preset level of brightness and the bottle warmer would switch on, warming the bottle.

The main point of this project was to learn how to use the MIT APP Builder .

Step 1: Circuit Requirement.

The basic requirement of the circuit is to control two mains sockets via Bluetooth. To do this required two triacs, devices which can control mains power. The problem here is that once a triac is switched on it cannot be turned off while a voltage is present, so we needed circuitry to detect when the AC mains signal was passing through zero volts. Once I knew when this happens via my 'zero crossover detection circuit' I could control power to the sockets to my hearts content. Before going any further I would like the following understood. Most of the components used were reclaimed. They were not my first choice but what I had available. I have neither the equipment or finance to improve the circuit and if someone wishes to take it upon themselves to improve it GREAT!

Step 2: Circuit Board

Mains power would be supplied to the box so I looked to see what transformers I had and found a 115v/230v transformer with two 6v outputs. One 6v output was to be used for power to the board and the other for zero crossover detection ( and possibly a 3.3v supply line if needed ). The live wire was fed via a connection strip to the transformer and one side of both triacs.

So the output from the first 6v winding was taken through a bridge rectifier ( reclaimed ) feeding a storage capacitor ( reclaimed ) and finally through a 5v regulator ( reclaimed ).

The second 6v output was fed to a load resistor and two diodes in parallel but with opposite polarities, which limited the voltage across the diodes which was then used to feed an op amp, with the overall effect that the output of the op amp was a mains frequency square wave. This square wave was given to the ATMEGA328P and the 'change' of the signal occurred at the zero crossover stage and was used to to trigger the INT0 signal of the micro controller..

Outputs from the arduino were sent to a photo coupler to drive the triacs. During development of the board I also placed an LED in series with the photocouplers which gave me visual indication of the pin state, before I added 'live' outputs.

Finally I extended the leads on the microphone to the sound sensor board to enable it to be attached through the box.

The circuit diagram is the best I could do with Fritzing, another piece of software I have to learn... :( The LED's are not shown connected as this makes the whole diagram a bigger mess than it is, however connection information is included elsewhere.

Parts.

HC-06 Bluetooth card.

Sound Sensor.

VTX-121-3015-406 Transformer

Bridge rectifier.

22000 micro farad electrolytic capacitor.

7805 Voltage regulator.

ATMEGA328P-PU

2 X MOC2032 Opto isolator.

2 X BTA08-600 Triacs

2 X IN4004 diodes.

3 x RED/GREEN tricolour led's ( Common Cathode )

6 X 220 Ohm resistors.

470k Resistor.

LM358 Op amp.

Plastic box. Maplins Geros Gr17008

Twin mains socket. Maplins.

Vero board.

Connection strip.

Tools

Hot glue gun.

Solder and iron

Screwdriver for use on twin socket and box.

Step 3: Connecting the Twin Socket

I purchased a box big enough for the board ( with future development in mind ) and room for a double mains socket.

Procedure. Open the socket. Using hot glue I placed the bottom of the socket where I wanted it to be. Once set I drilled four holes for the bolts to fix the socket in place, four more marking where the screw holes of the twin socket lid would be ( these holes would be made larger later to accommodate the screws ), four more for the wires between the twin mains socket and the control board, two near where the mains cable came in for power to the transformer, and two 'return' wires to feed the socket and finally another 3 to hold the power indication Led's..

Each LED had a 200 ohm resistor connected to both its anodes and all three cathodes were connected together and with ground. The Led's pins were shielded to prevent short circuit before all where hot glued into their final positions. The RED indicators were used to show the sockets was triggered to switch on ( by sound ) and to show that sound level monitoring was in operation on the power led. The GREEN led's were used to indicate power available at the sockets and mains indication on the POWER Led. .

The final thing to do before closing the twin socket was to cut the brass link between the live pin sockets and solder on the connecting wires. As there was room under the live pin socket connectors I placed in a small amount of hot glue to hold them in place until the twin socket lid was attached.

Step 4: Arduino Code

The basic idea of the code was simple, get an interrupt at the zero crossover point (CROSSOVER ROUTINE), reset a variable showing the percent of the half cycle left, then use another interrupt (PERCENT) to decrease this value, check if it matched the level assigned to one of the sockets and if so switched it on.

Note! Accuracy of the timing for the PERCENT interrupt can be adjusted and make the circuit auto adjust to compensate for fluctuations in mains frequency. If the percent variable is greater than zero atzero crossover time then decrease the interval between PERCENT triggers. IF the percent variable goes under 0 at PERCENT interrupt then increase the delay between PERCENT triggers.

The analogue reading of a pin could take up to 100 milli seconds ( Analog Read, Arduino ) which was to long and would mess up timings, so the reading was put into 'Free running Mode' where the micro controller would start doing the next conversion as soon as the readings from the last were taken (ATMEGA328P Chapter 28)

Finally all that was required was to test for serial activity from the Bluetooth device and act accordingly and test for the various operation, responding to those that needed action.

The code was developed with the Bluetooth device on a second, software serial port leaving the hardware serial port free for debugging. The code has been left this way to enable WIFI connection if needed.

A full explanation of the workings of the software are included in the source code which can be found in the working.txt file. Just copy / paste into Arduino IDE.

Step 5: MIT APP

Designing the MIT APP was much easier than anticipated and on examination can be easily understood. The only funny thing to note was that on reading the current device status from the device various checkbox trigger events fired, so the clock was used to disable them by use of a global variable 'initialize'.

The project is shared on MIT App inventor as 'TwoLightsBT' by Mick Press.