Light control, gates, temperature monitoring

   //wemos d1 mini 
//SLOVAKIA
//Vladimir Minar  
//22.3.2017
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>
/********************************************/
#define ONE_WIRE_BUS 1//D1-GPIO1 TX  //DS18B20
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
/********************************************/
DeviceAddress tempSensor1 = { 0x28, 0x19, 0xAE, 0xB0, 0x01, 0x00, 0x00, 0x78 };//adres dallas DS18B20 TYPE
DeviceAddress tempSensor2 = { 0x28, 0xF9, 0x1E, 0xB1, 0x01, 0x00, 0x00, 0x91 };//adres dallas
DeviceAddress tempSensor3 = { 0x28, 0xFF, 0xBE, 0x02, 0x3E, 0x04, 0x00, 0xB3 };//adres dallas

int temperature1, temperature2, temperature3;
/******************************************************/
char auth[] = "XXX";
char ssid[]   = "XXX";
char pass[]   = "XXX";
/**************RELAY********************************/
const int relay1 = 15;//D8-GPIO15  relay1 gate1
const int relay2 = 12;//D6-GPIO12   relay2 gate2
const int relay3 = 14;//D5-GPIO14   relay3 light1
const int relay4 = 16;//D0-GPIO16   relay4 light2
/**************BUTTON************************/
const int button1 = 3;//GPIO3 RX  button1 gate1  monostabil
const int button2 = 0;//D3-GPIO0     button2 gate2  monostabil
const int button3 = 2;//D4-GPIO2     button3 light1  bistabil
const int button4 = 13;//D7-GPIO13   button3 light2  bistabil
/***************************************/
const int magneticswitches1 = 5;//D1-GPIO5 input button gnd /gate 1 open/magneticswitches
const int magneticswitches2 = 4;//D2-GPIO4 input button gnd /gate 2 open/magneticswitches1
/******************************/
SimpleTimer timer;
/*********************************/
void physicalbutton();  //physical button
/************************************/
int relaystate3 = LOW;  //relayState3
int relaystate4 = LOW;  //relayState4
/***************************************/
int buttonstate3 = HIGH;//buttonState3
int buttonstate4 = HIGH;//buttonState4
/***************************************/
WidgetLED led1(V5); // led  monostabil gate1
WidgetLED led2(V6);// led  monostabil gate2
//WidgetLED led3(V7);//light bistabil
//WidgetLED led4(V8);//light1  bistabil
WidgetLED led5(V9);//led online
WidgetLED led6(V10);////garage 1 open/
WidgetLED led7(V11);//garage 2 open/
/*******************************/
// temperature1 V12
// temperature2 V13
// temperature3 V14
WidgetLCD lcd(V15);
//VALUE DISPLAY online V16
//VALUE DISPLAY magneticswitches GATE V17
//VALUE DISPLAY magneticswitches GATE2 V18
/**********************************************/
boolean buttonstate1 = false;//button1  magneticswitches gate 1
boolean buttonstate2 = false;//button2  magneticswitches gate 2
/**************************************/
/******************input button gnd /garage  open**************/
void ledmagneticswitches1()
{ 
  boolean isPressed = (digitalRead(magneticswitches1) == LOW);  
  if (isPressed != buttonstate1) {
    if (isPressed) {
      led6.on();
          Blynk.virtualWrite(V17, "OPEN");      
    lcd.print(1, 0, "GARAGE     OPEN"); 
    Blynk.email("XXX@gmail.com", "GARAGE OPEN!", "Garage open.");
    } else {
      led6.off();
    Blynk.virtualWrite(V17, "CLOSE");      
    lcd.print(1, 0, "GARAGE    CLOSE");
    }
    buttonstate1 = isPressed;
  }
}
/********input button gnd garage 1 open*****************************/
void ledmagneticswitches2()
{  
  boolean isPressed = (digitalRead(magneticswitches2) == LOW);  
  if (isPressed != buttonstate2) {
    if (isPressed) {
      led7.on();
    Blynk.virtualWrite(V18, "OPEN");      
    lcd.print(1, 1, "GARAGE1    OPEN"); 
    Blynk.email("XXX@gmail.com", "GARAGE1 OPEN!", "Garage1 open.");
    } else {
      led7.off();
    Blynk.virtualWrite(V18, "CLOSE");      
    lcd.print(1, 1, "GARAGE1   CLOSE");      
    }
    buttonstate2 = isPressed;
  }
}
/*************************************************/
BLYNK_CONNECTED() {
  Blynk.syncVirtual(V1);
  Blynk.syncVirtual(V2);
  Blynk.syncVirtual(V3);
  Blynk.syncVirtual(V4);
}
/************MONOSTABIL push button android*************/
BLYNK_WRITE(V1) 
{
  if (param.asInt()) 
  {   
   digitalWrite(relay1, HIGH); 
   led1.on();
  } 
  else 
  {
  digitalWrite(relay1, LOW); 
  led1.off();
  }
}
/**********MONOSTABIL push button android*******************/
BLYNK_WRITE(V2) 
{
  if (param.asInt()) 
  {   
   digitalWrite(relay2, HIGH); 
   led2.on();
  } 
  else 
  {
  digitalWrite(relay2, LOW); 
  led2.off();
  }
}
/*****************BISTABIL  switch button android***************/
BLYNK_WRITE(V3) 
{
  if (param.asInt()) 
  {   
   digitalWrite(relay3, HIGH);       
  } 
  else 
  {
  digitalWrite(relay3, LOW);    
  }
}
  /**************BISTABIL switch button android**************/
