You are on page 1of 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