0% found this document useful (0 votes)
39 views

Lab 7 (1) Iot

This document discusses interfacing various sensors with an ESP32 microcontroller. It provides code examples for connecting a humidity sensor, heart rate sensor, and PIR motion sensor to the ESP32. For each sensor, it outlines the necessary pin connections and includes the full Arduino code for reading and displaying or responding to the sensor data. The goal of the lab is to learn how to integrate different sensor types with the ESP32 using Arduino code.

Uploaded by

NAUTASH KHAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Lab 7 (1) Iot

This document discusses interfacing various sensors with an ESP32 microcontroller. It provides code examples for connecting a humidity sensor, heart rate sensor, and PIR motion sensor to the ESP32. For each sensor, it outlines the necessary pin connections and includes the full Arduino code for reading and displaying or responding to the sensor data. The goal of the lab is to learn how to integrate different sensor types with the ESP32 using Arduino code.

Uploaded by

NAUTASH KHAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

ESP with sensors Lab 7

ESP interfacing with sensors.

Learn about Arduino and the Arduino UNO and how you can integrate this board into your makerspace and coding program. Make interactive makerspace projects while learning to code and problem solve.

In this Lab Interface different sensors with esp32 that you have already interfaced with Arduino.

Lab Tasks

1. Connect Humidity sensor with esp32.


#define DHT11PIN 16
DHT dht(DHT11PIN, DHT11);
void setup()
{

Serial.begin(115200);
/* Start the DHT11 Sensor */
dht.begin();
}

void loop()
{
float humi = dht.readHumidity();
float temp = dht.readTemperature();
Serial.print("Temperature: ");
Serial.print(temp);
Serial.print("ºC ");
Serial.print("Humidity: ");
Serial.println(humi);
delay(1000);
}
1
ESP with sensors Lab 7

2. Connect heart rate sensor with esp32.


 int PulseSensorPurplePin = 0; // Pulse Sensor PURPLE WIRE connected to
ANALOG PIN 0
 int LED13 = 13; // The on-board Arduion LED


 int Signal; // holds the incoming raw data. Signal value can
range from 0-1024
 int Threshold = 550; // Determine which Signal to "count as a
beat", and which to ingore.


 // The SetUp Function:
 void setup() {
 pinMode(LED13,OUTPUT); // pin that will blink to your heartbeat!
 Serial.begin(9600); // Set's up Serial Communication at certain
speed.

 }

 // The Main Loop Function
 void loop() {

 Signal = analogRead(PulseSensorPurplePin); // Read the PulseSensor's
value.
 // Assign this value to the
"Signal" variable.

 Serial.println(Signal); // Send the Signal value to
Serial Plotter.

 if(Signal > Threshold){ // If the signal is above


"550", then "turn-on" Arduino's on-Board LED.
 digitalWrite(LED13,HIGH);
 } else {
 digitalWrite(LED13,LOW); // Else, the sigal must be
below "550", so "turn-off" this LED.
 }

 delay(10);

3. Connect PIR motion sensor with esp32.

/*

2
ESP with sensors Lab 7
PIR sensor tester
*/

int ledPin = 12; // choose the pin for the LED


int inputPin = 14; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status

void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input

Serial.begin(9600);
}

void loop() {
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH) {
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}

3
ESP with sensors Lab 7

Conclusion

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy