In about 16 weeks ago i finnished my Blynk code and Garasje project. I have som trouble with my Wifi, but i think this have to do with the temperature since my socket wifi extender is not rated for minus degrees.
But my main problem is that my garage light do not always turns off when i close the garage door. Sometimes it does, but not always.
I have an own microcontroller that takes care of that. My port opener is an separate controller and that works fine.
I just wonder if someone in here can see something in the code under that prevents the light (relay) turn off when i close the garage door?
The only reason for the Blynk connection is the temperature meassurement.
#include "OneWire.h"
#include "DallasTemperature.h"
OneWire oneWire(22);
DallasTemperature tempSensor(&oneWire);
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
int relay = 13;
int magnet = 5;
int magnetValue;
//WiFi and token data------------------------------------------
char auth[] = "*****";
char ssid[] = "*****";
char pass[] = "*****";
//-------------------------------------------------------------
BlynkTimer timer;
void setup(){
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
tempSensor.begin();
digitalWrite(relay, HIGH);
pinMode(relay, OUTPUT);
timer.setInterval(10000L, TempReading);
timer.setInterval(1000L, magnetSensor);
timer.setInterval(60000L, WiFiCheck);
}
void WiFiCheck(){
if(WiFi.status() == WL_CONNECTED){
Serial.print("WiFi Status: ");
Serial.println("Connected!");
}
else{
WiFi.reconnect();
Serial.print("WiFi Status: ");
Serial.println("NOT connected...");
}
}
void magnetSensor(){
magnetValue = digitalRead(magnet);
if(magnetValue == 1){
digitalWrite(relay, LOW);
}
else{
digitalWrite(relay, HIGH);
}
}
void TempReading(){
tempSensor.requestTemperaturesByIndex(0);
Blynk.virtualWrite(V3, tempSensor.getTempCByIndex(0));
}
void loop() {
Blynk.run();
timer.run();
}