Okay here is the code I am using,
- I changed the wifi router, it still gives the same result.
- I am trying connecting to the blynk cloud server.
- I am using the latest app version on andriod(6.0.1), Note 5.
- I am using DHT 22 sensor, 6 channel relay, ESP8266 and Arduino Uno.
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG
#include <SPI.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h> // include Blynk ESP8266
#include <SimpleTimer.h>
#include <DHT.h>
char auth[] = "19b*****************";
char ssid[] = "K********";
char pass[] = "**********";
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // ( RX, TX )
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
#define DHTPIN 4 // What digital pin we're connected to
#define DHTTYPE DHT22 // DHT 22
DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;
//Relay in Pin XX
#define Relay1 10
#define Relay2 9
#define Relay3 8
#define Relay4 7
#define Relay5 6
#define Relay6 5
// in Blynk app writes values to the Virtual Pin 1
BLYNK_WRITE(V1)
{
int RelayStatus1 = param.asInt();
if (RelayStatus1 == 1) {
digitalWrite(Relay1, LOW);
}
else {
digitalWrite(Relay1, HIGH);
}
}
BLYNK_WRITE(V2)
{
int RelayStatus2 = param.asInt();
if (RelayStatus2 == 1) {
digitalWrite(Relay2, LOW);
}
else {
digitalWrite(Relay2, HIGH);
}
}
BLYNK_WRITE(V3)
{
int RelayStatus3 = param.asInt();
if (RelayStatus3 == 1) {
digitalWrite(Relay3, LOW);
}
else {
digitalWrite(Relay3, HIGH);
}
}
BLYNK_WRITE(V4)
{
int RelayStatus4 = param.asInt();
if (RelayStatus4 == 1) {
digitalWrite(Relay4, LOW);
}
else {
digitalWrite(Relay4, HIGH);
}
}
BLYNK_WRITE(V5)
{
int RelayStatus5 = param.asInt();
if (RelayStatus5 == 1) {
digitalWrite(Relay5, LOW);
}
else {
digitalWrite(Relay5, HIGH);
}
}
BLYNK_WRITE(V6)
{
int RelayStatus6 = param.asInt();
if (RelayStatus6 == 1) {
digitalWrite(Relay6, LOW);
}
else {
digitalWrite(Relay6, HIGH);
}
}
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V8, h);
Blynk.virtualWrite(V7, t);
}
void setup()
{
pinMode(Relay1, OUTPUT); // sets the digital pin as output
digitalWrite(Relay1, HIGH); // Prevents relays from starting up engaged
pinMode(Relay2, OUTPUT); // sets the digital pin as output
digitalWrite(Relay2, HIGH); // Prevents relays from starting up engaged
pinMode(Relay3, OUTPUT); // sets the digital pin as output
digitalWrite(Relay3, HIGH); // Prevents relays from starting up engaged
pinMode(Relay4, OUTPUT); // sets the digital pin as output
digitalWrite(Relay4, HIGH); // Prevents relays from starting up engaged
pinMode(Relay5, OUTPUT); // sets the digital pin as output
digitalWrite(Relay5, HIGH); // Prevents relays from starting up engaged
pinMode(Relay6, OUTPUT); // sets the digital pin as output
digitalWrite(Relay6, HIGH); // Prevents relays from starting up engaged
// communication with the host computer
Serial.begin(9600);
delay(10);
// Set ESP8266 baud rate
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
delay(10);
dht.begin();
// Setup a function to be called every 5 second
timer.setInterval(5000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates SimpleTimer
}