BLYNK_WRITE(V4) 
{
  if (param.asInt())
  {   
   digitalWrite(relay4, HIGH);      
  } 
  else 
  {
  digitalWrite(relay4, LOW);  
  }
}
/**********MONOSTABIL***************/
void physicalbutton()
{
  int sensorVal = digitalRead(3);  
  Serial.println(sensorVal);
  if (sensorVal == HIGH) {
    digitalWrite(15, LOW);
    Blynk.virtualWrite(V1, LOW);
    led1.off();
  } else {
    digitalWrite(15, HIGH);
    Blynk.virtualWrite(V1, HIGH);
    led1.on();
  }
  /**********MONOSTABIL*************/
  int sensor1Val = digitalRead(0);  
  Serial.println(sensor1Val);
  if (sensor1Val == HIGH) {
    digitalWrite(12, LOW);
    Blynk.virtualWrite(V2, LOW);
    led2.off();
  } else {
    digitalWrite(12, HIGH);
    Blynk.virtualWrite(V2, HIGH);
    led2.on();
  }
  /**********BISTABIL**************/
  if (digitalRead(button3) == LOW) {
    if (buttonstate3 != LOW) {
      relaystate3 = !relaystate3;
      digitalWrite(relay3, relaystate3);
      Blynk.virtualWrite(V3, relaystate3);           
    }
    buttonstate3 = LOW;    
  } else {
    buttonstate3 = HIGH;        
  }
  /**********BISTABIL***************/
  if (digitalRead(button4) == LOW) {
    if (buttonstate4 != LOW) {
      relaystate4 = !relaystate4;
      digitalWrite(relay4, relaystate4);
      Blynk.virtualWrite(V4, relaystate4);           
    }
    buttonstate4 = LOW;         
  } else {
    buttonstate4 = HIGH;      
  }
}
/***ONLINE*************/
void ledonline()
{
  if (led5.getValue()) {
    led5.off();
    Serial.println("LED on V9: off");
    Blynk.virtualWrite(V16, "ERROR");
  } else {
    led5.on();
    Serial.println("LED on V9: on");
    Blynk.virtualWrite(V16, "ONLINE");
  }
}
/*****************************************/
void sendSensor1() {
  sensors.requestTemperatures();
  temperature1 = sensors.getTempC(tempSensor1);
  Blynk.virtualWrite(V12, temperature1);
}
void sendSensor2() {
  sensors.requestTemperatures();
  temperature2 = sensors.getTempC(tempSensor2);
  Blynk.virtualWrite(V13, temperature2);
}
void sendSensor3() {
  sensors.requestTemperatures();
  temperature3 = sensors.getTempC(tempSensor3);
  Blynk.virtualWrite(V14, temperature3);
}
/*****************************************/

