Annie Kelly
This tutorial will show you how to build a switch that can be activated by pushing down on it with your hands, feet, pets' paws, etc.
Step 1: Preparing your supplies
This tutorial will be using a tiny programmable computer called the micro:bit and basic craft and electronics materials.
1. Computer (laptop or desktop)
You will need to use a computer with internet access and a USB port to program the micro:bit.
2. micro:bit and a microUSB cable
You will need a micro:bit (~$12) and USB cable to complete this tutorial. Many retailers sell starter kits such as this one.
3. Alligator clips
In this tutorial I simply use alligator clips to connect the servo to the micro:bit, but for a more finished project you may want to consider soldering the connections so that they are more secure.
4. Cardboard and scissors
In this tutorial we are building the switch out of cardboard.
5. Aluminum foil
This will be the main material necessary for detecting pressure on the switch.
6. Tape
Any tape is fine. Glue is also an acceptable substitute.
Step 2: Assemble the switch
We will be using 3 pieces of cardboard to create the pressure switch. The two larger pieces will go on the outsides, and the smaller piece will go in the center. This is so that when we push down on the switch the outsides of the two larger pieces will make contact. In this example the two larger pieces are 4 in x 5 in, and the smaller piece is 3.5 in x 3.5 in. Feel free to adjust these sizes to your liking.
Next we want to cover both of the larger pieces in aluminum foil (leave the smaller center piece alone, it will not work if you cover it in foil). We want the inner-facing sides of the pieces to be completely covered in foil. To do this, cut a piece of foil larger than the piece of cardboard and then tape the pieces over the back edge.
This is what the backs of the larger pieces should look like.
And this is what the other side of the large pieces look like. Now we are ready to put all the pieces together.
Tape the smaller piece onto the inside of one of the larger pieces. Then tape the large piece on top. The above right photo is what the switch looks like from the side once it is all together.
Step 3: Connect the switch to your micro:bit
We want the switch to be activated when the two pieces of aluminum foil touch. In order to do this, we need to connect one of the sides to the power source (pin 3V on the micro:bit), and the other side to one of the input pins (pin 0 on the micro:bit). This way, when the two pieces of foil are not touching the value of the pin will be 0, and when the two pieces of foil are touching the value of the pin will be 1.
Step 4: Programming your micro:bit
If you are not familiar with programming or using the micro:bit, we recommend visiting the official Getting Started page.
Otherwise, let's start writing some code. This will be a simple program that will show the state of our switch on the LED screen. It will show us a 0 when the switch is not pushed down, and will show us a 1 when the switch is pushed down and activated.
Grab a forever block from the Basic category in the micro:bit programming editor and put a show number block inside of it. Click on the Advanced category dropdown and then click on the Pins category. Place the digital read pin P0 block inside of the show number block.
Download the code and load it onto the micro:bit.
Step 5: Test and play!
Once you have uploaded the code from Step 4 onto the micro:bit and completed the wiring in Step 3, you can now test to see if your pad works.
References:Comments are closed.
|