I noticed the sensors in the head and tail lights, they looked like IR receivers. At first I thought the LED in the body of the car was an IR LED and that the IR receivers detected the IR light bouncing off objects in the cars path (not that the tail lights would make much sense in this context), but when I got it home and put batteries in it, the LED turned out to be just a colour changing LED put there for decoration.
A while back I headed over to Noisebride on a Monday night to check out their circuit hacking/soldering workshop (hosted by Mich Altman). During the workshop I put together one of Mitch's kits - "The Trippy RGB Waves" kit (here's my Noisebridge post if you're interested in reading about the experience). The point is that this gizmo uses an IR LED and an IR receiver to detect overhead objects. The LED pulses IR light at 38KHz (not to be confused with the actual frequency of IR light which is ~ 3THz or 3 x 1012 Hz) which the IR receiver detects if there's an object above the LED reflecting the pulses back down.
I wondered if the car has a similar set-up and was just missing the remote control (which would have a pulsing IR LED). First off I tried a regular remote control, which had no effect so then I tried pointing the Trippy RGB LED kit at the car and voila! It reacted to the light. So, I set about creating a wand/gun for the kids to use to interact with the car.
First off I tried setting up a 555 timer to pulse an IR LED at 38KHz. It worked but the signal was weak (maybe I got the values off a little). I decided to use a microcontroller instead. The ATtiny range are pretty cheap - I bought some ATtiny45s for $1.20 each which is ~3x the cost of a 555. The hardest part was finding/creating a housing for the circuit. I looked around and decided to make my own out of PVC piping. They look like tiny guns and work a treat :)
Methods:
Here are the final "guns".
Ingredients:
The pipe is 1/2" PVC piping from Lowes (Home Depot have it too).
- PVC elbow joint
- PVC pipe (cut to a v.small length 1 1/2")
- PVC pipe cap
- Coin battery holder (3v, 20mm)
- 8-pin DIP socket
- momentary push button
- IR LED
- ATtiny45 (originally made with an ATtiny13).
The plastic dome is the case from a 25c toy from our local taqueria. The base fits snuggly on the end of the elbow joint and I've used it to cover the battery holder in the final 'product'. The piping paraphernalia was all left over from the marshmallow-gun fun.
The wiring is all very straightforward. The hardest part was adjusting the elbow joint so that my coin cell holders fitted snuggly inside (and getting the pushbutton in place).
So, first off is to drill some holes: 1 in the end cap for the LED and one in the elbow joint for the pushbutton. Then I used a rotary tool (Proxxon) to carve out some of the innards of the elbow joint until the battery holder fitted snuggly inside.
Then I soldered one short and one long lead to the pushbutton and fitted it into the elbow joint (see below).
Then I soldered a long ground lead to the battery holder and connected the short positive wire from the pushbutton and placed the battery holder in the end of the elbow joint.
Solder on the DIP socket. Using a socket was a great choice for me because it turns out that the code I was running was not getting the best results from the car. Having the socket let me replace the uC after I'd worked out the kinks. I guess it'll also let me easily recover the uC when the kids are bored of this toy. I stripped a little bit of insulation from near to the end of the ground lead and soldered it to the ground pin (rather than adding a couple of wire ends at that point).
Then it's just a matter of connecting the LED, placing the uC in the socket and fitting the remaining piping.
I made two so both girls could play. Although that also opens up a huge opportunity to fight over who's in control as well...
And here's the code (for some reason the car reacted best if the IR was pulsed for ~170 microseconds with a 400 microsecond pause before the next set of pulses):
I made two so both girls could play. Although that also opens up a huge opportunity to fight over who's in control as well...
And here's the code (for some reason the car reacted best if the IR was pulsed for ~170 microseconds with a 400 microsecond pause before the next set of pulses):
/*
* IrLedPulse.c
*
* Distributed under Creative Commons 3.0 -- Attib & Share Alike
*
* Created on: Dec 26, 2009
* Author: Paul
*/
#include <avr/io.h>
#include <avr/delay.h>
#ifndef F_CPU
#define F_CPU 1000000UL
#endif
// Use Timer 0 to pulse the IR LED at 38KHz
void pulseIr()
{
TCCR0A = 0 | (1 << COM0A0) | (1 << WGM01); // COM0A0=1 to toggle OC0A on Compare Match
TCCR0B = 0 | (1 << CS01); // 1/8 prescale
OCR0A = 104; // to output 38KHz on OC0A (PB0, pin 5)
_delay_us(170); // delay 170 microseconds
// turn off Timer0 to stop 38KHz pulsing of IR
TCCR0B = 0; // Stop Timer0 (turn off IR emitter)
TCCR0A = 0; // Disconnect OC0A from PB0 (pin 5)
}
int main(void)
{
DDRB |= (1 << PB0); // set PB0 to output
PORTB = 0xFF; // all PORTB output pins high (LED off).
while(1)
{
pulseIr();
_delay_us(400);
}
}
1 comment:
As a former teacher please, please volunteer to help with your kids school science program. Schools can use someone who can think out of the box to come up with ways to help kids understand science in more hands on minds on ways. As I read through your blog, my first thought was if you had been a parent at my school, I would have had you in my classroom as often as possible. :)
Post a Comment