9. Input Devices¶
Group assignment:¶
- Probe an input device(s)’s analog levels and digital signals
- Document your work on the group work page and reflect on your individual page what you learned
Individual assignment:¶
- Measure something: add a sensor to a microcontroller board that you have designed and read it.
Helpful Documenting of Past Students¶
What Sensor?¶
I decided to use the passive infrared sensor sensor. A passive infrared sensor (PIR sensor) is an electronic sensor that measures infrared (IR) light radiating from objects in its field of view. They are most often used in PIR-based motion detectors. PIR sensors are commonly used in security alarms and automatic lighting applications.
Later in the project I have decided to change this to a Doppler Radar. The Doppler Radar Sensor Module is a doppler radar microwave sensor module for detecting moving objects. This can act as an alternative to Passive Infrared (PIR) motion sensing. The doppler sensor detects “any movement” from “any object” and does not rely on heat, making it more reliable in hot environments.
Unlike the PIR sensor, this is an active sensor. Active sensors send out a pulse of energy and detect the changes in the return signal, while passive sensors detect energy emitted or reflected from an object.
PIR Sensor¶
Wokwi¶
Wokwi is a simulater like tinkerCAD. In our lab we are required to first test with a simulator because we don’t want to accidentally to burn out a boards.
This is the code for the PIR sensor in wokwi.
This is the PIR sensor not detecting motion. To simulate the motion I needed to click the button.
This is the PIR sensor detecting motion as you can see. Once the motion was detected the LED turned on.
Code¶
// Define pins
#define PIR_SENSOR_PIN D3 // GPIO pin connected to PIR sensor output
#define LED_PIN D2 // GPIO pin connected to LED
void setup() {
pinMode(PIR_SENSOR_PIN, INPUT); // Set PIR sensor pin as input
pinMode(LED_PIN, OUTPUT); // Set LED pin as output
digitalWrite(LED_PIN, LOW); // Ensure LED is off initially
Serial.begin(115200); // Start serial communication
}
void loop() {
int motionDetected = digitalRead(PIR_SENSOR_PIN);
if (motionDetected == HIGH) {
digitalWrite(LED_PIN, HIGH); // Turn LED on
Serial.println("Motion detected! LED ON");
} else {
digitalWrite(LED_PIN, LOW); // Turn LED off
Serial.println("No motion. LED OFF");
}
delay(500); // Small delay to avoid excessive readings
}
This is the code for the PIR Sensor