Today, we’re going to build the cheapest Raspberry Pi project possible.
It just involves 1 LED, but for many (including myself), it can be very fascinating to make the LED blink. This project is ideal as a first project, as it is very easy to plan and do. Everything you need is an LED. If your LED can’t handle 3.3 Volts, you’ll also need a resistor, but they are as cheap as 10ct. I think, even pupils in elementary schools will be able to successfully execute this project.
Ok, before we begin, let’s have a preview of what we want to do:
Use the GPIO to make your LED glow.
After a short look on the GPIO pinout, we can clearly see: Pin P1-04 = +5V, P1-06 = 0V (GND)
Fortunately, I have a spare LED here that can handle (almost) 5V. So I can connect this LED directly to the dedicated current source and ground, what makes the LED glow:
die erste LED mit dem Pi ans laufen gebracht! (ok, ein bisschen gecheated) :D twitter.com/TacticalCode/s…
— Tactical Code (@TacticalCode) Dezember 11, 2012
Important: Chose the correct resistor for your LED! R=U/I – If you have a 3V LED and want to connect it to 5V, you need to drain 2V. Let’s say your LED consumes 30mA, so you will need a 2V/0.03A = 66Ohm resistor. Basically, just do this if you already know what you are doing.
The first project
Our needed material: 1 LED, 2 Wires (at best with connectors to hook them up the the GPIO), some solder and a resistor.
Needed tools: Soldering iron, cable stripper
Other useful things: Raspberry Pi, Power supply (for the Pi), a monitor or network connection for SSH, an SD-Card with raspbian on it
Let’s go, here are our 5 simple steps:
Step 1: Start the Raspberry Pi, log in
Step 2: Solder resistor to the LED (doesn’t matter to which pin), then solder the resistor and the other LED pin to the GPIO-Cable.
Step 3: Connect the GPIO-Cable (with LED soldered to it) to the GPIO. Watch out for correct polarity (the longer pin on the LED is the (+)-Pin (Anode), the shorter one is the Cathode (-). I hooked them up to P1-9 (GND, Cathode) and P1-11 (3.3V, Anode)
Step 4: Save the following as a bash script:
root@raspberrypi:/home/pi# nano /tmp/blink.sh #!/bin/sh while true; do echo "1" > /sys/class/gpio/gpio17/value sleep 0.5; echo "0" > /sys/class/gpio/gpio17/value sleep 0.5; done #Press these keys to Save and Exit the editor [STRG+O][ENTER][STRG+X]
Step 5: Activate GPIO17, set it as an output and start the just saved bash-script:
pi@raspberrypi ~ $ sudo su root@raspberrypi:/home/pi# echo "17" > /sys/class/gpio/export root@raspberrypi:/home/pi# echo "out" > /sys/class/gpio/gpio17/direction root@raspberrypi:/home/pi# sh /tmp/blink.sh
Note: These commands have to be run as root. To get root privileges, once run sudo su – you’ll notice the username in the shell changes from pi (or whatever you were logged into) to root.
As previously said, you have to calculate and use the right resistor value for your LED, otherwise you will permanently destroy it. Use the formula R = U/I, where R is the resistance in Ohms (you want to calculate this), U is the Voltage that has to be drained and I is the part’s reverse current.
If your LED has a forward voltage of 2V and a reverse current of 20mA (look that up in a datasheet or the LED’s package), and you want this LED to operate in a 3.3V circuit (as the RasPi’s is), you need to drain 3.3V – 2V = 1.3V.
1.3V / 0.02A = 65 Ohms, in this case you could take the next higher value available for resistors, 68 Ohms. To be secure and not damage any parts in your circuit, including your Raspberry Pi, you should always take the next higher value available.
You can vary the blinking preiods through the both sleep commands in the bash-script. Insert a lower value to speed the blinking up. The first sleep controls how long the LED is on, the second one controls how long it will be off.
Personally, It just took me about 15 minutes to complete the project, including research, soldering and so on. You can also use a breadbord to do everything solderless, which would usually be better if You teach that to elementary school pupils.
(To teachers out there: For 5th grade up, please solder! I wish I had the chance to solder in school, this would have been my favourite class.)
As I said, this project is perfect to start with. It is done very quick, you get to work with hardware elements as well as software. It’s easy, cheap and you instantly see visual results.
The Raspberry Pi as an educational instrument
This project was great fun for me, a 19-year-old 13th grader, so I believe it has an even greater effect on younger pupils. I never had the chance to attend a very useful and interesting IT class, I just learned what a mouse is and how you feed some numbers to excel. But I think, if this class was more interesting and had better educational purpose, more students would like to learn handling computers, hardware and software. It’s a matter of time when everybody needs a basic understanding of how computers are programmed in this technologically fast growing world. Computers are everywhere, so everyone should understand them. With the Raspberry Pi, we have the ideal tool for this. Just $35 in cost can replace an entire $300 computer. You will still need a display to output data and a mouse + keyboard to input data as well as a power supply. But today, these things are cheap to get.
We shouldn’t lose this opportunity.