Thumbnail image

CONTROL A RELAY WITH A RASPBERRY PI AND PYTHON

With this project I wanted to control a motor over the internet. The motor needs 12-24V DC with 1500mA. It is started through an impulse with the same potential as the power supply.

I chose a Raspberry Pi model B for this project, as I had one laying around. As OS I used Raspberry Pi OS Lite on a 8GB SD Card. To control the motor I created a simple Flask API.

Hardware

Demo

You can see the relay being control through the flashing red led and by the click sound.

Circuit Diagram

Code

import RPi.GPIO as GPIO
from flask import Flask, redirect, url_for
import time

relayPin = 15 # Define the pin to be controlled

GPIO.setmode(GPIO.BCM) # Choose BCM or BOARD GPIO.setup(relayPin, GPIO.OUT) # Set pin as an output GPIO.output(relayPin, False) # set pin value to 0/GPIO.Low/False

app = Flask(name)

@app.route('/', methods=['GET']) def home(): return "<h1>Hello</h1>"

@app.route('/success/<message>') def success(message): return message

@app.route('/open_door', methods=['POST']) def open_door(): try: GPIO.output(relayPin, True) # set pin value to 1/GPIO.High/True time.sleep(0.2) GPIO.output(relayPin, False) # set pin value to 0/GPIO.Low/False except KeyboardInterrupt: GPIO.output(relayPin, False) # set pin value to 0/GPIO.Low/False GPIO.cleanup() return redirect(url_for('success', message='success'))

if name == 'main': # Make the Raspberry Pi accessible in the same network through ip app.run(host='0.0.0.0')

See here for how to run the api after booting the raspberry pi.

Thumbnail image

BRAG DOCUMENT

What is a brag document?

A brag document is a list of stuff you did at or besides work. It is great for showing what you did to your manager when it comes to raises. Additionally, it helps you to reflect on what you worked on. I find it useful to see how far you have come and what you have accomplished.

How often should I update it?

Update it regularly, like weekly or biweekly so you don’t forget anything.

Sample Structure

Here is a sample structure for your brag document:

Goals

Write about the goals you have for this year. At the end of the year, you could also include goals for the next year.

Projects

On what projects did you work? And how did you contribute?

Design & Documentation

Did you wrote documentation or created a design?

Company building

Did you help to grow the company, e.g. through recruiting or attending trade fairs?

What did you learn?

Have you learned a new skill? Or did you get certified in something?

Outside of work

Show your accomplishments outside of your work. This could be:

  • articles/blog posts
  • talks
  • open source work
  • private projects
  • industry recognition

This article was inspired by Julia Evans article.