Hi guys!
I have made a program for an indoor gardening project that runs on an ESP32.
Among other things, the program is supposed to run a ventilation fan when temperature or humidity readings are at certain levels. This is done with pwm and is either 0V (off), a percentage of the 12V, or 12V.
The system has one 3-way switch that when in mode 1 is set up for mushroom growing, in mode 2 is set up for greens growing, and in mode 0 is waiting for switch change.
My problem however is that the fan only runs if the switch is set to either mode 1 or 2 when the power started. And then if I use the switch to change mode, the fan stops and doesn't resume. It's not the fan, the ESP32 just doesn't output the pwm signal any more...
I'm hoping someone here can see what the cause could be?
I've been at this since this morning and am starting to loose my mind
Code below:
#include <DHT.h>
#include <TimeLib.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts/FreeMono9pt7b.h>
#include <NewPing.h>
#include <WiFi.h>
#include <ESPmDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <time.h>
....
prevbutton = 0;
digitalWrite(moist_pin, LOW);
digitalWrite(mushlight_pin, LOW);
digitalWrite(growlight_pin, LOW);
digitalWrite(pump_pin, LOW);
digitalWrite(fan_pin, LOW);
analogWrite(pwm_pin, 0);
ismoisting = 0;
isfaning = 0;
last_measureday = 0;
plantmeasure_before = 0;
plant_measure = 0;
}
// Running oxgenating function regardless of mode setting since it's important to keep water/nutrientsolution fresh
OxygenTimer(now_minute);
if (now_second != last_second) {
last_second = now_second;
loopTime = millis();
}
}
Thanks!