Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define BLYNK_PRINT Serial
- #include <WiFi.h>
- #include <WiFiClient.h>
- #include <BlynkSimpleEsp32.h>
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- BlynkTimer timer;
- LiquidCrystal_I2C lcd(0x27, 20, 4);
- char auth[] = "xxx";
- char ssid[] = "xxx";
- char pass[] = "xxx";
- int measurePin = 4;
- int ledPower = 2;
- int samplingTime = 280;
- int deltaTime = 40;
- int sleepTime = 9680;
- float voMeasured = 0;
- float calcVoltage = 0;
- float dustDensity = 0;
- void myTimerEvent(){ //Put your loop instruction in here with the Virtual pins at the end
- digitalWrite(ledPower,LOW);
- delayMicroseconds(samplingTime);
- voMeasured = analogRead(measurePin);
- delayMicroseconds(deltaTime);
- digitalWrite(ledPower,HIGH);
- delayMicroseconds(sleepTime);
- calcVoltage = voMeasured * (5.0 / 1024.0);
- dustDensity = 0.17 * calcVoltage - 0.1;
- Blynk.virtualWrite(V20,voMeasured );
- Blynk.virtualWrite(V21, calcVoltage);
- Blynk.virtualWrite(V22, dustDensity);
- updateLCD(voMeasured, calcVoltage, dustDensity);
- }
- void updateLCD(float newVO, float newVolts, float newDust){
- lcd.setCursor(1,1);
- lcd.print(newVO, 2);
- lcd.setCursor(9,2);
- lcd.print(newVolts, 2);
- lcd.setCursor(14,3);
- lcd.print(newDust, 2);
- return;
- }
- void setup(){
- Blynk.begin(auth, ssid, pass);
- lcd.begin();
- lcd.backlight();
- lcd.setCursor(0,0);
- lcd.print("Raw Signal Value: ");
- lcd.setCursor(0,2);
- lcd.print("Voltage:");
- lcd.setCursor(0,3);
- lcd.print("Dust Density:");
- pinMode(ledPower,OUTPUT);
- timer.setInterval(1000L, myTimerEvent); //This sets the time between samples
- }
- void loop(){
- Blynk.run();
- timer.run();
- }
Add Comment
Please, Sign In to add comment