My garage light do not turn off

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(){
  Blynk.begin(auth, ssid, pass);
  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.print("WiFi Status: ");
Serial.println("NOT connected...");

void magnetSensor(){
  magnetValue = digitalRead(magnet);
  if(magnetValue == 1){
    digitalWrite(relay, LOW);
    digitalWrite(relay, HIGH);
void TempReading(){
  Blynk.virtualWrite(V3, tempSensor.getTempCByIndex(0));
void loop() {;;

I don't see anything wrong with the code. I assume you have a wiring issue.

Thanks for fast reply :slight_smile:

What about the pins that i use? Can Pin 13 and pin 5 have som interference with the Wifi?

It is an ESP32 board i'm using.

I read this on

The ESP32 integrates two 12-bit SAR (Successive Approximation Register) ADCs supporting a total of 18 measurement channels (analog enabled pins).

The ADC driver API supports ADC1 (8 channels, attached to GPIOs 32 - 39), and ADC2 (10 channels, attached to GPIOs 0, 2, 4, 12 - 15 and 25 - 27). However, the usage of ADC2 has some restrictions for the application:

ADC2 is used by the Wi-Fi driver. Therefore the application can only use ADC2 when the Wi-Fi driver has not started.
Some of the ADC2 pins are used as strapping pins (GPIO 0, 2, 15) thus cannot be used freely.

From that, it looks as though 13 is a potential problem. Try 16 instead?

From that, it looks as though 13 is a potential problem. Try 16 instead?

Yes, it does. I had hoped that it was a code problem, but i see now that i probably have to rewire the pin 13 to another pin that is not an ADC2 pin.
I will try that.