void setup(){
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  ////////////////////////////////////////////
   Blynk.email("XXX@gmail.com", "online", "wemos d1 mini je  online.");
   /****************************************/
  pinMode(relay1, OUTPUT);//relay1
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);
  /**********************************/
  pinMode(button1, INPUT_PULLUP);//button1
  pinMode(button2, INPUT_PULLUP);
  pinMode(button3, INPUT_PULLUP);
  pinMode(button4, INPUT_PULLUP);
  /*************************************/
  digitalWrite(relay3, relaystate3);
  digitalWrite(relay4, relaystate4);
  /****************************************/
  pinMode(magneticswitches1, INPUT_PULLUP);//input button gnd /garage  open/
  pinMode(magneticswitches2, INPUT_PULLUP);//input button gnd /garage 1 open/
  //////////////////////////////////////////
  timer.setInterval(500L, ledmagneticswitches1);
  timer.setInterval(500L, ledmagneticswitches2);
  /*************************************************/
  timer.setInterval(1000L, physicalbutton);
  timer.setInterval(1000L, ledonline);
  /*******************************************/
  sensors.begin();
  sensors.setResolution(tempSensor1, 10);   
  sensors.setResolution(tempSensor2, 10);
  sensors.setResolution(tempSensor3, 10);
  /***************************************/
  timer.setInterval(5000L, sendSensor1);
  timer.setInterval(4800L, sendSensor2);
  timer.setInterval(4500L, sendSensor3);
}

void loop()
{
  Blynk.run();
  timer.run();
}
6 Likes

1 Like

What is this?

Garage Control temperature and light control

You should edit your first post and include more details about the project, otherwise this thread is kinda pointless and will just fall to the bottom.

Include a written description, links to reference, QR code of the clone Blynk project, and maybe a github repo.


//DS18B20  OTHERWISE
void readTemp()
{
  char t_buffer0[15];
  char t_buffer1[15];
  char t_buffer2[15];
  
  sensors.requestTemperatures();
  float floatTempC0 = sensors.getTempCByIndex(0);
  float floatTempC1 = sensors.getTempCByIndex(1);
  float floatTempC2 = sensors.getTempCByIndex(2);

  dtostrf(floatTempC0, 8, 9, t_buffer0);
  dtostrf(floatTempC1, 8, 9, t_buffer1);
  dtostrf(floatTempC2, 8, 9, t_buffer2);
  if(floatTempC0 != -127) Blynk.virtualWrite(V12, t_buffer0);
  if(floatTempC1 != -127) Blynk.virtualWrite(V13, t_buffer1);
  if(floatTempC2 != -127) Blynk.virtualWrite(V14, t_buffer2);   
}
    indent preformatted text by 4 spaces

More on resolutions:
http://www.homautomation.org/2015/11/17/ds18b20-how-to-change-resolution-9101112-bits/

push message

