macca-nz

Blynk_example_v4

Mar 7th, 2021 (edited)
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define BLYNK_PRINT Serial
  2. #include <WiFi.h>
  3. #include <WiFiClient.h>
  4. #include <BlynkSimpleEsp32.h>
  5. #include <Wire.h>
  6. #include <LiquidCrystal_I2C.h>
  7. BlynkTimer timer;
  8. LiquidCrystal_I2C lcd(0x27, 20, 4);
  9. char auth[] = "xxx";
  10. char ssid[] = "xxx";
  11. char pass[] = "xxx";
  12. int measurePin = 4;
  13. int ledPower = 2;
  14. int samplingTime = 280;
  15. int deltaTime = 40;
  16. int sleepTime = 9680;
  17. float voMeasured = 0;
  18. float calcVoltage = 0;
  19. float dustDensity = 0;
  20.  
  21. void myTimerEvent(){            //Put your loop instruction in here with the Virtual pins at the end
  22.     digitalWrite(ledPower,LOW);
  23.     delayMicroseconds(samplingTime);
  24.     voMeasured = analogRead(measurePin);
  25.     delayMicroseconds(deltaTime);
  26.     digitalWrite(ledPower,HIGH);
  27.     delayMicroseconds(sleepTime);
  28.     calcVoltage = voMeasured * (5.0 / 1024.0);
  29.     dustDensity = 0.17 * calcVoltage - 0.1;    
  30.     Blynk.virtualWrite(V20,voMeasured );
  31.     Blynk.virtualWrite(V21, calcVoltage);
  32.     Blynk.virtualWrite(V22, dustDensity);
  33.     updateLCD(voMeasured, calcVoltage, dustDensity);
  34. }
  35.  
  36. void updateLCD(float newVO, float newVolts, float newDust){
  37.     lcd.setCursor(1,1);
  38.     lcd.print(newVO, 2);
  39.     lcd.setCursor(9,2);
  40.     lcd.print(newVolts, 2);
  41.     lcd.setCursor(14,3);
  42.     lcd.print(newDust, 2);
  43.  
  44.     return;
  45. }  
  46. void setup(){
  47.     Blynk.begin(auth, ssid, pass);
  48.     lcd.begin();
  49.     lcd.backlight();
  50.     lcd.setCursor(0,0);
  51.     lcd.print("Raw Signal Value: ");
  52.     lcd.setCursor(0,2);
  53.     lcd.print("Voltage:");
  54.     lcd.setCursor(0,3);
  55.     lcd.print("Dust Density:");
  56.     pinMode(ledPower,OUTPUT);
  57.     timer.setInterval(1000L, myTimerEvent);   //This sets the time between samples
  58. }
  59. void loop(){
  60.   Blynk.run();
  61.   timer.run();
  62. }
Add Comment
Please, Sign In to add comment