Zeeshan IOT Assignment#2
Zeeshan IOT Assignment#2
of Computer
Science MY
University,
Islamabad.
Batch: FALL-2022
Semester: 5th
Question #1
Human motion sensor ( PIR sensor )
PIR sensor is a sensor that can detect the motion of humans (or animals). It's widely used to
detect the presence of humans in many applications (automatically turning ON/OFF light bulb,
opening/closing the door, activating/deactivating escalator, detecting an intruder ...)
1. VCC Pin: Connect the VCC pin of the PIR sensor to the 5V pin on the Arduino. This will
power the PIR sensor.
2. GND Pin: Connect the GND pin of the PIR sensor to one of the GND (Ground) pins on
the Arduino. This establishes a common ground for the circuit.
3. OUT Pin: Connect the OUT pin of the PIR sensor to a digital input pin on the Arduino.
Any digital pin can be used, but for this example, let’s use pin 12.
Diagram
Implementation
Pin Diagram
Code
Code
int pirPin = 12;
int motionStatus = 0; // variable to store the PIR sensor's motion status (high or low)
void setup() {
Serial.begin(9600);
pinMode(pirPin, INPUT); // set the Arduino pin that PIR sensor is connected to as an INPUT
}
void loop() {
motionStatus = digitalRead(pirPin); // read the PIR pin's current output (is it high or low?)
if (motionStatus == HIGH) {
Serial.println("Motion Detected");
else { Serial.println ("Motion Ended"); }
delay(100);
The LDR light sensor module can be utilized to detect the presence of light or measure the light
level in the surrounding environment. It provides two options via a digital output pin and analog
output pin.
4. AO pin: It is an analog output pin. The output value decreases as the light gets
brighter, and it increases as the light gets darker.
Diagram
Pin diagram
Code
Code
#define DO_PIN 2 // Arduino's pin connected to DO pin of the ldr module
void setup() {
Serial.begin(9600); // initialize serial communication
pinMode(DO_PIN, INPUT); // initialize the Arduino's pin as an input
}
void loop() {
int lightState = digitalRead(DO_PIN);
if (lightState == HIGH)
Serial.println("The light is NOT present");
else
Serial.println("The light is present");
The MAX30100 is a Pulse Oximetry heart rate monitor and calculate SP02 sensor solution. It
combines two LEDs, a photodetector, optimized optics, and low-noise analog signal processing
to detect pulse oximetry and heart-rate signals. You can use this sensor with any microcontroller
like Arduino, ESP8266, or ESP32 and easily measure the patient’s health parameters. This
cheap DIY Pulse Oximeter sensor just cost around 350.RS and can be used in multiple
applications if you are a beginner or an Electronics enthusiast.
Diagram
Pin diagram
Code
Code
#include <Wire.h>
#include "MAX30105.h"
MAX30105 particleSensor;
void setup() {
Serial.begin(9600);
// Initialize sensor
if (particleSensor.begin() == false) {
Serial.println("MAX30102 was not found. Please check wiring/power.");
while (1);
}
particleSensor.setup(); //Configure sensor. Use 6.4mA for LED drive
}
void loop() {
Serial.print(" R[");
Serial.print(particleSensor.getRed());
Serial.print("] IR[");
Serial.print(particleSensor.getIR());
Serial.println("]");
}