Practical 10 - Other Sensors
Practical 10 - Other Sensors
We use luma-oled libraries, provided by Richard Hull and contributors to support most of the
OLED Display version. Our Grove-OLED Display 1.12” version 2.2 comes with SH1107G,
128x128 pixels in 16 gray shades.
* If you are using your own Raspberry Pi, do install luma-oled libraries by typing:
sudo -H pip3 install --upgrade luma.oled
* Reference: https://wiki.seeedstudio.com/Grove-OLED_Display_1.12inch/
* Reference: https://luma-oled.readthedocs.io/en/latest/index.html
* Reference: https://lastminuteengineers.com/oled-display-arduino-tutorial/
Step 1: In Thonny Python (ID), click “New” to create a new python file and Save As “test11.py”.
Type the following codes:
Task 3: Display a QR code on the OLED display, scan using your smartphone to enter
a website.
This Grove - PIR Motion Sensor (Passive InfraRed Sensor) can detect infrared signals caused
by motion. If the PIR sensor notices the infrared energy, the motion detector is triggered and the
sensor outputs HIGH on its SIG pin. The detecting range and response speed can be adjusted
by 2 potentiometers soldered on its circuit board, The response speed is from 0.3s - 25s, and
max 6 meters of detecting range.
This is an easy-to-use motion sensor with Grove compatible interface. Simply connecting it to
Base Shield and programming it, it can be used as a suitable motion detector for Arduino
projects. For example, the PIR Motion Sensor is commonly used in security alarm systems and
automatic lighting applications.
* Reference: https://www.mouser.com/catalog/specsheets/Seeed_101020020.pdf
https://www.seeedstudio.com/Grove-PIR-Motion-Sensor.html
Step 1: In Thonny Python (ID), click “New” to create a new python file and Save As
“test12.py”. Type the following codes:
* Take note that the PIR sensor is “super” sensitive to any heat movement, suggest to
cover the sensor with a book and only expose the sensor to a heat movement
(hand-waving)
BAIT2123 INTERNET OF THINGS Jul 2024
Task 1: Integrate with Part 1 to show some advertisement image when there are people
waiting around (i.e., PIR detects motion)
BAIT2123 INTERNET OF THINGS Jul 2024
PART 3: Read values from Grove Moisture, Water and Touch sensors
We use these three sensors and read the values accordingly to perform certain actions (e.g.,
turn on a relay that connects to a water valve control, to water a plant).
* Reference: https://wiki.seeedstudio.com/Grove-Moisture_Sensor/
* Reference: https://wiki.seeedstudio.com/Grove-Water_Sensor/
* Reference: https://wiki.seeedstudio.com/Grove-Touch_Sensor/
Refer to the sample code below for exploring the hardware connections.
Step 1: In Thonny Python (ID), click “New” to create a new python file and Save As “test15.py”.
Type the following codes:
RFID stands for Radio Frequency IDentification. For our information, there are a few things
required as parts of an operational RFID System in place:
- A reader, that is connected to (or integrated with) embedded system
- An antenna, that sends out / receives in a radio signal
- A tag (or transponder) that returns the signal with information added
- An algorithm that is coded / programmed in an embedded system for specific features.
RFID systems use a wide range of frequency bandwidth. The antennas on both the reader and
the tag are tuned to a specific frequency to enable basic interoperability. Frequencies that are
often used in access control are (examples in bracket)
- Low Frequency (120 - 1355kHz) : HID Prox, EM, Nedap NeXS ...
- High Frequency (13.56 MHz) : MIFARE Classic, DESfire ...
- Ultra High Frequency (860 - 980 MHz) : RAIN RFID / EPC Gen 2 ...
- Microwave (2.45 GHz) : Nedap TRANSIT ...
Our Grove RFID Reader (Left) is running on 125kHz for PART 1. If you are interested to explore
more in this RFID system, you can get a low cost reader RC522 for 13.56MHz that comes in a
set (Right) for PART 2.
This Grove-125KHz RFID Reader is a module used to read uem4100 RFID card information
with two output formats: Uart and Wiegand. It has a sensitivity with a maximum 7cm sensing
distance. It can help us with projects like the access control systems.
* Reference: https://wiki.seeedstudio.com/Grove-125KHz_RFID_Reader/
BAIT2123 INTERNET OF THINGS Jul 2024
Our Grove-125kHz RFID Reader is using serial communication (i.e., UART). Enable your
Raspberry Pi Serial Port in the Raspberry Pi Configuration > Interfaces page (MUST disable the
Serial Console) and restart.
In Raspberry Pi version 1, 2, 3 and 4, there are several pre-configuration required to ensure the
serial data is readable from the memory (i.e., ttyS0 or ttyAMA0). In Pi version 4, the bluetooth is
enabled by default (then we have to use ttyS0) or set to disable-uart / mini-uart to use ttyAMA0
(refer to the reference on steps). For more information, please refer to the reference to
understand on Raspberry Pi UART architecture:
* Reference: https://www.raspberrypi.org/documentation/configuration/uart.md
Step 1: We use Raspberry Pi Serial Port (RPISER port on Grove Pi). Connect the Buzzer at
Port D2 and Grove 125kHz RFID module at the RPISER port [not SERIAL Port].
Step 2: In Thonny Python (ID), click “New” to create a new python file and Save As
“test13.py”. Write the following codes in the python file.
BAIT2123 INTERNET OF THINGS Jul 2024
Step 3: Run the codes with a 125kHz tag (i.e., access card or key chain).
* Reference: https://pimylifeup.com/raspberry-pi-rfid-rc522/
Step 1: If you are using your own Raspberry Pi, do install mfrc522 libraries by typing:
sudo pip3 install mfrc522
Step 2: Follow the guidelines provided by the reference to connect RFID-RC522 with
respective Raspberry Pi GPIO pins, add on a buzzer at GPIO 18:
* Follow the additional notes to construct the circuit using transistor, resistor and
buzzer.
BAIT2123 INTERNET OF THINGS Jul 2024
Step 3: In Thonny Python (ID), click “New” to create a new python file and Save As
“test14.py”. Write the following codes in the python file.
Additional Notes
Objective
Understand how to control servos using a Raspberry Pi's GPIO pins to support a basic project
to demonstrate precise positional control of a servo motor.
Background
A small, geared motor that can rotate to specific angular positions based on control signals.
They are used in many hobbyist applications like robotics, animatronics, and automation. Unlike
regular DC motors, servos provide precise control over their rotation with the help of an internal
feedback mechanism.
The Servo has three wires: power, ground, and signal. The power wire is typically red, and
should be connected to the 5V pin. The ground wire is typically black or brown and should be
connected to a ground pin. The signal pin is typically yellow, orange or white and should be
connected to the embedded system Pulse Wave Modulation (PWM) pin for controlling the servo
motor rotations.
Our servo motor can only turn in total 180 degrees, or forward / backward maximum to 90
degrees. Choose your favorite motor horn / arm / wing that suits your project applications, and
gear (screw) it on the motor gear GENTLY.
Reference: https://wiki.seeedstudio.com/Grove-Servo/#software-2
BAIT2123 INTERNET OF THINGS Jul 2024
Connect the servo motor to the PWM port (pin 12 in python code). Type the following code to
experience how the PWM controls the servo motor.
BAIT2123 INTERNET OF THINGS Jul 2024
Raspberry Pi original GPIO Pins with Pulse Width Modulation (PWM) feature:
Raspberry Pi's have General Purpose Input/Output (GPIO) pins that can be programmed to
send or receive signals. These pins allow you to interact with electronic components. The
available PWM signals are used to control a servo motor's position. By varying the width of the
pulses sent to the servo, you can command it to rotate to different angles.
Reference: https://projects.raspberrypi.org/en/projects/grandpa-scarer/3
Step 1: Connect the servo motor with 3 male to female and 1 male to male jumper wires to:
- Servo Motor Brown color cable to Raspberry Pi GND (pin 6 or other GND pin)
- Servo Motor Red color cable to Raspberry Pi 5V (pin 2 or 4) via a Schottky diode 1N5819
* You may need to use a breadboard with one male to female and 1 male to male jumper wires
* Please take note that DO NOT connect the servo motor connection “on top of the
connected GrovePi board” (refer to practical 3 on description of Raspberry Pi and GrovePi
connection)
* Please take note that DO NOT connect the servo motor connection by using the GrovePi
connectors (Not GrovePi’s PWM connectors too), as the GrovePi+ is not supporting the servo
motor control. This could cause the servo motor to be overheated due to incorrect PWM signals.
BAIT2123 INTERNET OF THINGS Jul 2024
Step 2:
We will be using a servo for the latch that holds the panel closed.
RPi.GPIO allows for really easy software PWM to be added to your Python programs.
Unset
# Set up libraries and overall settings
import RPi.GPIO as GPIO # Imports the standard Raspberry Pi GPIO library
from time import sleep # Imports sleep (aka wait or pause) into the program
GPIO.setmode(GPIO.BOARD) # Sets the pin numbering system to use the physical
layout
# Clean up everything
p.stop() # At the end of the program, stop the PWM
GPIO.cleanup() # Resets the GPIO pins back to defaults
BAIT2123 INTERNET OF THINGS Jul 2024
Task:
Resource: https://github.com/bogde/HX711
https://www.liberiangeek.net/2024/03/interface-esp32-with-weight-sensor-hx711-
amplifier/
Step 1: Open Arduino IDE and go to Sketch > Include Library > Manage Libraries.
Search for “HX711 Arduino Library” and install the library by Bogdan Necula.
Install HX711 Bogdan Library Arduino IDE.
Save this scale factor, as you are going to use this in the next code.