Fans not spinning on ESP32 but were?

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);
    }
  }
}

What Esp32 board?
What fans?
How are they powered/wired?

Its a custom PCB using ESP32-WROOM-32E(4MB). The fans are PC fans and they are powered by relays on the board.

What relays?
And how the relays are wired...?
What's the power supply for fans? Is it sufficient for 3 fans? Likely not.

Until we see a schematic, there's no point in speculation.

1 Like

But it's irresistible. :expressionless:

@nickos1 nice idea with the test sketch.

May we assume you have confirmed the output at the microprocessor pin, seen the same logic level at the relay controller, checked that the relay is switching and used known-good fans supplied by adequate power?

I am willing g to speculate based on your assertions that imply the circuit is the same and further that the bad boards are being deployed in identical fashion to boards that work…

a7

1 Like

I can't upload a schematic attachement as im a new user, so it's here Schematic (1) copy.pdf - Google Drive

Relay switching fine, tbh everything worked fine for almost 6 months then nada.
I also tried a brand new board thinking a component went bad on the older PCB but that doesn't work either. I'm using IDE, update fudged something maybe?

I do not see any relays shown on the schematic. Also what is the make and model of the fan, posting a link will help.

Could be that research now have such relays... but I don't think so. What powers the fans? Have you tried a different PSU? When the relays engage, is there a distinct click and did you measure that the output from the relays are ok?

They are SRD-05VDC-SL-C, I uploaded the wrong schematic. Link updated

Link updated to correct schematic, clicking definitely happening. Output from them is fine.

Looking at your second schematic it appears you are driving the fans with an N-Channel MOSFET (SI2302DS), there is no relay. You can carefully short source to drain and the fans should take of full speed. Same thing if you ground pin 1 of the connector.

If you connect the fans to 12 V direct, they work? Are they 3 or 4 pin / wire?

I'll test them tomorrow and see but I also tried brand new fans. The fans are just UpHere 120mm PC fans. 3 wire versions.

You seem to be confused as to how your custom PCB works.
The fans are controlled by MOSFETs not relays. If you are hearing the relays click when using your test code then there is something drastically wrong with the PCB.

Sound effect, like in modern cars, no turn signal relay but yet you hear it?

Yes sorry, the relays are for 2 other AC powered items, the mosfet are powering the fans. The clicks are audible when the PCB are in operation NOT with the test code.

No just me ssaying the wrong thing. I'm not a PCB designer or even have any idea how these things work hence why i'm here.

Why didn't you go to the designer? Sounds odd to me that you chose to get support from a forum run by volunteers for some commercial (at least it sound that way) solution.

1 Like

Well that clears up some confusion.
Are the MOSFETs used on the new PCBs the same as the old ones or were substitutes made.