Project 11: 16×2 LCD Alarm Clock With Snooze Button

What you will need:

  • Raspberry Pi
  • Breadboard
  • 16 x 2 LCD Screen
  • 10kΩ Potentiometer
  • Active Buzzer
  • Pushbutton Switch
  • 10 Female to Male Jumper Wires
  • 9 Male to Male Jumper Wires

Instructions:

This project is designed to use the Raspberry Pi to simulate a simple alarm clock with a buzzer and a snooze button. Our project utilizes the same 16 x 2 LCD screen from our previous projects while incorporating the active piezo buzzer from Project 10. Additionally, we have inserted a pushbutton switch into our breadboard layout to act as a simple snooze button.

Because this experiment builds upon Project 9 on this website and requires the Adafruit Raspberry Pi Python Code Library, be sure to follow the instructions in our Previous Project outlining the installation procedures before you continue.

After you have populated your breadboard and cloned the Adafruit library mentioned above, use your favorite editor to create the Python script below.

#!/usr/bin/env python
#
#  alarm_clock_LCD.py
#
# A simple alarm clock using Adafruit_CharLCD module
# plus a buzzer and 16x2 LCD display. A button is connected
# to GPIO 27 to simulate a snooze function.
#
#
# LCD Screen 16x2 Pins
# --------------------
# Pin 1  to GND
# Pin 2  to 5v
# Pin 3  to variable resistor then to GND 'Contrast Adjustment'
# Pin 4  to GPIO 25 for 'Command or Data Mode Switching'
# Pin 5  to GND for 'Read/Write Mode'
# Pin 6  to GPIO 24 for 'Enable Pin'
# Pin 7  to Not Connected
# Pin 8  to Not Connected
# Pin 9  to Not Connected
# Pin 10 to Not Connected
# Pin 11 to GPIO 23 for 'Data 4'
# Pin 12 to GPIO 17 for 'Data 5'
# Pin 13 to GPIO 21 for 'Data 6'
# Pin 14 to GPIO 22 for 'Data 7'
# Pin 15 to 5v for 'Backlight Anode' - Could use variable resistor as a 'Brightness Control'
# Pin 16 to GND for 'LED Backlight Cathode'
#
# The positive side of the two pin active buzzer is attached to pin 18
# and the other pin goes to ground
#
#  Copyright 2015  Ken Powers
# 

# Import the required libraries
from Adafruit_CharLCD import Adafruit_CharLCD
import time
import RPi.GPIO as GPIO

# Set some global constants
lcd = Adafruit_CharLCD()
buzzer_pin = 18
snooze_button = 27
alarm_sounding = False
RUNNING = True

# Set buzzer pin as a GPIO output and snooze button
# as an input with an internal pull-down resistor
GPIO.setup(buzzer_pin, GPIO.OUT)
GPIO.setup(snooze_button, GPIO.IN, GPIO.PUD_DOWN)

# Make the function to create a buzzing sound
# This function was originally written by Simon Monk
def buzz(pitch, duration):
	period = 1.0 / pitch
	delay = period / 2
	cycles = int(duration * pitch)
	for i in range(cycles):
		GPIO.output(buzzer_pin, True)
		time.sleep(delay)
		GPIO.output(buzzer_pin, False)
		time.sleep(delay)

