Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using a raspberry pi 3+ please modify this code to turn on a buzzer whenever the moisture sensor senses moisture Be advised that the buzzer

Using a raspberry pi 3+

please modify this code to turn on a buzzer whenever the moisture sensor senses moisture

Be advised that the buzzer is vcc and ground only.

#!/usr/bin/python import RPi.GPIO as GPIO import time #GPIO SETUP channel = 21 GPIO.setmode(GPIO.BCM) GPIO.setup(channel, GPIO.IN) def callback(channel): if GPIO.input(channel): print("NO Water Detected!") else: print("Water Detected!") GPIO.add_event_detect(channel, GPIO.BOTH, bouncetime=300) # let us know when the pin goes HIGH or LOW GPIO.add_event_callback(channel, callback) # assign function to GPIO PIN, Run function on change # infinite loop while True: time.sleep(0.1)

Please run and test it

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

10-9 How have social technologies changed e-commerce?

Answered: 1 week ago