ESP32 Exhaust Fan with SHT40, SSR-25DA and ACS712 - Proteus Simulation: the ESP32, the SHT40, the ACS712, the SSR-25DA and the 230 V fan

ESP32 Exhaust Fan with SHT40, SSR-25DA and ACS712 - Proteus Simulation

40
700
60
25
60
PCBWay

Hello friends, I hope you all are doing great. Today, I am going to share the ESP32 Exhaust Fan with SHT40, SSR-25DA and ACS712 - Proteus Simulation, the ninety-ninth project of our IoT Projects series. If you have searched for an ESP32 humidity-controlled fan, how to switch a 230 V load with a solid-state relay, how to measure AC current with an ACS712, or how to tell if a motor is really running, here is a complete one in a Proteus simulation. Switching a mains load from a microcontroller is easy; knowing that the load actually did what it was told is the part most projects leave out.

This project is a smart bathroom exhaust fan. An SHT40 sensor measures the humidity; when a shower pushes it past 70 %, the ESP32 switches the 230 V fan on through an SSR-25DA solid-state relay, and when the air is dry again it lets the fan run on for a while and stops it. An ACS712 current sensor sits in the fan's line wire, so the ESP32 also knows how much current the fan really draws. After every start it learns the fan's normal current; no current at all means a broken wire or a dead relay, and too much current means jammed blades, so the relay is switched off before the motor overheats. A dashboard shows everything, with a BOOST and a RESET. In this tutorial, we will go through the circuit, how the SHT40 measures humidity, how a zero-crossing solid-state relay switches the mains, how an ACS712 measures an AC current, and the code. Then we take a shower and jam the fan in the simulation. At the end, you can download the project with the sketch and every library file.

NOTICE: Our team has put a lot of effort into this project: the circuit, the code and every part in the simulation are our own work, and you get them all free. Your feedback is the fuel that keeps us going, so please tell us what you think in the comments below. And if our free projects help you, you can buy us a coffee. So, let's get started with the ESP32 exhaust fan with SHT40, SSR-25DA and ACS712 in Proteus simulation:

ESP32 Exhaust Fan with SHT40, SSR-25DA and ACS712 - Proteus Simulation: the ESP32, the SHT40, the ACS712, the SSR-25DA and the 230 V fan
Figure: The bathroom exhaust fan in a Proteus simulation.
ESP32 exhaust fan Proteus simulation: a shower starts the 230 V fan through the SSR-25DA, it runs, stops, and trips when blocked
Figure: The project working in the Proteus simulation (an animation of the main steps).

What Does This Exhaust Fan Controller Do?

  • Humidity control: the fan starts at 70 % RH and stops under 60 %, after a 10 s run-on.
  • Mains switching: an SSR-25DA switches the 230 V fan at the zero crossing, with no spark and no inrush spike.
  • Current check: an ACS712 measures the fan's RMS current twice a second.
  • Fault detection: NO CURRENT, BLOCKED (more than 1.2 times the learned current) and a relay stuck on.
  • Protection: a jammed fan is switched off and stays off until RESET.
  • A dashboard: the humidity, the fan, its current, BOOST and RESET.

In the simulation, the SHT40's pop-up changes the air, the relay's pop-up captures every turn-on and turn-off against the mains wave, the ACS712's shows the current, and the fan's pop-up shows its speed and lets us block its blades.

Components Used in the Proteus Simulation

All the parts come from our Proteus libraries, each with its own tutorial, plus Proteus's own ALTERNATOR as the mains. The project zip at the end includes every LIB and DLL file.

The parts of the exhaust fan controller and their library posts
PartProteus deviceLibrary postConnection
ESP32 DevKit V1ESP32 DEVKIT V1ESP32 DevKit V1 Library for ProteusU1, ESP32_Exhaust_Fan.hex, Wi-Fi 192.168.1.101
SHT40 humidity sensorSHT40TEPSHT40 Humidity Sensor Library for ProteusU2 at 0x44: SDA D21, SCL D22
SSR-25DA solid-state relaySSRDA25TEPSSR-25DA Solid State Relay Library for ProteusU3: IN+ on D26, T1 / T2 in the line
ACS712 current sensor (5 A)CURRENTACS712TEPACS712 Current Sensor Library for ProteusU4: IP+ / IP- in the line, OUT on D34
120 mm 230 V AC fanFAN120ACTEP120mm 230V AC Fan Library for ProteusM1, the exhaust fan
Laptop WiFi MonitorLAPTOP WIFI MONITORLaptop WiFi MonitorPC1
Mobile WiFi MonitorMOBILE WIFI MONITORMobile WiFi MonitorMOB1

