EasyManua.ls Logo

Keyestudio ESP32 - Page 113

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
Code
To fulfil an invasion alarm, an “if() else” statement is necessary.
/*
keyestudio ESP32 Inventor Learning Kit
Project 17.2 Invasion Alarm
http://www.keyestudio.com
*/
int pir = 5; //Set PIR sensor pin to IO5
int red_led = 18; //Set red LED to pin IO18
int buzz = 19; //Set buzzer to pin IO19
void setup() {
// put your setup code here, to run once:
pinMode(pir,INPUT); //Set PIR pin to input mode
pinMode(red_led,OUTPUT); //Set LED pin to output mode
pinMode(buzz,OUTPUT); //Set buzzer pin to output mode
}
void loop() {
// put your main code here, to run repeatedly:
int pir_val = digitalRead(pir);
if(pir_val == 1){
digitalWrite(red_led,HIGH);
(continues on next page)
8.5. Arduino Project 109

Table of Contents