Making an LED blink on and off.
In this tutorial we are going to turn an LED on and off in a blinking motion.
Equipment You Will Need
As well as all the usual equipment you need for the raspberry pi, you will need:
- An LED
- A 330 ohm resistor
- An electronic breadboard
- 2 x Male to Female jumper wires
Making The Circuit
To create the circuit place the LED into the breadboard as with the diagram above. NOTE: the LED has a long leg called the anode (positive) and a shorter leg called the cathode (negative/ground).
Next we want to connect the resistor to the longer leg of the LED. To do this we place the resistor in the breadboard in the same column as the longer leg of the LED.
Now we need to connect the breadboard to the pi. To do this we take a jumper wire and place the pointed end into the breadboard within the same column as the shorter leg of the LED and the other end if the jumper wire onto pin 18 of the raspberry pi. Which is located 6 pins down on the left. (refer to the diagram for help)
Take the other jumper wire and put the end with the point into the breadboard in the same column as the resistor. Connect the other end of the wire to the 3rd pin down on the left. (refer to the diagram for help)
We are now ready to do some coding.
To open scratch click on -> menu -> programming -> scratch.
Now click on the menu. Click and drag a block to the code area.
Next click and drag a into the coding area and attach it to the now click on the little black arrow at the edge of the broadcast block then click on new/edit and type gpioserveron (no spaces). This tells scratch to communicate with the GPIO pins. Your code should look like this
We now nee to drag another block and attach it below the previous . Again we need to edit the text this time click on edit/new and type config18out (no spaces) this configure pin 18 as an output. Your code should now look like this
Next we need to click and drag a and place it at the bottom of the code block. Your code should now look like this all the code that goes in between the block will be repeated forever.
Now we need to add another we again need to edit the text on this so click on edit/new and type gpio18on (no spaces) this will turn the LED on. Your code should look like this
Next we need to click and drag a and place it within the block below the your code should now look like this
Now we need to drag another and put it in between the below the we need to edit the text of this block to gpio18off (no spaces) This turns the LED off. Your code should now look like this
Next we need to add another and attach it within the and below the click within the white block and change the 1 to 2. Your code should now look like this
Running The Code
Now you have written the code click on the above Felix to run the code.
You should now see the LED turn off and off.
Within the code we have created a loop so the code will not stop unless you click on the above Felix.