EasyManua.ls Logo

Keyestudio ESP32 - 4. Test Code

Keyestudio ESP32
344 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
ESP32 Starter Kit
3. Wiring Diagram
4. Test Code
From the working principle, we can read the level of the sensor pin to judge whether there are people nearby.
/*
keyestudio ESP32 Inventor Learning Kit
Project 17.1 Invasion Alarm
http://www.keyestudio.com
*/
int pir = 5; //Define IO5 as PIR sensor pin
void setup() {
pinMode(pir,INPUT); //Set IO5 pin to input
Serial.begin(9600);
}
void loop() {
int pir_val = digitalRead(pir); //Read the PIR result and assign it to pir_val
Serial.print("pir_val:"); //Print “pir_val”
Serial.println(pir_val);
delay(500);
(continues on next page)
106 Chapter 8. Arduino Tutorial

Table of Contents