Proteus Simulation of the Exhaust Fan: the Circuit

Exhaust fan Proteus simulation circuit: an ESP32, an SHT40, an ACS712, an SSR-25DA and a 230 V AC fan
Figure: The complete circuit of the exhaust fan on an A3 Proteus sheet.
The connections of the exhaust fan controller
SignalESP32Goes to
SDA / SCLD21 / D22the SHT40 (I2C, 0x44)
SSRD26the SSR-25DA's IN+ (IN- to GND)
CURD34the ACS712's OUT
5VVINthe ACS712's VCC
L, LS, LOAD-the mains line: the ALTERNATOR, the ACS712, the relay, the fan

The circuit has two halves. The low-voltage half is the ESP32 with the sensor, the relay's input and the current sensor's output. The mains half is one loop: the line from the ALTERNATOR (230 V RMS, 50 Hz) runs through the ACS712, then through the relay, then through the fan and back to the neutral. On a real board, the relay's optocoupler and the ACS712's isolated Hall sensor are what keep the two halves apart; in the simulation the neutral and the ESP32 share Proteus's ground.

How the Exhaust Fan Controller Works

Measuring Humidity with the SHT40

The SHT40 is a tiny I2C sensor that measures temperature and relative humidity together. Every action is a single command byte: 0xFD starts a high-repeatability measurement, about 7 ms later the chip has six bytes ready: the temperature, its CRC, the humidity and its CRC. The ESP32 checks both CRCs (CRC-8 with the polynomial 0x31) and converts the raw values: RH = -6 + 125 x raw / 65535 %. A shower takes a bathroom from about 50 % to over 90 % in minutes; a fan that starts at 70 % catches it early.

Switching the Mains with a Solid-State Relay

The SSR-25DA has an LED and an optocoupler on its input and a triac on its output, so the ESP32 never touches the mains. Its input takes 3 - 32 V DC at about 6 mA, which a GPIO pin drives directly. It is a zero-cross relay: after the input comes on it waits for the next zero of the mains voltage before it conducts, so the fan never gets a sudden half-cycle peak. And a triac lets go only when its current falls to zero, so with an inductive load like a fan motor it turns off at the next zero of the current, which comes later than the voltage's zero. There are no contacts to spark or wear.

Measuring an AC Current with the ACS712

The ACS712 passes the current through a copper strip next to a Hall sensor; its output sits at half its supply with no current and moves 185 mV per ampere (the 5 A chip). With AC the output swings above and below that zero 50 times a second, so a single reading means nothing. The sketch takes 40 ms of samples, two whole mains cycles, subtracts the zero it measured at the start with the fan off, and computes the root mean square: RMS = the square root of the average of the squares. A 120 mm fan draws only about 0.115 A, which is 21 mV on the output, and the RMS still resolves it.

Is the Fan Really Running?

An induction fan's current tells a lot. It is high while the motor starts, settles to a steady value when it runs, and rises again if the rotor is held, because the motor no longer produces the back voltage that limits it. The sketch waits 5 s after every start, learns the steady current as normal, and from then on compares: under 0.05 A means NO CURRENT (a broken wire, a blown fuse, a relay that did not close), more than 1.2 times normal means BLOCKED. A blocked fan is switched off and the fault is kept until someone presses RESET, because a fan that jams once will jam again. Current while the relay is off means the relay is stuck on, a triac's usual way to fail.

The Arduino Code Explained

The sketch is ESP32_Exhaust_Fan.ino, built for our ESP32 DevKit V1 with the WiFi, WebServer and Wire libraries. The humidity band:

const float ON_RH = 70.0, OFF_RH = 60.0;                          // the humidity band

