Skip to content

Instantly share code, notes, and snippets.

@meub
Last active December 25, 2020 21:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save meub/c3833921a3a45a3ec392d9962313b68e to your computer and use it in GitHub Desktop.
Save meub/c3833921a3a45a3ec392d9962313b68e to your computer and use it in GitHub Desktop.
Raspberry Pi Bell Ringer
#!/usr/bin/env python
import time
import RPi.GPIO as GPIO # Importing the GPIO library
from time import sleep # Import sleep module from time library
# Set up GPIO
servo_pin = 21 # GPIO Pin where servo is connected
GPIO.setmode(GPIO.BCM)
# Define the Pin numbering type and define Servo Pin as output pin
GPIO.setup(servo_pin, GPIO.OUT)
p = GPIO.PWM(servo_pin, 50) # PWM channel at 50 Hz frequency
p.start(0) # Zero duty cycle initially
# Hammer time!
sleep(0.4)
p.ChangeDutyCycle(6)
sleep(0.4)
p.ChangeDutyCycle(12)
sleep(0.25)
p.ChangeDutyCycle(6)
sleep(0.4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment