User Tools

Site Tools


user:bmurphy7:hpc0:doorbell

Doorbell

The Circuit:

The Code:

  1 #!/usr/bin/env python3                         
  2 ########################################################################
  3 # Filename    : Doorbell.py                    
  4 # Description : Make doorbell with buzzer and button    
  5 # auther      : www.freenove.com               
  6 # modification: 2019/12/28                     
  7 ########################################################################
  8 import RPi.GPIO as GPIO                        
  9                                                
 10 buzzerPin = 11    # define buzzerPin           
 11 buttonPin = 12    # define buttonPin           
 12                                                
 13 #initization function                          
 14 def setup():                                   
 15     GPIO.setmode(GPIO.BOARD)                                    # use PHYSICAL GPIO Numbering
 16     GPIO.setup(buzzerPin, GPIO.OUT)                             # set buzzerPin to OUTPUT mode
 17     GPIO.setup(buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)    # set buttonPin to PULL UP INPUT mode
 18                                                
 19 #loop function that will activate the buzzer   
 20 def loop():                                    
 21     while True:                                
 22         if GPIO.input(buttonPin)==GPIO.LOW:  # if button is pressed
 23             GPIO.output(buzzerPin,GPIO.HIGH) # turn on buzzer
 24             print ('buzzer turned on >>>')     
 25         #if button is released                 
 26         else :                                 
 27             GPIO.output(buzzerPin,GPIO.LOW)  # turn off buzzer
 28             print ('buzzer turned off <<<')    
 29                                                
 30 #function to shutdown the board                
 31 def destroy():                                 
 32     GPIO.cleanup()                           # Release all GPIO
 33                                                
 34 if __name__ == '__main__':                     
 35     print ('Program is starting...')           
 36     setup()                                    
 37     try:                                       
 38         loop()                                 
 39     except KeyboardInterrupt:                # When we are all done.                                        
 40         destroy()

In project involved using a button that when pressed would activate a buzzer which makes a noise when activated. This project ended up using a button, an active buzzer, 2 10 ohm resistors, a 1 ohm resistor, and a few jumpers. As for the porject code I made the comments align and described what each function did.

user/bmurphy7/hpc0/doorbell.txt · Last modified: 2020/05/10 15:12 by 127.0.0.1