Hi, I am using ESP32 for read gas sensor and temperature data and send to blynk server as well as Serial Monitor and lcd display. I can read only Gas sensor data but temperature sensor read only zero. I double check the hardware connection. Here are my code
int gasPin=33;
int lm35=34;
// Setup adxl335 x, y , z pin
/*int xAxis = 32;
int yAxis = 35;
int zAxis = 39;*/
int buzzer = 5;
//int Switch = 15;
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define BLYNK_TEMPLATE_ID "TMPL0sHFSboC"
#define BLYNK_TEMPLATE_NAME "AI DRIVEN"
#define BLYNK_AUTH_TOKEN "Cl0H_xKNnQbqFGgpalOmjnlCxpxwTkl"
#define BLYNK_PRINT Serial
#include <WiFi.h>
//#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp32.h>
//#include <DHT.h>
//char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "HI"; // type your wifi name
char pass[] = "00000000"; // type your wifi password
BlynkTimer timer;
void setup()
{
pinMode(buzzer,OUTPUT);
Serial.begin(115200);
lcd.begin(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
lcd.clear();
//*********0123456789012345
lcd.print("Drink L:");
lcd.print(" Temp:");
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
//dht.begin();
timer.setInterval(1000L, sendSensor);
digitalWrite(buzzer,HIGH);
delay(500);
digitalWrite(buzzer, LOW);
}
void loop()
{
Blynk.run();
timer.run();
}
void sendSensor(){
float gasLevel = analogRead(gasPin);
float temperature = analogRead(lm35);
Serial.print(temperature);
// Convert sensor readings to meaningful values
gasLevel = map(gasLevel, 0, 4095, 0, 100); // Assuming 0-100% range for gas sensor
temperature = (temperature * 0.080586); // (0.080586 )Convert LM35 output to Celsius (3.3V/4095)
// Send sensor data to Blynk app
Serial.print("Gas: ");
Serial.print(gasLevel);
lcd.setCursor(2,1);
lcd.print(gasLevel);
Serial.print(" Temperature: ");
Serial.println(temperature);
lcd.setCursor(11,1);
lcd.print(temperature);
Blynk.virtualWrite(V0, gasLevel); // Display gas level on V0
Blynk.virtualWrite(V1, temperature); // Display temperature on V1
}
And my second problem is that Serial monitor and lcd display shows data when device connected to wifi, until wifi connected i can’t get data offline, even buzzer not beep. What should I change to my code for get offline dat when no wifi available. I also try below this and it does not work.
//Tech Trends Shameer
int gasPin=33;
int lm35=34;
// Setup adxl335 x, y , z pin
/*int xAxis = 32;
int yAxis = 35;
int zAxis = 39;*/
int buzzer = 5;
//int Switch = 15;
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define BLYNK_TEMPLATE_ID "TMPL0sHFSboC"
#define BLYNK_TEMPLATE_NAME "AI DRIVEN"
#define BLYNK_AUTH_TOKEN "Cl0H_xKNnQbqFGgpalOmjnlCxpxwTkl"
#define BLYNK_PRINT Serial
#include <WiFi.h>
//#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp32.h>
//#include <DHT.h>
//char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "HI"; // type your wifi name
char pass[] = "00000000"; // type your wifi password
BlynkTimer timer;
void setup()
{
pinMode(buzzer,OUTPUT);
Serial.begin(115200);
lcd.begin(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
lcd.clear();
//*********0123456789012345
lcd.print("Drink L:");
lcd.print(" Temp:");
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
//dht.begin();
timer.setInterval(1000L, sendSensor);
digitalWrite(buzzer,HIGH);
delay(500);
digitalWrite(buzzer, LOW);
}
void loop()
{
Blynk.run();
timer.run();
sensorData();
}
void sendSensor(){
float gasLevel = analogRead(gasPin);
float temperature = analogRead(lm35);
//Serial.print(temperature);
// Convert sensor readings to meaningful values
gasLevel = map(gasLevel, 0, 4095, 0, 100); // Assuming 0-100% range for gas sensor
temperature = (temperature * 0.080586); // (0.080586 )Convert LM35 output to Celsius (3.3V/4095)
/*// Send sensor data to Blynk app
Serial.print("Gas: ");
Serial.print(gasLevel);
lcd.setCursor(2,1);
lcd.print(gasLevel);
Serial.print(" Temperature: ");
Serial.println(temperature);
lcd.setCursor(11,1);
lcd.print(temperature);*/
Blynk.virtualWrite(V0, gasLevel); // Display gas level on V0
Blynk.virtualWrite(V1, temperature); // Display temperature on V1
}
void sensorData(){
float gasLevel = analogRead(gasPin);
float temperature = analogRead(lm35);
Serial.print(temperature);
// Convert sensor readings to meaningful values
gasLevel = map(gasLevel, 0, 4095, 0, 100); // Assuming 0-100% range for gas sensor
temperature = (temperature * 0.080586); // (0.080586 )Convert LM35 output to Celsius (3.3V/4095)
// Send sensor data to Blynk app
Serial.print("Gas: ");
Serial.print(gasLevel);
lcd.setCursor(2,1);
lcd.print(gasLevel);
Serial.print(" Temperature: ");
Serial.println(temperature);
lcd.setCursor(11,1);
lcd.print(temperature);
delay(250);
}