Saturday 26 December 2015

Audio Controlled Christmas Lights

So it's the run up to Christmas, and at work we're having a desk decorating competition. This of course means lights, and an excuse for some colourful, blinky-type projects.

Most supermarkets are selling these battery operated chains of coloured LED lights for a couple of quid. They run off 3 AA batteries (4.5v) and are just static lights.





If you look closely there's actually 3 wires – this is likely because the different colour LEDs have different voltage drops. When I get to dismantling them later we'll know which are on which wire, but my guess is that red and orange are on one line, green and blue on the other. Turns out I was right.

My idea is very simple, wire an transistor onto each line so that they can be controlled independently, then connect a stereo jack to the base, with each channel (left/right) connecting to alternating transistors, so each audio channel will control one strand of lights. The principle is similar to the design I used on the space invaders alarm clock project, but instead of the alternating current being responsible for changing the colour, it'll be the audio channel.


The circuit diagram. The only components I need to add were the transistors, the stereo socket, and a USB cable for power (the resistors were already part of the assembled lights.)


The finished circuit, with the ever-useful TicTacs box enclosure.


The flickering of the lights works, but the frequency is very rapid, which seems to stop the LEDs reaching full brightness. Potentially this could be alleviated by adding capacitors to smooth out the switching, but as the effect varies quite drastically depending on audio source, it's not really an issue. The next challenge is finding a playlist that uses the lights to best effect!




Sunday 13 December 2015

Car Smoke Machine Pt 3

This is the final part of an on-going series of posts about a project to build and install a smoke machine in my car... for science or something...

If you missed the first two parts, they can be found here

So far we've got an e-Cigarette and an air pump wired together to produce a cloud of smoke. Now what we need is to find a way to control it and install it covertly in my car.

I don't want the trap to spring too early, I need to give them time to get comfortable in the car and get started, for it to be believable.

Also, the motor driver chip will need some logic control, so it makes sense to use a microcontroller to provide the logic and the timings.

As I mentioned in the previous post, left to it's own devices, the eCig's coil gets rather hot, so in order to counter that I wanted the microcontroller to only switch it on in 5 second bursts, then wait 5 seconds for it to cool down.

I used an ATTiny26, for no technical reason other than I have a lot of them spare.


Microcontroller code

 1 #define F_CPU 1000000UL
 2 
 3 #include <avr/io.h>
 4 #include <util/delay.h>
 5 
 6 #define CONTROL_PORT           PORTA
 7 #define output_low(port,pin)   port &= ~(1<<pin)
 8 #define output_high(port,pin)  port |= (1<<pin)
 9 #define delay(a)               _delay_ms(a)
10 #define smokeEnable            PA2
11 #define setInput(ddr,pin)      ddr &= ~(1 << pin)
12 #define isInputHigh(pinr,pin)  pinr & (1<<pin)
13 
14 int isRunning = 0;
15 int secCount = 0;
16 
17 int main(void) {
18     setup();
19     while (1) { loop(); }
20 }
21 
22 void setup() {
23     DDRA = 0xFF;  // all outputs
24     setInput(DDRB, PB6);
25 }
26 
27 void loop() {
28         if (isInputHigh(PINB, PA6)) {
29                 if (!isRunning) {
30                         delay(10000);
31                         output_high(CONTROL_PORT, smokeEnable);
32                         isRunning = 1;
33                 } else {
34                         secCount++;
35                         if (secCount > 5) {
36                                 output_low(CONTROL_PORT, smokeEnable);
37                                 delay(5000);
38                                 secCount = 0;
39                                 output_high(CONTROL_PORT, smokeEnable);
40                         }
41                 }
42         } else {
43                 output_low(CONTROL_PORT, smokeEnable);
44                 isRunning = 0;
45         }
46         delay(1000);
47 }
48 


The finished circuit
Click to enlarge
The Videos
I was hoping to use this to prank as many people as possible, and get some good video footage, but unfortunately only 2 of the videos were really usable. The first, is Craigs "We're all gonna die lads!" reaction, and the second, is Bethany's obliviousness to the cloud of smoke forming around her. Enjoy.