Tags:
view all tags
---+ Exercise 3: Switches ---++ Introduction Switches exist in various incarnations. There are the simple mechanical switches: on/off or push button switches but there are also switches than turn on or off with various external conditions: * temperature * infra red radiation (e.g. the Passive Infrared Sensor or PIR sensor) * Hall switches detecting magnetic field * microphone switches which turn on when a certain noise level is detected In this exercise we will use a mechanical push button switch <img alt="button.png" height="455" src="%ATTACHURL%/button.png" title="button.png" width="432" /> and a PIR sensor. <img alt="pir.png" height="457" src="%ATTACHURL%/pir.png" title="pir.png" width="429" /> ---++ Exercise 1: The push button switch is connected to GPIO 17 on the ESP32 board. Write a script that polls the state of the switch every 100 ms and prints state changes (only print out a message when the switch state has changed). Catch <ctrl> C to smoothly exit the program. Check [[https://docs.micropython.org/en/latest/esp8266/tutorial/pins.html][https://docs.micropython.org/en/latest/esp8266/tutorial/pins.html ]]and [[https://docs.micropython.org/en/latest/esp32/quickref.html][https://docs.micropython.org/en/latest/esp32/quickref.html ]]for information on how to accomplish this. ---++ Exercise 2: Do the same thing as in exercise 1 but use external interrupts and a callback routine to do the job. ---++ Exercise 3: Combine this exercise with the exercise on !LEDs: Switch the builtin LED on when the button is pressed and off when it is released ---++ Exercise 4: Write a program scanning the PIR sensor, indicating if a person is close. The PIR sensor, just like the push button, uses a single GPIO line as input. The boards allows to choose which GPIO to use and I selected D4 = GPIO 16 ---++ Exercise 5: The sensor kit in the lab contains a big number of sensors acting like switches: * rolling ball switch * mercury switch * noise level detector (microphone) * hall sensor (detecting magnetic field) * reed relay (detecting magnetic field) * and many more... Connect these sensors to the ESP32 and try them with the programs developed in exercise 1-3 -- %USERSIG{UliRaich - 2020-05-06}% ---++ Comments %COMMENT%
Attachments
Attachments
Topic attachments
I
Attachment
History
Action
Size
Date
Who
Comment
png
button.png
r1
manage
279.6 K
2020-05-06 - 09:01
UliRaich
png
pir.png
r1
manage
319.4 K
2020-05-06 - 09:01
UliRaich
Edit
|
Attach
|
Watch
|
P
rint version
|
H
istory
:
r9
|
r6
<
r5
<
r4
<
r3
|
B
acklinks
|
V
iew topic
|
Raw edit
|
More topic actions...
Topic revision: r4 - 2020-05-21
-
UliRaich
Home
Site map
AFNOG web
Embedded_Systems web
IoT_Course_English web
IoT_Course_French web
Main web
Sandbox web
TWiki web
IoT_Course_English Web
Create New Topic
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
P
View
Raw View
Print version
Find backlinks
History
More topic actions
Edit
Raw edit
Attach file or image
Edit topic preference settings
Set new parent
More topic actions
Account
Log In
Register User
Edit
Attach
Copyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback