My Account

Wish List (0)

Ryanteck Traffic HAT - Blinking LED

Written by in RyanTeck, RyanTeck Traffic HAT on .

Blinking an LED in python has become really easy due to the new GPIO Zero library. There's a few different ways.

Lets begin by just turning the amber LED on. Open up your favourite python editor and type in the following to turn it on.

from gpiozero import LED
amber = LED(23)

And then try "" to turn it off.

We can make the LED now blink by adding the following code at the top

from time import sleep

And as the body

while True:

This will then turn the LED off and on with a 1 second interval.

Congratulations you're now blinking a LED!

  • But wait, there's more!*

Instead a fancy feature of GPIO Zero is auto blinking which can be done using the following command.


This will make the LED blink forever with a 1 second interval and pause the program.

We can change the False to True (or remove the ",False") section to make it so the rest of the program would continue.

You can change "None" to be a number which is how many times it would blink, Replacing "None" with 10 would make it blink just 10 times.

Finally you can change the two beginning numbers to set the intervals, using "1,2" would make the LED turn on for one second and then off for 2.

Last update: Nov 01, 2017

Related Article

Related Products


Leave a Comment

Leave a Reply

The product is currently Out-of-Stock. Enter your email address below and we will notify you as soon as the product is available.