You are on page 1of 3

#define BLYNK_PRINT Serial // Comment this out to disable prints and save space

#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

int inPinVal ; // Virtual Pin Input


float vin=0.0;
float temp=0.0;
float r1=36000.0; // Set the value of resister R1
float r2=1500.0; // Set the value of resister R2
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "eb9f5a13195d424ca27459bbe1845402";//u22 RMS

// Your WiFi credentials.


// Set password to "" for open networks.
char ssid[] = "electrical";
char pass[] = "014272900ntc";

#define DHTPIN 2 // What digital pin we're connected to

// Uncomment whatever type you're using!


#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21 // DHT 21, AM2301

DHT dht(DHTPIN, DHTTYPE);


SimpleTimer timer;
// Set the value of resister R2

// 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

Serial.begin(9600); // See the connection status in Serial Monitor


Blynk.begin(auth, ssid, pass);

dht.begin();

// Setup a function to be called every second


timer.setInterval(1000L, sendSensor);

}
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

You might also like