I used 4 sensor with arduino uno and also connected it to blynk, i also want to display the output in LCD but when i upload the lcd code the its not running, but without the lcd code its running in blynk. what should i do ?
this my code without LCD (the none running in blynk)
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_TEMPLATE_NAME ""
#define BLYNK_AUTH_TOKEN ""
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
// Your WiFi credentials.
// Set password to "" for open networks.
const char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "";
char pass[] = "";
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600
OneWire oneWire(4); // Pin 2 is used for the OneWire interface
DallasTemperature sensors(&oneWire); // Pass the OneWire reference to DallasTemperature library
ESP8266 wifi(&EspSerial);
float calibration_value = 22.85;
int phval = 0;
unsigned long int avgval;
int buffer_arr[10], temp;
int temperature;
int turb ;
float ph ;
int tds ;
const int tdsPin = A1; // Analog input pin for TDS sensor
BlynkTimer timer;
void setup() {
// Debug console
Serial.begin(9600);
delay(10);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(BLYNK_AUTH_TOKEN, wifi, ssid, pass);
timer.setInterval(1000L, getSendData);
}
void loop() {
Blynk.run();
timer.run();
}
void getSendData(){
// Temperature
sensors.requestTemperatures(); // Request temperature readings from the sensor
float temperature = sensors.getTempCByIndex(0); // Get the temperature in Celsius
// Turbidity
int turbidity = analogRead(A2);
float turb = turbidity * (5.0 / 1024.0) * 3;
// pH
for (int i = 0; i < 10; i++) {
buffer_arr[i] = analogRead(A0);
}
for (int i = 0; i < 9; i++) {
for (int j = i + 1; j < 10; j++) {
if (buffer_arr[i] > buffer_arr[j]) {
temp = buffer_arr[i];
buffer_arr[i] = buffer_arr[j];
buffer_arr[j] = temp;
}
}
}
avgval = 0;
for (int i = 2; i < 8; i++) {
avgval += buffer_arr[i];
}
float volt = (float)avgval * 5.0 / 1024 / 6;
ph = -5.70 * volt + calibration_value;
int tdsValue = analogRead(tdsPin);
float voltage2 = tdsValue * (5.0 / 1024.0);
float tds = voltage2 * 1000; // Convert to TDS value (adjust the conversion factor as per your sensor)
Serial.print("temp: ");
Serial.println(temperature);
Serial.print("turb: ");
Serial.println(turb);
Serial.print("ph: ");
Serial.println(ph);
Serial.print("tds: ");
Serial.println(tds);
Blynk.virtualWrite(V0, temperature);
Blynk.virtualWrite(V1, turb);
Blynk.virtualWrite(V2, ph);
Blynk.virtualWrite(V3, tds);
}
and this is with lcd (not running or display in lcd )
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID ""
#define BLYNK_TEMPLATE_NAME ""
#define BLYNK_AUTH_TOKEN ""
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <LiquidCrystal_I2C.h>
// Your WiFi credentials.
// Set password to "" for open networks.
const char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "";
char pass[] = "";
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600
OneWire oneWire(4); // Pin 2 is used for the OneWire interface
DallasTemperature sensors(&oneWire); // Pass the OneWire reference to DallasTemperature library
LiquidCrystal_I2C lcd(0x27, 20, 4); // I2C address may vary, adjust as necessary
ESP8266 wifi(&EspSerial);
float calibration_value = 22.85;
int phval = 0;
unsigned long int avgval;
int buffer_arr[10], temp;
int temperature;
int turb ;
float ph ;
int tds ;
const int tdsPin = A1; // Analog input pin for TDS sensor
BlynkTimer timer;
void setup() {
// Debug console
Serial.begin(9600);
delay(10);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(BLYNK_AUTH_TOKEN, wifi, ssid, pass);
timer.setInterval(1000L, getSendData);
Lcd();
}
void Lcd() {
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
}
void loop() {
Blynk.run();
timer.run();
}
void getSendData(){
// Temperature
sensors.requestTemperatures(); // Request temperature readings from the sensor
float temperature = sensors.getTempCByIndex(0); // Get the temperature in Celsius
// Turbidity
int turbidity = analogRead(A2);
float turb = turbidity * (5.0 / 1024.0) * 3;
// pH
for (int i = 0; i < 10; i++) {
buffer_arr[i] = analogRead(A0);
}
for (int i = 0; i < 9; i++) {
for (int j = i + 1; j < 10; j++) {
if (buffer_arr[i] > buffer_arr[j]) {
temp = buffer_arr[i];
buffer_arr[i] = buffer_arr[j];
buffer_arr[j] = temp;
}
}
}
avgval = 0;
for (int i = 2; i < 8; i++) {
avgval += buffer_arr[i];
}
float volt = (float)avgval * 5.0 / 1024 / 6;
ph = -5.70 * volt + calibration_value;
int tdsValue = analogRead(tdsPin);
float voltage2 = tdsValue * (5.0 / 1024.0);
float tds = voltage2 * 1000; // Convert to TDS value (adjust the conversion factor as per your sensor)
lcd.setCursor(0, 0);
lcd.print("checking ");
Serial.print("temp: ");
Serial.println(temperature);
Serial.print("turb: ");
Serial.println(turb);
Serial.print("ph: ");
Serial.println(ph);
Serial.print("tds: ");
Serial.println(tds);
Blynk.virtualWrite(V0, temperature);
Blynk.virtualWrite(V1, turb);
Blynk.virtualWrite(V2, ph);
Blynk.virtualWrite(V3, tds);
}