Briefcase on my issue faced:
Below are my project code drafted by me, the the system is to basically detect seismic vibration and the temperature and push notifications using the Blynk IOT app. Before implementing and adding Blynk Wifi connection code, the code was running fine and being projected in the Serial Monitor. After adding the Wifi codes, the serial monitor is being projected with the Wifi Ping and connection status only and the circuit was not working at all. Can i know anyway to solve this issue?
Original Project Code:
#define RED_LED_PIN 5
#define GREEN_LED_PIN 6
#define BUZZER_PIN 4
#include "DHT.h"
#define DHT22_PIN 3
DHT dht22(DHT22_PIN, DHT22);
int Vibration_signal = 7; //Define the Digital Input on the Arduino for the sensor signal
int Sensor_State = 1;
int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value
void setup() {
pinMode(RED_LED_PIN, OUTPUT);
pinMode(GREEN_LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(Vibration_signal, INPUT); //Set pin as input
Serial.begin(9600); // Start the serial communication
dht22.begin();
}
void loop() {
// read humidity
float humi = dht22.readHumidity();
// read temperature as Celsius
float tempC = dht22.readTemperature();
// read temperature as Fahrenheit
float tempF = dht22.readTemperature(true);
Serial.println("===========================================================");
Serial.print("Earthquake status : ");
Sensor_State = digitalRead(Vibration_signal);
if (Sensor_State == 1) {
Serial.println("Seismic Activity Detected!");
digitalWrite(RED_LED_PIN, HIGH);
digitalWrite(GREEN_LED_PIN, LOW);
tone(BUZZER_PIN, 1500);
delay(1000);
}
else {
Serial.println("No Seismic Activity");
digitalWrite(GREEN_LED_PIN, HIGH);
digitalWrite(RED_LED_PIN, LOW);
noTone(BUZZER_PIN);
delay(500);
}
delay(50);
Serial.print("Environment status: ");
if (tempC >= 35 && tempC < 40) {
Serial.println("High Temperature Warning!");
digitalWrite(RED_LED_PIN, HIGH);
digitalWrite(GREEN_LED_PIN, LOW);
tone(BUZZER_PIN, 1500);
delay(1000);
}
else if (tempC >= 40 ) {
Serial.println("Heat Wave Alert!");
digitalWrite(RED_LED_PIN, HIGH);
digitalWrite(GREEN_LED_PIN, LOW);
tone(BUZZER_PIN, 1500);
delay(1000);
}
else {
Serial.println("Normal");
digitalWrite(GREEN_LED_PIN, HIGH);
digitalWrite(RED_LED_PIN, LOW);
noTone(BUZZER_PIN);
delay(500);
}
delay(50);
if (isnan(humi) || isnan(tempC) || isnan(tempF)) {
Serial.println("Failed to read from DHT22 sensor!");
} else {
Serial.print("Humidity: ");
Serial.print(humi);
Serial.print("%");
Serial.print(" | ");
Serial.print("Temperature: ");
Serial.print(tempC);
Serial.print("°C ~ ");
Serial.print(tempF);
Serial.println("°F");
}
delay(50);
}
Project Code after adding Blynk WiFi Config:
#define RED_LED_PIN 5
#define GREEN_LED_PIN 6
#define BUZZER_PIN 4
#define BLYNK_TEMPLATE_ID "-"
#define BLYNK_TEMPLATE_NAME "-"
#define BLYNK_AUTH_TOKEN "-"
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include "DHT.h"
#define DHT22_PIN 3
DHT dht22(DHT22_PIN, DHT22);
int Vibration_signal = 7; //Define the Digital Input on the Arduino for the sensor signal
int Sensor_State = 1;
int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value
char auth[] = "-";
char ssid[] = "-";
char pass[] = "-";
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
void setup() {
Serial.begin(9600);
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
pinMode(RED_LED_PIN, OUTPUT);
pinMode(GREEN_LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(Vibration_signal, INPUT); //Set pin as input
Serial.begin(9600); // Start the serial communication
dht22.begin();
delay(10);
}
void loop() {
Blynk.run();
// read humidity
float humi = dht22.readHumidity();
// read temperature as Celsius
float tempC = dht22.readTemperature();
// read temperature as Fahrenheit
float tempF = dht22.readTemperature(true);
Serial.println("===========================================================");
Serial.print("Earthquake status : ");
Sensor_State = digitalRead(Vibration_signal);
if (Sensor_State == 1) {
Serial.println("Seismic Activity Detected!");
digitalWrite(RED_LED_PIN, HIGH);
digitalWrite(GREEN_LED_PIN, LOW);
tone(BUZZER_PIN, 1500);
Blynk.logEvent("earthquake_alert");
delay(1000);
}
else {
Serial.println("No Seismic Activity");
digitalWrite(GREEN_LED_PIN, HIGH);
digitalWrite(RED_LED_PIN, LOW);
noTone(BUZZER_PIN);
delay(500);
}
delay(50);
Serial.print("Environment status: ");
if (tempC >= 35 && tempC < 40) {
Serial.println("High Temperature Warning!");
digitalWrite(RED_LED_PIN, HIGH);
digitalWrite(GREEN_LED_PIN, LOW);
tone(BUZZER_PIN, 1500);
Blynk.logEvent("high_temperature_warning");
delay(1000);
}
else if (tempC >= 40 ) {
Serial.println("Heat Wave Alert!");
digitalWrite(RED_LED_PIN, HIGH);
digitalWrite(GREEN_LED_PIN, LOW);
tone(BUZZER_PIN, 1500);
Blynk.logEvent("heat_wave_alert");
delay(1000);
}
else {
Serial.println("Normal");
digitalWrite(GREEN_LED_PIN, HIGH);
digitalWrite(RED_LED_PIN, LOW);
noTone(BUZZER_PIN);
delay(500);
}
delay(50);
// check if any reads failed
if (isnan(humi) || isnan(tempC) || isnan(tempF)) {
Serial.println("Failed to read from DHT22 sensor!");
} else {
Serial.print("Humidity: ");
Serial.print(humi);
Serial.print("%");
Serial.print(" | ");
Serial.print("Temperature: ");
Serial.print(tempC);
Serial.print("°C ~ ");
Serial.print(tempF);
Serial.println("°F");
}
delay(50);
}