I have been using custom ESP32 dev boards with multiple fans, AC outs and in etc. Everything was working nicely but the latest 2 boards (identcal to previous boards) the fans will not spin.
Even using test code below, the fans moan when theyre meant to spin but wont actually move.
#define fan1 27
#define fan2 14
#define fan3 12
void setup() {
Serial.begin(115200);
pinMode(fan1, OUTPUT);
pinMode(fan2, OUTPUT);
pinMode(fan3, OUTPUT);
}
void loop() {
Serial.println("Fans ON");
digitalWrite(fan1, 1);
digitalWrite(fan2, 1);
digitalWrite(fan3, 1);
delay(5000);
Serial.println("Fans ON");
digitalWrite(fan1, 0);
digitalWrite(fan2, 0);
digitalWrite(fan3, 0);
delay(5000);
}
I have been working with a guy who has basically done all the deign work etc and coding and he's lost as to why the fans now wont spin.
Any got any ideas?
The Original code that's been working for over a year.
// Board : ESP32 Dev Module
// v.3.2
// Pump runs for 20 seconds every 2.5 hours then turns off.
const int pumpOnTime = 20; // Pump on time in seconds
const int pumpInterval = 9000; // pump running interval
// Fan 1 runs permanently at 100%
const int fanPower = 100; // fan power in percentage
// Fan 2 turns on at 55% humidity and turns off at 46% humidity
const int humidityHigh = 55; // humidity high value
const int humidityLow = 46; // humidity low value
// Fan 3 turns on at 30c and turns off at 25c
const int tempHigh = 30; // temperature high value
const int tempLow = 25; // temperature low value
// AC out Times (24h format)
const int acOnTime = 420; // 07:00 = 7*60 + 30 = 420
const int acOffTime = 1230; // 20:30 = 20*60 + 30 = 1230
// relay timers [in seconds]
//const int relayOnTime = 14 * 3600;
//const int relayOffTime = 10 * 3600;
#include <Wire.h>
#include <RTClib.h>
#include <Adafruit_SHT31.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
Adafruit_SHT31 sht31 = Adafruit_SHT31();
RTC_DS3231 rtc;
#define pump 23
#define relay 19
#define sw 5
#define dt 17
#define clk 16
#define fan1 27
#define fan2 14
#define fan3 12
// other variables
const int ledfreq = 5000;
const int resolution = 8;
const int fan1Channel = 4;
int lastClk = 1;
int count = 0;
unsigned long timeNow = 0;
bool toggle = false;
bool pumpOnDelay = false;
void setup() {
delay(2000);
Serial.begin(115200);
Serial.println("Booting...");
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1) delay(10);
}
oled.clearDisplay();
oled.setTextColor(WHITE);
oled.setTextSize(1);
oled.setCursor(0, 0);
oled.println("Welcome to....");
oled.display();
delay(4000);
if (!sht31.begin(0x44)) { // Set to 0x45 for alternate i2c addr
Serial.println("Couldn't find SHT31");
while (1) delay(10);
}
sht31.heater(false);
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1) delay(10);
}
if (rtc.lostPower()) {
Serial.begin(115200);
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1) delay(10);
}
if (rtc.lostPower()) {
Serial.println("RTC is NOT running, let's set the time!");
// When time needs to be set on a new device, or after a power loss, the
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 8, 2024 at 9:51 you would call:
// rtc.adjust(DateTime(2024, 1, 8, 21, 51, 0));
}
}
pinMode(pump, OUTPUT);
pinMode(relay, OUTPUT);
pinMode(sw, INPUT_PULLUP);
pinMode(dt, INPUT);
pinMode(clk, INPUT);
pinMode(fan1, OUTPUT);
pinMode(fan2, OUTPUT);
pinMode(fan3, OUTPUT);
digitalWrite(pump, 0);
digitalWrite(relay, 0);
digitalWrite(fan1, 1);
digitalWrite(fan2, 0);
digitalWrite(fan3, 0);
}
unsigned int timeCounter = 0;
uint64_t timeCounter2 = 0;
float t = 0, h = 0;
void loop() {
if (millis() - timeNow > 3000) {
timeNow = millis();
timeCounter += 3;
if (timeCounter >= pumpInterval) timeCounter = 0;
/*
timeCounter2 += 3;
if (timeCounter2 < relayOnTime) {
digitalWrite(relay, 1);
} else if (timeCounter2 < relayOnTime + relayOffTime) {
digitalWrite(relay, 0);
} else
timeCounter2 = 0;
*/
DateTime now = rtc.now();
Serial.println(String("DateTime : ") + now.timestamp(DateTime::TIMESTAMP_FULL));
int nowTime = (now.hour() * 60) + now.minute();
Serial.println("Formatted Time : " + String(nowTime));
if (acOffTime > acOnTime) {
if (nowTime >= acOnTime && nowTime < acOffTime) {
digitalWrite(relay, 1);
}
if (nowTime > acOffTime) {
digitalWrite(relay, 0);
}
}
t = sht31.readTemperature();
h = sht31.readHumidity();
if (!isnan(t)) {
Serial.print("Temp *C = ");
Serial.print(t);
Serial.print("\t\t");
} else {
t = -1;
Serial.println("Failed to read temperature");
}
if (!isnan(h)) {
Serial.print("Hum. % = ");
Serial.println(h);
} else {
h = -1;
Serial.println("Failed to read humidity");
}
oled.clearDisplay();
oled.setTextSize(1);
oled.setCursor(5, 5);
oled.println("Temperature:");
oled.setCursor(5, 18);
oled.print(t);
oled.print((char)247);
oled.println("C");
oled.setCursor(5, 35);
oled.println("Humidity:");
oled.setCursor(5, 48);
oled.print(h);
oled.println("%");
oled.setTextSize(3);
oled.setCursor(95, 5);
oled.println("A");
oled.setCursor(95, 35);
oled.println("V");
oled.display();
if (millis() > 1000) {
pumpOnDelay = true;
}
if (pumpOnDelay) {
if (timeCounter > 0 && timeCounter <= pumpOnTime) {
digitalWrite(pump, 1);
} else {
digitalWrite(pump, 0);
}
}
if (h > humidityHigh) {
digitalWrite(fan2, 1);
}
if (h < humidityLow) {
digitalWrite(fan2, 0);
}
if (t > tempHigh) {
digitalWrite(fan3, 1);
}
if (t < tempLow) {
digitalWrite(fan3, 0);
}
}
}