One SHT40 measurement: the command, the CRC check, the humidity:

  Wire.beginTransmission(SHT40); Wire.write(0xFD);
  if (crc8(d, 2) != d[2] || crc8(d + 3, 2) != d[5]) { crcErrors++; return false; }
  rh = constrain(-6 + 125.0f * srh / 65535, 0, 100);

The ACS712's zero at the start, then the RMS over two mains cycles:

  zero = sum / 400.0f;
  while (micros() - t0 < 40000UL) { const float v = analogRead(CUR) - zero; sq += v * v; n++; }
  return n ? sqrt(sq / n) * VREF / 4095 * 1000 / MV_PER_A : 0;

The relay is one pin:

  digitalWrite(SSR, on ? HIGH : LOW);

The control: ON when humid, OFF only after the run-on:

  if (rh >= ON_RH) { dryAt = 0; relay(true, "humid"); }
    else if (ms - dryAt >= RUNON_MS) { dryAt = 0; relay(false, "dry"); }

The checks against the learned current:

  if (amps < NO_CURRENT_A) { trip("NO CURRENT"); return; }
  } else if (normalA && amps > normalA * BLOCKED_X) trip("BLOCKED");

The dashboard's links are Refresh, BOOST and RESET; /data gives the humidity, the fan, the current, the normal current and the fault as JSON.

How to Run the Proteus Simulation

  1. Download the project zip below and install the library files (the steps are under the download button).
  2. Open ESP32-Exhaust-Fan.pdsprj from the Proteus Simulation folder. Keep the HEX and the DLL files next to it.
  3. Press Play. Click U2 for the SHT40's pop-up and press RH +5 % five times: the fan starts.
  4. Click M1, U3 and U4 for the fan, the relay and the current. Press RH -5 % four times: the run-on, then OFF.
  5. Open the Laptop WiFi Monitor (press Go), press BOOST, then Blades blocked on the fan's pop-up.

Simulation Results: a Shower and a Jammed Fan in Proteus

We pressed Play and took a shower in the simulation: the humidity raised with the SHT40 pop-up's chips, dried again, a BOOST from the phone, and then the fan's blades blocked with its pop-up's chip. The relay's pop-up captures every turn-on and turn-off against the mains wave; the fan's shows its speed, current and power. The times are the sketch's clock; the whole run took 46.9 simulated seconds.

The Quiet Bathroom

The ESP32 measured the ACS712's zero with the fan off, 3110.3 counts = 2.506 V, joined TEP-WiFi and reported READY - 50.0 % RH, 23.0 C at 2.34 s. With no current at all, the RMS calculation still reads about 0.02 A: that is the ADC's own noise, and the reason the NO CURRENT limit is 0.05 A and not lower. The relay held the mains off with 1.5 mA of leakage through its snubber.

Exhaust fan Proteus simulation ready: 50 % RH, the fan off, the relay holding 230 V off
Figure: Ready: the fan off.
SHT40 pop-up in the exhaust fan simulation: 23.0 C, 50 % RH, the 0xFD measurements
Figure: The SHT40: 50 % RH.
ACS712 pop-up in the exhaust fan simulation: no current, OUT 2.506 V, the zero
Figure: The ACS712 at its zero.
SSR-25DA pop-up in the exhaust fan simulation: off, 230 V RMS held off, 1.5 mA leakage
Figure: The relay: off.
Laptop WiFi Monitor showing the exhaust fan dashboard in the simulation: FAN OFF, 50 % RH
Figure: The dashboard.

A Shower: the Fan Starts

Five presses of RH +5 % took the bathroom to 75 %, and at 8.35 s the sketch reported FAN ON (humid). The relay's pop-up shows how it switched: its input went to 6.0 mA, and it waited for the mains' zero crossing, turning on 8.1 ms after its input with only 12.1 V across it at that moment. The fan started at 0.135 A, its start current, 1876 RPM and rising.

Exhaust fan Proteus simulation: a shower, 75 % RH, the relay on and the fan starting
Figure: A shower: the fan starts.
SHT40 pop-up in the exhaust fan simulation: 75 % RH after the shower
Figure: The SHT40: 75 % RH.
SSR-25DA pop-up in the exhaust fan simulation: turned on at the zero crossing, 8.1 ms after the input
Figure: The relay turns on at the zero crossing.
AC fan pop-up in the exhaust fan simulation: STARTING, 1876 RPM, 0.135 A
Figure: The fan starting.

