Home Interests Raspberry Pi

How to Use a Relay with a Raspberry Pi

Add an electrically-operated switch to your Pi!
howchoo   (434)
September 18, 2023
3 minutes

Share

You'll Need 2

What you'll need
Interests
Howchoo is reader-supported. As an Amazon Associate, we may earn a small affiliate commission at no cost to you when you buy through our links.
Posted in these interests:
electronics • 3 guides
pi • 91 guides

A relay is an electrically-operated switch. These switches can be extremely useful for a variety of Raspberry Pi projects (think turning on a light or opening your garage door. Watch the video below to learn how to drive a relay using your Raspberry Pi.

1 – The video

The following video will show you how to wire up the relay to your Raspberry Pi.

2 – The test script

Here’s a copy of the test script used in the video:

#!/usr/bin/env python

import time

import RPi.GPIO as GPIO


GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
GPIO.output(17, GPIO.LOW)

time.sleep(0.25)

GPIO.output(17, GPIO.HIGH)
GPIO.cleanup()

To run the script, simply copy the code above to a file on your Raspberry Pi called test-relay.py (or whatever you want). And then run the script using:

python test-relay.py
NEXT UP

HeaterMeter: Control your Grill Using a Raspberry Pi!

Fire up the summer with a new Pi project.
howchoo   (434)
November 28, 2023

With summer right around the corner, it’s time to fire up the grill! But who will watch the grill while you’re beating the heat? This year, kick things up a notch with your own Raspberry Pi-powered HeaterMeter. Don’t just throw a BBQ, be a part of it. HeaterMeter lets you keep a close eye on

Continue Reading

howchoo

 434 guides

Introducing Howchoo, an enigmatic author whose unique pen name reflects their boundless curiosity and limitless creativity. Mysterious and multifaceted, Howchoo has emerged as a captivating storyteller, leaving readers mesmerized by the uncharted realms they craft with their words. With an insatiable appetite for knowledge and a love for exploration, Howchoo's writing transcends conventional genres, blurring the lines between fantasy, science fiction, and the surreal. Their narratives are a kaleidoscope of ideas, weaving together intricate plots, unforgettable characters, and thought-provoking themes that challenge the boundaries of imagination.

Discover interesting things!

Explore Howchoo's most popular interests.

Explore