Task
Copy the code in your Arduino. Then answer the quiz at the bottom of the page.
You’ve learned how to turn different things on and off with varying methods - magnets, touching, and tilting. Things you’ve turned on so far have been parts of your Maker Kit, such as LEDs and motors. But what if you wanted to turn on some external device, such as an electronic toy? In this project, we’ll do just that!
Electronic devices usually have their own power supply, e.g., a battery. That’s why we’ll sort of divide the circuit in two. Arduino will use its power supply, and the toy its own. You’ll need a transistor for that.
For this exercise, you’ll need an electronic toy. The toy has to work, and you must be able to take it apart so that you can get your hands on the two wires (ground and voltage wires) coming from its power supply. Below is a video of the Mehackit Dino, which is turned on with the help of a microphone by clapping your hands! What kind of mechanism would you like to use to turn your toy on?
In addition to Arduino, the USB cable, breadboard, and wires, you’ll need:
Part | Image | Description |
---|---|---|
NPN transistor | You have three of these in your Maker Kit. Make sure that the component has MP5 written on it, not TMP (like in the temperature sensor) or FT66T (like in the melody generator). | |
Diode | In this exercise, the diode is used to make sure that possible surges don't move from the toy's power supply to Arduino. The diode allows current to flow toward the striped end, but not the other way | |
An electronic toy to hack | The toy must work and be relatively easy to take apart so that you can find the two wires going into the power supply. | |
Wire cutters | For cutting and peeling the toy's wires. | |
Soldering iron | This is not essential, but it will make your job easier! Ask your instructor if they could arrange you one for some of the classes. | |
Screwdriver | For taking the toy apart. You can find a small Phillips screwdriver with a black handle in your Maker Kit. If there are other screws in the toy, ask your instructor for help! | |
Resistor 1 kΩ | The resistor resists the flow of electric current. The value of the resistor is measured in ohms (Ω) and announced in the component in stripes of different colors (in this case brown, black, red and gold) | |
Reed switch | Closes the circuit when a magnet is brought close to it | |
Resistor 330 Ω | ||
LED | The longer leg (the one with the bend in the picture), i.e., anode to the + -terminal, i.e., to Arduino's pin. The shorter leg, i.e., cathode to minus-terminal, i.e., ground. | |
The first aim is to turn on the LED with a transistor. Later, we’ll replace the LED with an electronic toy, which you can turn on with the same logic.
Note, that the LED isn’t connected to Arduino’s digital pin, so you can’t directly use it through Arduino! This time, you’ll control the LED through the transistor.
When the switch is closed, the middle leg of the transistor receives voltage from pin 6. Now, the transistor connects the other two legs and the LED’s (and later the toy’s) circuit closes. When the switch is not closed, the transistor receives no voltage, the LED’s circuit disconnects and the LED isn’t on.
Necessary Commands
The aim is to first try if you can use the LED through the transistor. Later, we’ll replace the LED with the electronic toy!
void setup() {
pinMode(6, OUTPUT);
}
void loop() {
digitalWrite(6, HIGH);
delay(4000);
digitalWrite(6, LOW);
delay(4000);
}
With the instructions above, you turned the LED on and off by using Arduino. Next, you’ll turn on the toy instead of the LED. The legs of the LED are simply replaced by the two wires of the toy!
Just like before, applying voltage to the middle leg of the transistor connects the other two legs. Connect the two ends of the grounding wire you cut to the left and right leg of the transistor.
void setup() {
//Set the state of the reed switch to INPUT_PULLUP
//Set the pin of the transistor to OUTPUT
}
void loop() {
//If the reed switch closes, apply voltage to the transistor and start the toy
}
When you’re able to start the toy with the transistor, you can develop your project further in many ways. Here are two options!
Testing different switches and building chain reactions
Previously, you turned on the toy with a magnet using a reed switch. How else could you start the toy? Could a magnet tied to a string swing next to the reed switch, which starts the toy, which topples a glass of water, which closes the next switch and starts something else… Use your imagination!
Circuit bending
Circuit bending means modifying the toy’s circuit. So far the only alteration you’ve made was cutting one wire. You could, for example, modify the toy’s sounds by adding a variable resistor in a convenient place in the circuit. Below is a video introducing you to the world of circuit bending!