//6x temperatures

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>
/********************************************/
#define ONE_WIRE_BUS 1//D1-GPIO1 TX  //DS18B20
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
/********************************************/
DeviceAddress tempSensor1 = { 0x28, 0xB0, 0x68, 0x15, 0x06, 0x00, 0x00, 0x7E };//adres dallas DS18B20 TYPE
DeviceAddress tempSensor2 = { 0x28, 0x70, 0x6A, 0x15, 0x06, 0x00, 0x00, 0x52 };//adres dallas
DeviceAddress tempSensor3 = { 0x28, 0x2A, 0x30, 0x15, 0x06, 0x00, 0x00, 0x7B };//adres dallas
DeviceAddress tempSensor4 = { 0x28, 0x19, 0xAE, 0xB0, 0x01, 0x00, 0x00, 0x18 };//adres dallas DS18B20 TYPE
DeviceAddress tempSensor5 = { 0x28, 0x7F, 0xB8, 0xB0, 0x01, 0x00, 0x00, 0xE7 };//adres dallas
DeviceAddress tempSensor6 = { 0x28, 0xFF, 0xBE, 0x02, 0x3E, 0x04, 0x00, 0xB4 };//adres dallas

int temperature1, temperature2, temperature3, temperature4, temperature5, temperature6;
/******************************************************/
char auth[] = "xxx";
char ssid[]   = "xxx";
char pass[]   = "xxx";
/**************RELAY********************************/
const int relay1 = 15;//D8-GPIO15  relay1 gate1
const int relay2 = 12;//D6-GPIO12   relay2 gate2
const int relay3 = 14;//D5-GPIO14   relay3 light1
const int relay4 = 16;//D0-GPIO16   relay4 light2
/**************BUTTON************************/
const int button1 = 3;//GPIO3 RX  button1 gate1  monostabil
const int button2 = 0;//D3-GPIO0     button2 gate2  monostabil
const int button3 = 2;//D4-GPIO2     button3 light1  bistabil
const int button4 = 13;//D7-GPIO13   button3 light2  bistabil
/***************************************/
const int magneticswitches1 = 5;//D1-GPIO5 input button gnd /gate 1 open/magneticswitches
const int magneticswitches2 = 4;//D2-GPIO4 input button gnd /gate 2 open/magneticswitches1
/******************************/
SimpleTimer timer;
SimpleTimer timer1;
/*********************************/
void physicalbutton();  //physical button
/************************************/
int relaystate3 = LOW;  //relayState3
int relaystate4 = LOW;  //relayState4
/***************************************/
int buttonstate3 = HIGH;//buttonState3
int buttonstate4 = HIGH;//buttonState4
/***************************************/
WidgetLED led1(V5); // led  monostabil gate1
WidgetLED led2(V6);// led  monostabil gate2
WidgetLED led3(V7);//light bistabil
WidgetLED led4(V8);//light1  bistabil
WidgetLED led5(V9);//led online
WidgetLED led6(V10);////garage 1 open/
WidgetLED led7(V11);//garage 2 open/
/*******************************/
// temperature1 V12
// temperature2 V13
// temperature3 V14
// temperature1 V19
// temperature2 V20
// temperature3 V21
/************************/
WidgetLCD lcd(V15);
//VALUE DISPLAY online V16
//VALUE DISPLAY magneticswitches GATE V17
//VALUE DISPLAY magneticswitches GATE2 V18
/**********************************************/
boolean buttonstate1 = false;//button1  magneticswitches gate 1
boolean buttonstate2 = false;//button2  magneticswitches gate 2
/**************************************/