Running Normally: the Current Learned

Five seconds after the start, at 13.40 s, the sketch reported running normally: 0.118 A learned. The fan's pop-up agrees: 2642 RPM, 0.115 A, 18.9 W at a power factor of 0.72, moving 160 m3/h. From now on, 1.2 times 0.118 A, about 0.14 A, is the limit for BLOCKED.

Exhaust fan Proteus simulation: the fan running at 2642 RPM, 0.118 A learned
Figure: Running normally.
AC fan pop-up in the exhaust fan simulation: RUNNING, 2642 RPM, 0.115 A, 18.9 W, 160 m3/h
Figure: The fan running.
ACS712 pop-up in the exhaust fan simulation: the fan's AC current through the sensor
Figure: The ACS712: the fan's current.
Laptop WiFi Monitor in the exhaust fan simulation: FAN ON - humid, 0.118 A, normal 0.118 A
Figure: The dashboard: running normally.

Dry Again: the Run-On

Four presses of RH -5 % brought the air to 55 %, under the 60 % limit. The sketch did not stop the fan at once: dry - running on 10 s at 17.35 s, then FAN OFF (dry) at 27.35 s. The relay's second capture shows the triac letting go at the zero of the fan's current, -14 mA, which comes after the voltage's zero because the motor is inductive. The fan coasted down.

Exhaust fan Proteus simulation: dry again at 55 % RH, the fan switched off after the run-on
Figure: Dry: the fan off.
SHT40 pop-up in the exhaust fan simulation: 55 % RH, the air dry again
Figure: The SHT40: 55 % RH.
SSR-25DA pop-up in the exhaust fan simulation: turned off at the current's zero, -14 mA
Figure: The relay turns off at the current's zero.
AC fan pop-up in the exhaust fan simulation: COASTING at 1295 RPM, no current
Figure: The fan coasting.

BOOST, and a Jammed Fan

From the phone we pressed BOOST at 31.63 s; the page answered at once and the fan started 0.7 s later, FAN ON (BOOST), and learned 0.118 A again at 37.39 s. Then we blocked its blades with the fan pop-up's chip at 38.6 s. Held still, the motor no longer makes the back voltage that limits its current, and the current rose: at 38.88 s, 0.28 s after the jam, the sketch reported FAULT: BLOCKED - 0.156 A, 1.32 times normal, and switched the relay off. The fan's pop-up shows it stopped with no voltage; the relay's shows its second turn-off.

Mobile WiFi Monitor showing the exhaust fan dashboard in the simulation: FAN OFF, 55 % RH
Figure: The phone.
Mobile WiFi Monitor in the exhaust fan simulation: BOOST pressed, 30 s
Figure: BOOST from the phone.
Exhaust fan Proteus simulation: the blades blocked, FAULT BLOCKED, the relay off
Figure: FAULT: BLOCKED.
AC fan pop-up in the exhaust fan simulation: the blades blocked, stopped, no voltage
Figure: The fan: blocked and switched off.
ACS712 pop-up in the exhaust fan simulation after the trip: no current, the run's graph
Figure: The ACS712 after the trip.
SSR-25DA pop-up in the exhaust fan simulation: off after the fault, 2 turn-ons and 2 turn-offs
Figure: The relay: off after the fault.
Laptop WiFi Monitor in the exhaust fan simulation: FAULT: BLOCKED - 0.156 A
Figure: The dashboard: FAULT BLOCKED.

Free Air and RESET

We freed the blades with the Free air chip and pressed RESET on the laptop: RESET from the web: the fault cleared at 42.63 s. The fan stays off until the humidity or a BOOST asks for it again. The serial monitor logged the whole run, every 2 s:

Laptop WiFi Monitor in the exhaust fan simulation: RESET, the fault cleared
Figure: RESET: the fault cleared.
Exhaust fan Proteus simulation at the end: free air, the fault cleared, the fan ready
Figure: The end.
AC fan pop-up in the exhaust fan simulation: free air again, stopped
Figure: The fan freed.
ESP32 serial monitor in the exhaust fan simulation: the humidity, the fan and its current
Figure: The serial log.

