Home Interests Raspberry Pi

How to Use a Relay with a Raspberry Pi

Add an electrically-operated switch to your Pi!
howchoo   (467)
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 • 92 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

How to Run a Minecraft Server on the Raspberry Pi

A whole world trapped inside your Pi.
howchoo   (467)
December 7, 2023

There are several ways to go about running a Minecraft server on the Raspberry Pi. In this guide, I’ll cover how to install Nukkit—a cross-platform Minecraft server that’s super easy to set up on the Raspberry Pi. This server should work with PCs, consoles, and tablets running Minecraft 1.14. I’ll be using a Raspberry Pi

Continue Reading

howchoo

 467 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