The other day, well actually quite a lot of days ago, Thomas, one of my twin boys, asked about making an electronic car. It seems that they might be making an electronic car at school soon, and he wanted to get a head start … awww, bless him, he’s only 8 🙂
So I thought I’d better get prepared.
Now, we didn’t really have much in the electronics box that we could use, apart from an L293D. This is a DC motor driver, a simple IC that can control DC motors via an H-Bridge circuit. Now, if we’re going to be connecting up some 5v hobby motors to a microcontroller chip such as an ATTiny45, we need to protect the chip from i) drawing too much current, and ii) problems associated with switching inductive loads such as motors.
An H-Bridge is simply a set of four switches with protective flyback diodes, and the L293D provides a very convenient way to control two motors via a microcontroller chip. Yay!
However, it turns out I didn’t have much else …
… apart from a USB missile launcher which hadn’t worked in years … hmmm. Taking the USB missile launcher apart gave us some wonderful pieces to play with. Not only did it have two low voltage DC motors, but some very useful microswitches which will come in handy later (I’m thinking of bump/collision detection here!)
So, two motors, three microswitches, ATTiny45, L293D … what else do we need?
Of course. Good job Thomas had a Konnects building set which just so happened to have some wheels included, and he was happy to donate them to the project. It was an easy case of gluing the wheels to the DC motors. Also, I have some standard stripboard which we can use for the chassis and to hold all the electronics. This is looking good!
Now we have all our bits and pieces, we just need to get started on building the circuit. The code itself is going to be simply a case of making control pins go HIGH and LOW, though for reading the microswitches I’m going to use another simple technique rather than constantly polling the input pins.
Effectively I’m going to create a resistor ladder with all the microswitches connected into the resitor ladder circuit to act as a voltage divider or potential divider, and then measure the voltage at the input pin relative to the source voltage. By running an ADC conversion at the input pin, we can determine which microswitch has been pressed. More on this in a later post.
So, we have all the pieces ready. All we have to do now is build the circuit, program the ATTiny, and let Thomas take it in to his “show and tell” session at school …
… but first, perhaps, I should wait for Thomas to help me build the electronic robot car, eh? 🙂 That will be the basis of the next post in this series …