Download the Project Files

Click the button below to download ESP32-Exhaust-Fan-SHT40-SSR-25DA-ACS712-Proteus-Simulation-v1.0.zip (about 4.0 MB, without the source code of the models):

ESP32 Exhaust Fan with SHT40, SSR-25DA and ACS712 - Proteus Simulation V1.0
  • Proteus Simulation: ESP32-Exhaust-Fan.pdsprj, ESP32_Exhaust_Fan.hex and copies of the models.
  • Arduino Code: ESP32_Exhaust_Fan.ino, the sketch.
  • Proteus Library Files: the LIB files of every part.
  • Proteus Model Files: the DLL models.
  • README.txt: the installation steps, the properties, the test results and the links to every library post.

No Proteus yet? Read How to Download and Install Proteus 7 and 8. New to libraries? Follow How to Install a New Library in Proteus.

How to Install the Project Files

  1. Close Proteus and extract the whole zip file, for example to your Desktop.
  2. Copy the files from Proteus Library Files into the LIBRARY folder of Proteus.
  3. Copy the files from Proteus Model Files into the MODELS folder.
  4. Start Proteus and open the project from the Proteus Simulation folder.

Changing the Code

Open the sketch in the Arduino IDE with the TEP Boards for Proteus installed, select ESP32 Dev Module (TEP Proteus), and use Sketch > Export Compiled Binary. Put the new HEX next to the project. The humidity band, the run-on, the learning time and the fault limits are near the top.

Ideas to Extend the Project

  • Start the fan on a fast rise of the humidity instead of a fixed level, so it works in a humid summer too.
  • Add a light switch input: the fan runs on for a few minutes after the light goes off, like many building codes ask.
  • Log the fan's running hours and its normal current over months: a current that creeps up means a dusty filter.
  • Use a dimmer instead of the relay for two speeds, a quiet one and a boost.
  • Send a message to a phone on any fault.
  • Add a second SHT40 outside the bathroom and run the fan only while the air outside is drier.

From Simulation to Real Hardware

  • Mains safety: an enclosure, a fuse in the line, no exposed terminals; only work on it with the mains disconnected.
  • The SSR: a fan needs no heatsink, but above about 5 A the relay does; use one rated for the load's voltage and inductive loads.
  • The ACS712: its output can swing up to 5 V; add a divider before an ESP32 pin, and keep the mains side of the board well away from the rest.
  • The bathroom: splash-proof parts, a sensor away from the shower's direct spray, and the electronics outside the wet zone.
  • Noise: average a few RMS readings before deciding on a fault; a real fan's current varies a little.

Troubleshooting

  • The fan never starts: the humidity must reach 70 %; D26 must drive the SSR's IN+ with IN- on GND.
  • NO CURRENT at every start: the ACS712 must be in the line wire and its OUT on D34.
  • A false BLOCKED: the fan was still speeding up when its current was learned; make LEARN_MS longer.
  • The current never reads zero: the zero is measured at the start; the fan must be off then.
  • No dashboard: the ESP32 joins TEP-WiFi about three seconds after the start; press Go again.

Limitations of the Simulation

  • The SHT40, the SSR-25DA, the ACS712 and the fan are our libraries' models, built from their datasheets and the parts' behaviour, not every detail of real parts.
  • The shower is the SHT40 pop-up's chips, not steam: the humidity jumps 5 % at a press.
  • The run-on is 10 s so that the run stays short; a real fan runs on for minutes.
  • ESP32 is a product of Espressif Systems; this project is not made or endorsed by Espressif or by Labcenter.

So, that was all about the ESP32 Exhaust Fan with SHT40, SSR-25DA and ACS712 - Proteus Simulation. I hope it helps you understand how a humidity sensor, a solid-state relay and a current sensor work together, and why a controller that switches a motor should also check that the motor turns, all tested in a simulation before you go near the mains. One more project will complete this series of one hundred. If you have any questions, ask in the comments and I will help you out. Till the next tutorial, take care and have fun!


Comments

0

Join the conversation