Turning an LED on.
In this tutorial we are going to make an LED turn on using scratch.
Equipment You Will Need
- 1 x red LED
- 2 x male to female jumper wires
- 1 x breadboard
- 1 x 330 ohm resistor
If you aren’t sure what any of these components are, or just want to learn a bit more about them go to (insert link here)
Making The Circuit
It is through the GPIO (General Purpose Input Output) pins that the raspberry pi can control and even monitor the outside world by being connected
into an electronic circuit. The raspberry pi can control LED’s, motors, button presses, and even buzzers.
We are now ready to create our circuit.
- Put the LED into the breadboard with the longer leg (the anode) on the right hand side.
- Put the resistor into the breadboard in the same column as the short leg (cathode) of the LED leaving room for a jumper wire.
- Take one of the jumper wires and connect the end with the pin into the same column as the resistor and the short leg of the LED and connect the
other end of the jumper wire to the ground (gnd) pin on the raspberry pi. The ground pin is the 3rd pin down on the right hand side with the USB
ports facing you.
- Take the second jumper wire and connect the end with the pin into the same column as the longer leg of the LED and the other side to pin 18 on the raspberry pi which is located at the 6th pin down on the right hand side.
Now that we have created the circuit, we can turn the raspberry pi on and get coding.
The first thing we need to do is load scratch. To do this go to menu -> programming -> scratch. Once scratch has loaded click on the Menu. Find the block and drag it to the coding area.
Next from the We need a block. Drag this to the coding area and attach it underneath the block. We need to add some text into the block to do this click on the little black arrow and click on edit/new, in the text box that appears type gpioserveron (no spaces), now click on OK or press enter. This tells scratch to talk to the GPIO pins.
We now need to drag another block to the coding area and attach it under the other block. We now need to click on the black arrow and select edit/new. In the text box type config18out (no spaces), now click on OK or press enter. This is configuring pin 18 as an output.
We now need to drag another block to the coding area and attach it underneath the other block. Again we need to edit the text. This time type gpio18on (no spaces), this tells scratch to turn the LED on. Once you have done all of this your code should look like this
Running The Code
Now that we have finished the code to run it click . You should now see the LED turn on, if you don’t go back and see where you went wrong.