/******************input button gnd /garage  open**************/
void ledmagneticswitches1()
{
  boolean isPressed = (digitalRead(magneticswitches1) == LOW);
  if (isPressed != buttonstate1) {
    if (isPressed) {
      led6.on();
      lcd.print(1, 0, "BRANA  OTVORENA");
      Blynk.email("xxx@gmail.com", "BRANA OTVORENA!", "Brana je otvorena.");
    } else {
      led6.off();
      lcd.print(1, 0, "BRANA ZATVORENA");
    }
    buttonstate1 = isPressed;
  }
}
/********input button gnd garage 1 open*****************************/
void ledmagneticswitches2()
{
  boolean isPressed = (digitalRead(magneticswitches2) == LOW);
  if (isPressed != buttonstate2) {
    if (isPressed) {
      led7.on();
      lcd.print(1, 1, "GARAZ  OTVORENA");
      Blynk.email("xxx@gmail.com", "GARAZ OTVORENA!", "Garaz je otvorena.");
    } else {
      led7.off();
      lcd.print(1, 1, "GARAZ ZATVORENA");
    }
    buttonstate2 = isPressed;
  }
}
/*************************************************/
BLYNK_CONNECTED() {
  Blynk.syncVirtual(V1);
  Blynk.syncVirtual(V2);
  Blynk.syncVirtual(V3);
  Blynk.syncVirtual(V4);
}
/************MONOSTABIL push button android*************/
BLYNK_WRITE(V1)//tlacitko ide 1sekundu nezalezi na dlzke zatlacenia
{
  if (param.asInt()) {
    digitalWrite(relay1, HIGH);
    led1.on();
    delay(1000);
    digitalWrite(relay1, LOW);
    led1.off();
  }
}
/**********MONOSTABIL push button android*******************/
BLYNK_WRITE(V2)//tlacitko ide 1sekundu nezalezi na dlzke zatlacenia
{
  if (param.asInt()) {
    digitalWrite(relay2, HIGH);
    led2.on();
    delay(1000);
    digitalWrite(relay2, LOW);
    led2.off();
  }
}
/*****************BISTABIL  switch button android***************/
BLYNK_WRITE(V3) {
  relaystate3 = param.asInt();
  digitalWrite(relay3, relaystate3);
  if (digitalRead(relay3) == HIGH) {
    Blynk.virtualWrite(V17, "SVETLO ON");
    led3.on();
  }
  else {
    Blynk.virtualWrite(V17, "SVETLO OFF");
    led3.off();
  }
}
/**************BISTABIL switch button android**************/
BLYNK_WRITE(V4) {
  relaystate4 = param.asInt();
  digitalWrite(relay4, relaystate4);
  if (digitalRead(relay4) == HIGH) {
    Blynk.virtualWrite(V18, "SVETLO1 ON");
    led4.on();
  }
  else {
    Blynk.virtualWrite(V18, "SVETLO1 OFF");
    led4.off();
  }
}

/**********MONOSTABIL***************/
void physicalbutton()
{
  if (digitalRead(button1) == HIGH) {
    digitalWrite(relay1, LOW);
    Blynk.virtualWrite(V1, LOW);
    led1.off();
  } else {
    digitalWrite(relay1, HIGH);
    Blynk.virtualWrite(V1, HIGH);
    led1.on();
  }
  /**********MONOSTABIL*************/

  if (digitalRead(button2) == HIGH) {
    digitalWrite(relay2, LOW);
    Blynk.virtualWrite(V2, LOW);
    led2.off();
  } else {
    digitalWrite(relay2, HIGH);
    Blynk.virtualWrite(V2, HIGH);
    led2.on();
  }
  /**********BISTABIL**************/
  if (digitalRead(button3) == LOW) {
    if (buttonstate3 != LOW) {
      relaystate3 = !relaystate3;
      digitalWrite(relay3, relaystate3);
      Blynk.virtualWrite(V3, relaystate3);
      if (digitalRead(relay3) == HIGH) {
        Blynk.virtualWrite(V17, "SVETLO ON");
        led3.on();
      }
      else {
        Blynk.virtualWrite(V17, "SVETLO1 OFF");
        led3.off();
      }
    }
    buttonstate3 = LOW;

  } else {
    buttonstate3 = HIGH;

  }
  /**********BISTABIL***************/
  if (digitalRead(button4) == LOW) {
    if (buttonstate4 != LOW) {
      relaystate4 = !relaystate4;
      digitalWrite(relay4, relaystate4);
      Blynk.virtualWrite(V4, relaystate4);
      if (digitalRead(relay4) == HIGH) {
        Blynk.virtualWrite(V18, "SVETLO1 ON");
        led4.on();
      }
      else {
        Blynk.virtualWrite(V18, "SVETLO1 OFF");
        led4.off();
      }
    }
    buttonstate4 = LOW;

  } else {
    buttonstate4 = HIGH;
  }
}
/***ONLINE*************/
void ledonline()
{
  if (led5.getValue()) {
    led5.off();
    Serial.println("LED on V9: off");
    Blynk.virtualWrite(V16, "ERROR");
  } else {
    led5.on();
    Serial.println("LED on V9: on");
    Blynk.virtualWrite(V16, "ONLINE");
  }
}
/*****************************************/
void sendSensor1() {
  sensors.requestTemperatures();
  temperature1 = sensors.getTempC(tempSensor1);
  Blynk.virtualWrite(V12, temperature1);
}
void sendSensor2() {
  sensors.requestTemperatures();
  temperature2 = sensors.getTempC(tempSensor2);
  Blynk.virtualWrite(V13, temperature2);
}
void sendSensor3() {
  sensors.requestTemperatures();
  temperature3 = sensors.getTempC(tempSensor3);
  Blynk.virtualWrite(V14, temperature3);
}
void sendSensor4() {
  sensors.requestTemperatures();
  temperature4 = sensors.getTempC(tempSensor4);
  Blynk.virtualWrite(V19, temperature4);
}
void sendSensor5() {
  sensors.requestTemperatures();
  temperature5 = sensors.getTempC(tempSensor5);
  Blynk.virtualWrite(V20, temperature5);
}
void sendSensor6() {
  sensors.requestTemperatures();
  temperature6 = sensors.getTempC(tempSensor6);
  Blynk.virtualWrite(V21, temperature6);
}
/*****************************************/


