What is an LED?

An LED (light-emitting diode) is a type of diode; a component which allows electricity to flow in one direction only and blocks it in the other. LEDs emit light when the current passes through. LEDs are cheap, they don´t consume much power and they can produce a considerable amount of light. They are frequently used in electronic systems and are replacing traditional lighting. LED

Switching an LED on and off

In the previous post , we learnt that our components can be actuators or sensors, as well as a analogue or digital. As LED are components that emit light in order to act on the environment, this means that they are actuators. They also only have two states: on or off, which means that they are digital.

As an LED is a digital actuator, we will need to connect it to one of the digital pins on our board. In this example, we will connect it to digital pin 13.

Now we will make the program. Go to the Software tab and click on Components. You will see the block to Switch on/off the LED led_name. Drag it into the loop block.

Now all you need to do is Check the program. Once it has been checked for errors, click on Load. The program will be uploaded to the board and, thanks to the magic of programming, your LED will light up. Now have a go at switching it off!

recuerda REMEMBER: It is the board and not the computer that stores and runs each program that we make. Every time you modify your program, you will need to upload it to your board again for the changes to be applied. Simply click on Load to do this.

Hello world! Making an LED flash on and off

In programming, the first program we make when learning a programming language is called “Hello world”. When a controller board is programmed, the “Hello world” program would be to make an LED light up and then check that everything is working as it should.

The first thing to do is to switch it the LED, as our board thinks very fast. If we tell it to switch off the LED after we have told it to turn it on, it will move from one command to the next so fast that it the LED will appear to be constantly switched on. (Try it and see for yourself). To fix it, we need to set a pause using the “Wait” block under the Control tab. This block will make the program wait for a certain number of milliseconds, which is determined by you. As we want the LED to blink every second, we have set waiting time at 1000 milliseconds. After the first pause, we can switch off the LED and, as the program is repeated indefinitely, we need to pause for one more second before starting again. Here´s the result:


And there´s more

    Here´s a few more ideas so you can keep on practising:

  • Use two LEDs or more and make them blink simultaneously.
  • Make two or more LEDs blink alternately.
  • Make your own fairy lights by programming a sequence of lights using LEDs and wait blocks.

So now that you know how to light up an LED, you will surely have hundreds of ideas on how to use them. The number of LEDs that you can use is determined by the number of digital pins you have available. Remember that you can use components from the ZUM kit or any others. Now don´t be shy, connect all the LEDs you´ve got!