Professional Documents
Culture Documents
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
WidgetLED led1(V11); //GEN 1 LED
WidgetLED led2(V8); //GEN 2 LED
WidgetLED led3(V9); //MAINS LED
WidgetLED led4(V10); //LOAD LED
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
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(V5, h);
Blynk.virtualWrite(V6, t);
}
void setup()
{
pinMode(14, INPUT_PULLUP); //gen 1
pinMode(5, INPUT_PULLUP); //gen 2
pinMode(4, INPUT_PULLUP); //mains
pinMode(13, INPUT_PULLUP); //load on
pinMode(A0, INPUT); //VOLTAGE
dht.begin();
}
void checkPin()
{
if (digitalRead(14)) // D0 GEN SET 1
{ led1.off();
} else {
led1.on();
}}
void checkPin1()
{
if (digitalRead(5)) // D1 GEN SET 2
{ led2.off();
} else {
led2.on();
}}
void checkPin2()
{
if (digitalRead(4)) // d2 mains
{ led3.off();
} else {
led3.on();
}}
void checkPin3()
{
if (digitalRead(13)) // d3 load
{ led4.off();
} else {
led4.on();
}}
void checkPin4()
{
int analog_val=analogRead(A0); // read the value of analog pin A0 and
store it in the variable analog_val
temp = (analog_val * 5.0)/1024.0;
vin = temp/(r2/(r1+r2));
Blynk.virtualWrite(V4, vin);}
void loop()
{
checkPin();
checkPin1();
checkPin2();
checkPin3();
checkPin4();
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates SimpleTimer