Hello could you help me show the issue in this project the blynk does not show the values in my blynk app. Please help me thank you
Source code:
#define BLYNK_TEMPLATE_NAME "*****"
#define BLYNK_AUTH_TOKEN "*****"
#define BLYNK_PRINT Serial
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <RTClib.h>
#include <DHT.h>
// Your WiFi credentials.
char auth[] = "usBPpIFvpjSjO3K3rbizTQx6SqvZ-WU3";
char ssid[] = "Paulene";
char pass[] = "four_eyes";
// Define pins for sensors
#define PH_SENSOR_PIN A0
#define IR_SENSOR_PIN 5
#define TOUCH_SENSOR_PIN 4
#define ULTRASONIC_TRIG_PIN 8
#define ULTRASONIC_ECHO_PIN 7
#define FAN_PIN 9
// DHT and RTC Sensor
#define DHTPIN 6
#define DHTTYPE DHT22
RTC_DS3231 rtc;
DHT dht(DHTPIN, DHTTYPE);
// Adafruit PWM Servo Driver
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// Servo channel definitions
#define WATER_SERVO_CHANNEL 0
#define FOOD_SERVO_CHANNEL 2
#define SANITATION_SERVO_CHANNEL1 4
#define SANITATION_SERVO_CHANNEL2 6
#define DOOR_SERVO_CHANNEL1 8
#define DOOR_SERVO_CHANNEL2 10
#define DOOR_SERVO_CHANNEL3 12
// Software Serial for ESP8266
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
// Your ESP8266 baud rate
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
// Routine times set by user
int waterHours[3] = {-1, -1, -1};
int waterMinutes[3] = {-1, -1, -1};
int foodHours[3] = {-1, -1, -1};
int foodMinutes[3] = {-1, -1, -1};
int sanitationHours[3] = {-1, -1, -1};
int sanitationMinutes[3] = {-1, -1, -1};
// Water calibration
float calibration_value = 21.34 + 0.7;
unsigned long int avgValue;
int buf[10], temp;
// Function to convert degrees to pulse length
int convertDegToPulse(int deg) {
int pulse = map(deg, 0, 180, 150, 600); // 150-600 corresponds to the 1-2ms pulse width
return pulse;
}
// Functions for servo actions
void moveServo(int channel, int position) {
int pulse = convertDegToPulse(position);
pwm.setPWM(channel, 0, pulse);
}
void dipSensor() {
moveServo(WATER_SERVO_CHANNEL, 90); // dip the pH sensor
delay(5000); // Allow time for the sensor to stabilize in water
moveServo(WATER_SERVO_CHANNEL, 0);
}
void waterRoutine() {
dipSensor();
delay(5000); // Allow time for the sensor to stabilize in water (adjust as needed)
// Read pH value
avgValue = 0;
for (int i = 0; i < 10; i++) { // Get 10 sample values from the sensor for smoothing
buf[i] = analogRead(PH_SENSOR_PIN);
delay(10);
}
for (int i = 0; i < 9; i++) { // Sort the analog values from small to large
for (int j = i + 1; j < 10; j++) {
if (buf[i] > buf[j]) {
temp = buf[i];
buf[i] = buf[j];
buf[j] = temp;
}
}
}
for (int i = 2; i < 8; i++) avgValue += buf[i]; // Take the average value of 6 center samples
float phValue = (float)avgValue * 5.0 / 1024 / 6; // Convert the analog value into millivolts
phValue = -5.70 * phValue + calibration_value; // Convert the millivolts into pH value
// Serial.print("pH Value: ");
// Serial.println(phValue, 2); // Print pH value with 2 decimal places
String phStatus;
// Determine acidity level
if (phValue < 6.9) {
Serial.println("Acidic");
} else if (phValue > 7) {
Serial.println("Neutral");
} else if (phValue > 7.1) {
Serial.println("Alkaline");
} else{
}
// Create a single string for pH value and status
String phValueAndStatus = String(phValue, 2) + " " + phStatus;
// Print to Serial (optional)
Serial.println(phValueAndStatus);
// Send pH value and status to Blynk
Blynk.virtualWrite(V4, phValueAndStatus);
}
void checkFoodStatus() {
int irSensorValue = digitalRead(IR_SENSOR_PIN);
// IR sensor logic (adjust as per your sensor's behavior)
if (irSensorValue == LOW) {
Blynk.virtualWrite(V8, "Empty"); // Send status to Blynk
} else {
Blynk.virtualWrite(V8, "Available"); // Send status to Blynk
}
}
void readTouchSensor() {
int touchValue = digitalRead(TOUCH_SENSOR_PIN);
// Check if touch sensor is triggered (adjust condition based on sensor behavior)
if (touchValue == HIGH) {
foodRoutine(); // Call foodRoutine if touch sensor is triggered
delay(1000); // Add a delay to prevent rapid triggering
}
}
void foodRoutine() {
moveServo(FOOD_SERVO_CHANNEL, 180); // dispense food
delay(1000);
moveServo(FOOD_SERVO_CHANNEL, 0);
}
void sanitationRoutine() {
moveServo(SANITATION_SERVO_CHANNEL1, 180);
moveServo(SANITATION_SERVO_CHANNEL2, 180);
delay(1000);
moveServo(SANITATION_SERVO_CHANNEL1, 0);
moveServo(SANITATION_SERVO_CHANNEL2, 0);
}
void doorRoutine() {
moveServo(DOOR_SERVO_CHANNEL1, 90);
moveServo(DOOR_SERVO_CHANNEL2, 90);
moveServo(DOOR_SERVO_CHANNEL3, 90);
// Send door status to Blynk
Blynk.virtualWrite(V14, "Open");
delay(1000);
moveServo(DOOR_SERVO_CHANNEL1, 0);
moveServo(DOOR_SERVO_CHANNEL2, 0);
moveServo(DOOR_SERVO_CHANNEL3, 0);
// Send door status to Blynk
Blynk.virtualWrite(V14, "Close");
}
void fanControl(float temp) {
if (temp > 30.0) {
digitalWrite(FAN_PIN, HIGH);
} else {
digitalWrite(FAN_PIN, LOW);
}
}
void checkTime() {
DateTime now = rtc.now();
int hour = now.hour();
int minute = now.minute();
for (int i = 0; i < 3; i++) {
if (hour == waterHours[i] && minute == waterMinutes[i]) {
waterRoutine();
}
if (hour == foodHours[i] && minute == foodMinutes[i]) {
foodRoutine();
}
if (hour == sanitationHours[i] && minute == sanitationMinutes[i]) {
sanitationRoutine();
}
}
}
// Blynk handlers to set routine times
BLYNK_WRITE(V1) {
String time = param.asStr();
waterHours[0] = time.substring(0, 2).toInt();
waterMinutes[0] = time.substring(3, 5).toInt();
}
BLYNK_WRITE(V2) {
String time = param.asStr();
waterHours[1] = time.substring(0, 2).toInt();
waterMinutes[1] = time.substring(3, 5).toInt();
}
BLYNK_WRITE(V3) {
String time = param.asStr();
waterHours[2] = time.substring(0, 2).toInt();
waterMinutes[2] = time.substring(3, 5).toInt();
}
BLYNK_WRITE(V5) {
String time = param.asStr();
foodHours[0] = time.substring(0, 2).toInt();
foodMinutes[0] = time.substring(3, 5).toInt();
}
BLYNK_WRITE(V6) {
String time = param.asStr();
foodHours[1] = time.substring(0, 2).toInt();
foodMinutes[1] = time.substring(3, 5).toInt();
}
BLYNK_WRITE(V7) {
String time = param.asStr();
foodHours[2] = time.substring(0, 2).toInt();
foodMinutes[2] = time.substring(3, 5).toInt();
}
BLYNK_WRITE(V9) {
String time = param.asStr();
sanitationHours[0] = time.substring(0, 2).toInt();
sanitationMinutes[0] = time.substring(3, 5).toInt();
}
BLYNK_WRITE(V10) {
String time = param.asStr();
sanitationHours[1] = time.substring(0, 2).toInt();
sanitationMinutes[1] = time.substring(3, 5).toInt();
}
BLYNK_WRITE(V11) {
String time = param.asStr();
sanitationHours[2] = time.substring(0, 2).toInt();
sanitationMinutes[2] = time.substring(3, 5).toInt();
}
// Blynk Write Handlers for Servo
BLYNK_WRITE(V12) {
int value = param.asInt();
if (value == 1) {
sanitationRoutine();
}
}
BLYNK_WRITE(V13) {
int value = param.asInt();
if (value == 1) {
doorRoutine();
}
}
BLYNK_WRITE(V17) {
int value = param.asInt();
digitalWrite(FAN_PIN, value);
}
void setup() {
Serial.begin(9600);
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
pwm.begin();
pwm.setPWMFreq(60); // Analog servos run at ~60 Hz
Wire.begin();
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
pinMode(FAN_PIN, OUTPUT);
pinMode(ULTRASONIC_TRIG_PIN, OUTPUT);
pinMode(ULTRASONIC_ECHO_PIN, INPUT);
dht.begin();
rtc.begin();
}
void loop() {
Blynk.run();
double humidity = dht.readHumidity();
double temp = dht.readTemperature();
// Send temperature and humidity data to Blynk
Blynk.virtualWrite(V15, temp);
Blynk.virtualWrite(V16, humidity);
checkTime();
checkFoodStatus();
readTouchSensor();
fanControl(temp);
// Read distance from ultrasonic sensor
long duration, distance;
digitalWrite(ULTRASONIC_TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(ULTRASONIC_TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(ULTRASONIC_TRIG_PIN, LOW);
duration = pulseIn(ULTRASONIC_ECHO_PIN, HIGH);
distance = (duration / 2) / 29.1;
if (distance < 10) { // cat is detected
doorRoutine();
}
}```