# Define a function that returns a correct 24 hour result after
# snooze time has been added
def snooze(alarm):
	# Add 9 minutes to the alarm time for the snooze
	alarm += 9
	# Separate time into hours and minutes
	hours = int(alarm / 100)
	minutes = alarm - hours * 100

	# Make sure new alarm time fits 24 hour format
	if (minutes > 59):
		plushrs = int(minutes//60)
		minutes = minutes % 60
		hours = hours + plushrs
	if (hours > 23):
		hours = hours - 24

	# Reconstruct alarm time and return to main loop
	alarm = hours * 100 + minutes
	return alarm

try:
	# Get alarm time from user
	response = raw_input("Enter the alarm time in 24-Hour format HHMM: ")
	print("Alarm time has been set for %s hrs" % response)
	buzz(500,0.1)

	alarm = int(response)

	# Clear LCD screen
	lcd.clear()

	while RUNNING:
		# Continually get the time as an integer
		# Output time in 24-Hour format to the LCD
		curr_time = int(time.strftime("%H%M"))
		lcd.home()
		lcd.message("  Current Time\n")
		lcd.message(time.strftime("    %H:%M:%S\n"))

		# Trigger the buzzer function when the alarm time is reached
		# The buzzer will have two different tones just for fun
		if curr_time == alarm:
			lcd.clear()
			lcd.home()
			lcd.message("    Wake Up!")
			buzz(10,0.25)
			time.sleep(0.1)
			buzz(20,0.25)
			time.sleep(0.1)
			alarm_sounding = True

		# Check for snooze button press
		input_button = GPIO.input(snooze_button)
		if alarm_sounding == True and input_button == True:
			print('Snooze Pressed!')

			# Call function to add snooze time
			alarm = snooze(alarm)

			print('New Alarm Time Is: %s' % alarm)
			alarm_sounding = False

			# Wait until the button is released to move on
			while input_button == True:
				input_button = GPIO.input(snooze_button)
				# Let the system have a brief break
				time.sleep(0.01)

except KeyboardInterrupt:
	RUNNING = False
	print "\nQuitting"

# Clear LCD screen upon exit
# Don't forget to clean up after so we
# can use the GPIO next time
finally:
	lcd.clear()
	GPIO.cleanup()

Code Analysis:

Our Raspberry Pi Python script begins by telling the interpreter we are using the Python language. We also include some descriptive comments that help to let readers know what the script will accomplish as well as indicating what Raspberry Pi GPIO pins we are using.

#!/usr/bin/env python
#
#  alarm_clock_LCD.py
#
# A simple alarm clock using Adafruit_CharLCD module
# plus a buzzer and 16x2 LCD display. A button is connected
# to GPIO 27 to simulate a snooze function.
#
#
# LCD Screen 16x2 Pins
# --------------------
# Pin 1  to GND
# Pin 2  to 5v
# Pin 3  to variable resistor then to GND 'Contrast Adjustment'
# Pin 4  to GPIO 25 for 'Command or Data Mode Switching'
# Pin 5  to GND for 'Read/Write Mode'
# Pin 6  to GPIO 24 for 'Enable Pin'
# Pin 7  to Not Connected
# Pin 8  to Not Connected
# Pin 9  to Not Connected
# Pin 10 to Not Connected
# Pin 11 to GPIO 23 for 'Data 4'
# Pin 12 to GPIO 17 for 'Data 5'
# Pin 13 to GPIO 21 for 'Data 6'
# Pin 14 to GPIO 22 for 'Data 7'
# Pin 15 to 5v for 'Backlight Anode' - Could use variable resistor as a 'Brightness Control'
# Pin 16 to GND for 'LED Backlight Cathode'
#
# The positive side of the two pin active buzzer is attached to pin 18
# and the other pin goes to ground
#
#  Copyright 2015  Ken Powers
#

Next, we import all the required function libraries, instantiate an LCD using the Adafruit library, and define some necessary constants.

# Import the required libraries
from Adafruit_CharLCD import Adafruit_CharLCD
import time
import RPi.GPIO as GPIO

# Set some global constants
lcd = Adafruit_CharLCD()
buzzer_pin = 18
snooze_button = 27
alarm_sounding = False
RUNNING = True

At this point in our script, we setup our GPIO so our buzzer pin is an OUTPUT and our snooze button is an INPUT that is utilizing an internal pull-down resistor.

# Set buzzer pin as a GPIO output and snooze button
# as an input with an internal pull-down resistor
GPIO.setup(buzzer_pin, GPIO.OUT)
GPIO.setup(snooze_button, GPIO.IN, GPIO.PUD_DOWN)

Our first function definition was written by Simon Monk and is designed to make a sound through our active buzzer.

# Make the function to create a buzzing sound
# This function was originally written by Simon Monk
def buzz(pitch, duration):
	period = 1.0 / pitch
	delay = period / 2
	cycles = int(duration * pitch)
	for i in range(cycles):
		GPIO.output(buzzer_pin, True)
		time.sleep(delay)
		GPIO.output(buzzer_pin, False)
		time.sleep(delay)

Our next function definition is used for our snooze button. If the alarm is sounding and the snooze button is depressed, this function is called.

Every alarm clock I have ever owned has had a snooze time of 9 minutes. I have no idea why 10 minutes isn’t used. This function sticks with that unusual convention and adds 9 minutes to the current alarm time.

Next, the time is broken into hours and minutes so we can ensure that the new alarm time fits standard 24-hour format conventions.

# Define a function that returns a correct 24 hour result after
# snooze time has been added
def snooze(alarm):
	# Add 9 minutes to the alarm time for the snooze
	alarm += 9
	# Separate time into hours and minutes
	hours = int(alarm / 100)
	minutes = alarm - hours * 100

	# Make sure new alarm time fits 24 hour format
	if (minutes > 59):
		plushrs = int(minutes//60)
		minutes = minutes % 60
		hours = hours + plushrs
	if (hours > 23):
		hours = hours - 24

	# Reconstruct alarm time and return to main loop
	alarm = hours * 100 + minutes
	return alarm

The main loop of our script prompts the user for their desired alarm time in 24-hour format. Our LCD screen is continually updated with the current time and the alarm buzzer is sounded if our alarm time is reached. While the alarm is sounding, a press of the snooze button calls our snooze() function and the new alarm time is returned. The entire process continues until Ctrl + C is pressed.

try:
	# Get alarm time from user
	response = raw_input("Enter the alarm time in 24-Hour format HHMM: ")
	print("Alarm time has been set for %s hrs" % response)
	buzz(500,0.1)

	alarm = int(response)

	# Clear LCD screen
	lcd.clear()

	while RUNNING:
		# Continually get the time as an integer
		# Output time in 24-Hour format to the LCD
		curr_time = int(time.strftime("%H%M"))
		lcd.home()
		lcd.message("  Current Time\n")
		lcd.message(time.strftime("    %H:%M:%S\n"))

		# Trigger the buzzer function when the alarm time is reached
		# The buzzer will have two different tones just for fun
		if curr_time == alarm:
			lcd.clear()
			lcd.home()
			lcd.message("    Wake Up!")
			buzz(10,0.25)
			time.sleep(0.1)
			buzz(20,0.25)
			time.sleep(0.1)
			alarm_sounding = True

		# Check for snooze button press
		input_button = GPIO.input(snooze_button)
		if alarm_sounding == True and input_button == True:
			print('Snooze Pressed!')

			# Call function to add snooze time
			alarm = snooze(alarm)

			print('New Alarm Time Is: %s' % alarm)
			alarm_sounding = False

			# Wait until the button is released to move on
			while input_button == True:
				input_button = GPIO.input(snooze_button)
				# Let the system have a brief break
				time.sleep(0.01)

except KeyboardInterrupt:
	RUNNING = False
	print "\nQuitting"

# Clear LCD screen upon exit
# Don't forget to clean up after so we
# can use the GPIO next time
finally:
	lcd.clear()
	GPIO.cleanup()

The addition of a snooze button to our previous project turned out to be a bit of a challenge. Making sure the adjusted alarm time remained in proper 24-hour format required a bit of thought. Enjoy the project and have fun modifying it to suit your own needs. Above all, however, have fun!

Project 7a: Switched LED

What you will need:

  • Raspberry Pi
  • Breadboard
  • 1 Push-button Switch
  • 1 Red LED (or whatever color you have handy)
  • 1 1kΩ Resistors —[III I]—
  • 1 220Ω Resistor —[III I]—
  • 1 .1μF Ceramic Disk Capacitors
  • 6 Female to Male Jumper Wires
  • 4 Male to Male Jumper Wires

Instructions:

In Project 7, we discussed multiple ways to implement a push-button switch with Python and the Raspberry Pi microcomputer. The obvious next step is to accomplish something with that information. What better way to connect what we have learned so far than by using the switch to turn on an LED?

My son and I basically combined Project 2 and Project 7 in order to arrive at this particular experiment. As before, once you connect all your components by following the breadboard layout above, use your favorite editor to enter the Python script below:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  switched_LED.py
#
# A short program to test implementing a switch
# connected to GPIO pin 18 which will turn on an LED
# connected to GPIO 23
#
#  Copyright 2015  Ken Powers
# 

# Import the modules used in the script
import RPi.GPIO as GPIO
import time

# Set constants
RUNNING = True
led_button = 18
led = 23

# Select GPIO numbering method and set switch pin
# as an input with internal pull-down resistance
# and LED pin as an output
GPIO.setmode(GPIO.BCM)
GPIO.setup(led_button, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(led, GPIO.OUT)
GPIO.output(led, GPIO.LOW)

# Illuminate an LED connected to GPIO 23
# if the push-button is pressed.

print("Press button to illuminate LED")

try:
	while RUNNING:
		while True:
			input_value = GPIO.input(led_button)
			if input_value == True:
				GPIO.output(led, GPIO.HIGH)
			while input_value == True:
				input_value = GPIO.input(led_button)
				time.sleep(0.01)
			GPIO.output(led, GPIO.LOW)

# If CTRL+C is pressed the main loop is broken
except KeyboardInterrupt:
    RUNNING = False
    print "\Quitting"

# Actions under 'finally' will always be called, regardless of
# what stopped the program (be it an error or an interrupt)
finally:
    # Stop and cleanup to finish cleanly so the pins
    # are available to be used again
    GPIO.cleanup()

Code Analysis:

Once again, we begin our Python script by letting the interpreter know which language we are using. Next, we make a few comments that let readers know some of the details of our program. Specifically, we want programmers to know that we are connecting a switch to the Raspberry Pi’s GPIO 18 and an LED to GPIO 23. By the way, although we suggest a red LED in our project requirements, you can utilize any color you have handy.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  switched_LED.py
#
# A short program to test implementing a switch
# connected to GPIO pin 18 which will turn on an LED
# connected to GPIO 23
#
#  Copyright 2015  Ken Powers
#

Our next section of code simply imports some necessary modules we will be using and defines some necessary constants.

# Import the modules used in the script
import RPi.GPIO as GPIO
import time

# Set constants
RUNNING = True
led_button = 18
led = 23

We then define our GPIO numbering method, set the appropriate GPIO pins as inputs and outputs, and toggle the internal pull-down resistance for our push-button input. It is very important to make sure the push-button switch pin is set as an INPUT and NOT an OUTPUT as this could potentially damage the Raspberry Pi.

# Select GPIO numbering method and set switch pin
# as an input with internal pull-down resistance
# and LED pin as an output
GPIO.setmode(GPIO.BCM)
GPIO.setup(led_button, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(led, GPIO.OUT)
GPIO.output(led, GPIO.LOW)

Our main Python script loop simply checks the status of the push-button pin. If it is TRUE (or depressed) the LED pin’s status is changed to HIGH (or on). Once the switch is released, the LED is turned off and the script continues until CTRL + C is pressed.

# Illuminate an LED connected to GPIO 23
# if the push-button is pressed.

print("Press button to illuminate LED")

try:
	while RUNNING:
		while True:
			input_value = GPIO.input(led_button)
			if input_value == True:
				GPIO.output(led, GPIO.HIGH)
			while input_value == True:
				input_value = GPIO.input(led_button)
				time.sleep(0.01)
			GPIO.output(led, GPIO.LOW)

# If CTRL+C is pressed the main loop is broken
except KeyboardInterrupt:
    RUNNING = False
    print "\Quitting"

# Actions under 'finally' will always be called, regardless of
# what stopped the program (be it an error or an interrupt)
finally:
    # Stop and cleanup to finish cleanly so the pins
    # are available to be used again
    GPIO.cleanup()

As you can see, it is very simple to combine the elements from our previous Projects to accomplish the task of turning an LED on and off. An additional fun experiment might be to attempt to modify the Python script to allow the LED to turn on with a single press of the switch and off with an additional press much like a standard light switch. Above all, however, have fun with your projects and what you have learned!

Project 7: A Simple Switch

What you will need:

  • Raspberry Pi
  • Breadboard
  • 4 Pushbutton Switches
  • 2 10kΩ Resistors —[III I]—
  • 4 1kΩ Resistors —[III I]—
  • 4 .1μF Ceramic Disk Capacitors
  • 6 Female to Male Jumper Wires
  • 4 Male to Male Jumper Wires

Instructions:

Up until now, all our projects have used Python scripts to manipulate LEDs. My son and I wanted to begin to introduce push-button switches into our future experiments. Before that could happen, however, we wanted to ensure we knew how switches worked with the Raspberry Pi’s GPIO.

Interestingly, we discovered that we couldn’t simply hook a switch between a controlling GPIO pin and ground to read its state. When a switch is connected to a GPIO input pin, its state is actually floating between high and low and is unreliable to read.

To anchor the GPIO pin’s state, we discovered we could connect either a Pull-Up or Pull-Down resistor to our switch. A Pull-Down resistor connects the pin to ground through a large resistance so when the switch is open there is a path to ground and the GPIO pin will read low. With the other side connected to 3.3v and the switch pressed, there is a lower resistance path to high and so the GPIO pin will read high. A large 10kΩ Pull-Down resistor in the circuit ensures that only a small amount of current is drawn when the switch is pressed.

Pull-Up Pull-Down Schematic

Building a circuit like this ensures we will be able to take reliable readings from our switch. However, it is still possible to damage the GPIO pins if they are accidentally set to output mode in our Python script. Pushing the button could easily create a short circuit between 3.3V and ground. To make this less possible, we can insert a 1kΩ limiting resistor into the circuit to ensure the Pi can handle the current drawn.

Interestingly, each GPIO pin of the Raspberry Pi also has a software configurable pull-up or pull-down resistor built into its hardware. When using a GPIO pin as an input, you can configure these resistors so they are enabled by using the optional PUD_UP or PUD_DOWN parameter of GPIO.setup. If this parameter is omitted, then neither resistor will be enabled.

As can be seen from our breadboard layout, we have set up four switches. The first is an example of using a Pull-Up resistor. The second is an example of using a Pull-Down resistor. The last two examples are identical to the first two except  they no longer use a physical resistor but instead use our Python script to incorporate the software configurable resistors built into the Raspberry Pi.

You might have noticed that we have inserted a .1μF capacitor across the pins of our switches. This can help if you experience a state fluctuation (bouncing) occurring during the time you are reading a switch connected to a GPIO pin. By connecting a capacitor, the result is a smoothing of the voltage curve. Before the button is pressed, the capacitor is fully charged. When the button is pressed, the capacitor starts draining. The voltage on the GPIO pin will smoothly ramp down from 3.3v to 0v and the GPIO will sense a single state change.

After carefully populating your breadboard and connecting the circuit to the Raspberry Pi’s GPIO, use your favorite editor to create the following Python script:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  switch_test.py
#
# A short program to test implementing 4 switches.
# Each switch is attached to the Raspberry Pi in a
# different manner. One uses a physical Pull-Up resistor.
# The second uses a physical Pull-Down resistor.
# The third uses an internal Pull-Up resistor and the fourth
# uses an internal Pull-Down resistor. The switches are
# attached to GPIO 17, 23, 24, and 25.
#
# Each switch is connected to a 1K resistor to protect the
# GPIO in case a pin is accidentally set to an Output
# instead of an Input mode which could short things out
# and damage the Raspberry Pi.
#
#  Copyright 2015  Ken Powers
# 

# Import the modules used in the script
import RPi.GPIO as GPIO
import time

# Set constants
RUNNING = True
button_one = 17
button_two = 23
button_three = 24
button_four = 25

# Select GPIO numbering method and set switch pin
# as an input
GPIO.setmode(GPIO.BCM)
GPIO.setup(button_one, GPIO.IN)
GPIO.setup(button_two, GPIO.IN)
GPIO.setup(button_three, GPIO.IN, GPIO.PUD_UP)
GPIO.setup(button_four, GPIO.IN, GPIO.PUD_DOWN)

# Main loop
try:
    while RUNNING:
		# Print a notification if a button is pressed
		while True:
			input_one = GPIO.input(button_one)
			input_two = GPIO.input(button_two)
			input_three = GPIO.input(button_three)
			input_four = GPIO.input(button_four)
			if input_one == False:
				print('Button One Pressed!')
			if input_two == True:
				print('Button Two Pressed!')
			if input_three == False:
				print('Button Three Pressed!')
			if input_four == True:
				print('Button Four Pressed!')
			# Wait until the button is released to move on
			while input_one == False or input_two == True or input_three == False or input_four == True:
				input_one = GPIO.input(button_one)
				input_two = GPIO.input(button_two)
				input_three = GPIO.input(button_three)
				input_four = GPIO.input(button_four)
				# Let the system have a brief break
				time.sleep(0.01)

# If CTRL+C is pressed the main loop is broken
except KeyboardInterrupt:
    RUNNING = False
    print "\Quitting"

# Actions under 'finally' will always be called
finally:
    # Stop and finish cleanly so the pins
    # are available to be used again
    GPIO.cleanup()

Code Analysis:

As with our previous projects, we begin by making sure the interpreter knows we are using the Python language. We also make a few comments so code analysts know what our Python script is going to accomplish.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  switch_test.py
#
# A short program to test implementing 4 switches.
# Each switch is attached to the Raspberry Pi in a
# different manner. One uses a physical Pull-Up resistor.
# The second uses a physical Pull-Down resistor.
# The third uses an internal Pull-Up resistor and the fourth
# uses an internal Pull-Down resistor. The switches are
# attached to GPIO 17, 23, 24, and 25.
#
# Each switch is connected to a 1K resistor to protect the
# GPIO in case a pin is accidentally set to an Output
# instead of an Input mode which could short things out
# and damage the Raspberry Pi.
#
#  Copyright 2015  Ken Powers
#

Next, we import the Python modules that are required for our script and define some constants. The first you may recognize from all our previous projects and is used in determining when our main program loop should end. The next four define which GPIO pins we are using to read the states of our switches.

# Import the modules used in the script
import RPi.GPIO as GPIO
import time

# Set constants
RUNNING = True
button_one = 17
button_two = 23
button_three = 24
button_four = 25

The next section of our Python script sets our GPIO mode to the Broadcom system. We then set our pre-defined GPIO pins to be inputs. Notice that the first two coincide with our two left-most breadboard buttons. They are using external Pull-Up and Pull-Down resistors. The next two coincide with the second set of switches on our breadboard which are using the Raspberry Pi’s internal Pull-Up and Pull-Down resistors so we need to mention that in our GPIO setup code. This is done through the use of the GPIO.PUD_UP and GPIO.PUD_DOWN parameters of GPIO.setup.

# Select GPIO numbering method and set switch pin
# as an input
GPIO.setmode(GPIO.BCM)
GPIO.setup(button_one, GPIO.IN)
GPIO.setup(button_two, GPIO.IN)
GPIO.setup(button_three, GPIO.IN, GPIO.PUD_UP)
GPIO.setup(button_four, GPIO.IN, GPIO.PUD_DOWN)

Our main program loop checks to see if a button has been pressed and then prints out an appropriate message. Notice that the switches using Pull-Up resistors are checked to see if their state is 0 or False which indicates they have been depressed. The switches using Pull-Down resistors are checked to see if their state is 1 or True to determine if they have been pressed.

Because the Raspberry Pi can check the state of the switches very rapidly, we have included another short loop that waits until a switch is released before the program proceeds. If we didn’t do this, the main loop would repeatedly print a new “Button Pressed” message until the switch was released.

The main Python script loop continues until Ctrl + C is pressed.

# Main loop
try:
    while RUNNING:
		# Print a notification if a button is pressed
		while True:
			input_one = GPIO.input(button_one)
			input_two = GPIO.input(button_two)
			input_three = GPIO.input(button_three)
			input_four = GPIO.input(button_four)
			if input_one == False:
				print('Button One Pressed!')
			if input_two == True:
				print('Button Two Pressed!')
			if input_three == False:
				print('Button Three Pressed!')
			if input_four == True:
				print('Button Four Pressed!')
			# Wait until the button is released to move on
			while input_one == False or input_two == True or input_three == False or input_four == True:
				input_one = GPIO.input(button_one)
				input_two = GPIO.input(button_two)
				input_three = GPIO.input(button_three)
				input_four = GPIO.input(button_four)
				# Let the system have a brief break
				time.sleep(0.01)

# If CTRL+C is pressed the main loop is broken
except KeyboardInterrupt:
    RUNNING = False
    print "\Quitting"

# Actions under 'finally' will always be called
finally:
    # Stop and finish cleanly so the pins
    # are available to be used again
    GPIO.cleanup()

Although this particular project isn’t the most glamorous or exciting to date, it has given us quite a bit of insight into the way a press-button switch functions and how it needs to be connected to the Raspberry Pi’s GPIO in order to properly operate. Most websites my son and I were able to find that discussed switches were fairly vague or difficult to understand. Our hope is that by presenting 4 different breadboard switch layouts along with Python script to read the switches, we will be able to help other Raspberry Pi enthusiasts.