Hi everyone! been using Blynk for a few months now and love the ease of use, but… I’m having issues with this code. just using the code to read the sensor works fine, but when I inject the Blynk code it doesn’t show the correct readings(maxed out) or display anything on the LCD. I had help to edit the original code (first one) too the second one but have been unable to resolve the issue. I am using a NodeMCU32s and Arduino IDE with Blynk on iOS. I have learning difficulties that makes it difficult for me to learn by sitting down and reading up, I learn by when I encounter issues but this has me stumped.
//First code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
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 setup(){
lcd.init();
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);
}
void loop(){
digitalWrite(ledPower,LOW);
delayMicroseconds(samplingTime);
voMeasured = analogRead(measurePin);
delayMicroseconds(deltaTime);
digitalWrite(ledPower,HIGH); // turn the LED off
delayMicroseconds(sleepTime);
calcVoltage = voMeasured * (5.0 / 1024.0);
dustDensity = 0.17 * calcVoltage - 0.1;
lcd.setCursor(1,1);
lcd.print(voMeasured);
lcd.setCursor(9,2);
lcd.print(calcVoltage);
lcd.setCursor(14,3);
lcd.print(dustDensity);
delay(1000);
}
//Second code for blynk
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
BlynkTimer timer;
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27);
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);
ifPrint();
}
void ifPrint(){
lcd.setCursor(1,1);
lcd.print(voMeasured);
lcd.setCursor(9,2);
lcd.print(calcVoltage);
lcd.setCursor(14,3);
lcd.print(dustDensity);
}
void setup(){
Blynk.begin(auth, ssid, pass);
lcd.begin(20,4);
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();
}