void setup() {
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  ////////////////////////////////////////////
  // Blynk.email("xxx@gmail.com", "online", "wemos d1 mini je  online.");
  /****************************************/
  pinMode(relay1, OUTPUT);//relay1
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);
  /**********************************/
  pinMode(button1, INPUT_PULLUP);//button1
  pinMode(button2, INPUT_PULLUP);
  pinMode(button3, INPUT_PULLUP);
  pinMode(button4, INPUT_PULLUP);
  /*************************************/
  digitalWrite(relay1, LOW);
  digitalWrite(relay2, LOW);
  digitalWrite(relay3, relaystate3);
  digitalWrite(relay4, relaystate4);
  /****************************************/
  pinMode(magneticswitches1, INPUT_PULLUP);//input button gnd /garage  open/
  pinMode(magneticswitches2, INPUT_PULLUP);//input button gnd /garage 1 open/
  //////////////////////////////////////////
  timer.setInterval(500L, ledmagneticswitches1);
  timer.setInterval(500L, ledmagneticswitches2);
  /*************************************************/
  timer.setInterval(1000L, physicalbutton);
  timer.setInterval(1000L, ledonline);
  /*******************************************/
  sensors.begin();
  sensors.setResolution(tempSensor1, 10);   
  sensors.setResolution(tempSensor2, 10);
  sensors.setResolution(tempSensor3, 10);
  sensors.setResolution(tempSensor4, 10);   
  sensors.setResolution(tempSensor5, 10);
  sensors.setResolution(tempSensor6, 10);
  /***************************************/
  timer.setInterval(5000L, sendSensor1);
  timer.setInterval(4800L, sendSensor2);
  timer.setInterval(4500L, sendSensor3);
  timer1.setInterval(5000L, sendSensor4);
  timer1.setInterval(4800L, sendSensor5);
  timer1.setInterval(4500L, sendSensor6);
}
/********************************************/
void loop()
{
  Blynk.run();
  timer.run();
  timer1.run();
}

indent preformatted text by 4 spaces

Hello, thanks for the code and it works verry good. I wonder if it is possible to burn an external LED as soon as the magnetic switches (GPIO5 and 4) start working and as LED (V10 and V11) light up