Blinking LED

Project

Making an LED blink on and off.

Description

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.

Code

To open scratch click on -> menu -> programming -> scratch.

Now click on the control_menu menu. Click and drag a green_flag_clicked block to the code area.

Next click and drag a config_18_out into the coding area and attach it to the green_flag_clicked 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 code_block10

We now nee to drag another config_18_out block and attach it below the previous config_18_out. 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 code_block11

Next we need to click and drag a forever_block and place it at the bottom of the code block. Your code should now look like this code_block12 all the code that goes in between the forever_block block will be repeated forever.

Now we need to add another gpio_server_on 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 code_block13

Next we need to click and drag a wait_block and place it within the forever_block block below the config_18_out your code should now look like this code_block14

Now we need to drag another config_18_out and put it in between the forever_blockbelow the wait_block 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 code_block15

Next we need to add another wait_block and attach it within the forever_block and below the gpio_server_on click within the white block and change the 1 to 2. Your code should now look like this code_block16

Running The Code

Now you have written the code click on the green_flag 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 red_dot above Felix.

That’s all for now.

Keep the Pi out of the cupboard and keep coding!