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;
int
red_led
=
18;
int
buzz
=
19;
void
setup() {
// put your setup code here, to run once:
pinMode(pir,INPUT);
pinMode(red_led,OUTPUT);
pinMode(buzz,OUTPUT);
}
void
loop() {
// put your main code here, to run repeatedly:
int
pir_val
=
digitalRead(pir);
if(pir_val
==
1){
digitalWrite(red_led,HIGH);
8.5. Arduino Project
//Set PIR sensor pin to IO5
//Set red LED to pin IO18
//Set buzzer to pin IO19
//Set PIR pin to input mode
//Set LED pin to output mode
//Set buzzer pin to output mode
ESP32 Starter Kit
(continues on next page)
109
Need help?
Do you have a question about the ESP32 and is the answer not in the manual?
Questions and answers