Aim:
To use sensor input to control an output device based on conditions.
Requirements:
- Arduino Uno or Raspberry Pi Pico
- PIR motion sensor or LDR (light sensor)
- Buzzer or LED
- Jumper wires
- Breadboard
- Computer with Arduino IDE or Thonny IDE
Procedure:
- Set Up Your Microcontroller
- Connect your Arduino or Pico to your computer.
- Open Arduino IDE (for Arduino) or Thonny IDE (for Pico).
- Choose Your Sensor
- If using PIR motion sensor: Detects movement.
- If using LDR: Detects light levels.
- Connect the Components
- Vcc of sensor → 5V or 3.3V on board.
- GND → Ground.
- Sensor output → Digital input pin (e.g., D2).
- Buzzer/LED → Output pin (e.g., D13) with a resistor if needed.
Write the “If-Then” Code
Example for motion sensor and buzzer (Arduino):
cpp
CopyEdit
if (digitalRead(sensorPin) == HIGH) {
digitalWrite(buzzerPin, HIGH); // Buzzer ON
} else {
digitalWrite(buzzerPin, LOW); // Buzzer OFF
}
4.Test the System
-
- Wave your hand in front of the PIR sensor — the buzzer or LED should turn ON.
- Remove motion — it should turn OFF.
5.Add a Second Condition
- Example: Only alert if it’s dark AND motion is detected.
- This requires two sensors (PIR + LDR) and nested if conditions.
6.Record Your Observations
Note when the output device activates and when it stays off.