#include <Wire.h>
#include <Arduino.h>
#define led1 5
#define led2 18
#define PPM_PIN 4
int batas = 100;
void setup() {
Wire.begin(23, 22);
Serial.begin(115200);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
Serial.println("Hello, ESP32!");
}
void loop() {
// Value after from AD convertor
int16_t ppmValue = analogRead(PPM_PIN);
// Map the correct value ad AD convertor expects max votage to be 3.3 V and we are sending 5 V
int mappedppmValue = (ppmValue/4.095);
Serial.print("PPM: ");
Serial.println(mappedppmValue);
Serial.print("Nilai Analog = ");
Serial.println(ppmValue);
Serial.print("Smoke = ");
Serial.println(ppmValue-50);
if(ppmValue-50 >= batas){
Serial.println("Asap terdeteksi");
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
} else {
Serial.println("Asap tidak terdeteksi");
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
}
delay(1000);
}
esp:0
esp:2
esp:4
esp:5
esp:12
esp:13
esp:14
esp:15
esp:16
esp:17
esp:18
esp:19
esp:21
esp:22
esp:23
esp:25
esp:26
esp:27
esp:32
esp:33
esp:34
esp:35
esp:3V3
esp:EN
esp:VP
esp:VN
esp:GND.1
esp:D2
esp:D3
esp:CMD
esp:5V
esp:GND.2
esp:TX
esp:RX
esp:GND.3
esp:D1
esp:D0
esp:CLK
chip1:VCC
chip1:GND
chip1:A0
chip1:D0
led1:A
led1:C
led2:A
led2:C