Turning an LED on

Project

Turning an LED on.

Description

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.

  1. Put the LED into the breadboard with the longer leg (the anode) on the right hand side.
  2. Put the resistor into the breadboard in the same column as the short leg (cathode) of the LED leaving room for a jumper wire.
  3. 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.
  4. 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.

Code

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 control_menu Menu. Find the block green_flag_clicked and drag it to the coding area.

Next from the control_menu We need a gpio_server_on block. Drag this to the coding area and attach it underneath the green_flag_clicked 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 gpio_server_on block to the coding area and attach it under the other gpio_server_on 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 gpio_server_on block to the coding area and attach it underneath the other gpio_server_on 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 code_block_0

Running The Code

Now that we have finished the code to run it click green_flag. You should now see the LED turn on, if you don’t go back and see where you went wrong.

Thats all for now.

Keep the Pi out of the cupboard and keep coding!