Onion storage ventilation controller
Build it step by step
0 of 7 doneTest both sensors
Print inside and outside readings with an I2C scan first.
Check the addresses
SHT31 at 0x44 and AHT20 at 0x38.
Wire the fan and relay
Test the fan from a simple sketch.
Upload
Breathe on the inside sensor to raise its humidity.
Compare absolute humidity
Watch the two values on the serial monitor.
Check the rule
The fan should start only when outside is drier.
Install
Place the sensors and fans in the shed; log fan hours each day.
How do you build an onion storage ventilation controller?
Fans in an onion shed run when outside air is drier than inside air, which keeps stored onions from rotting. You need Arduino Nano, SHT31 temperature and humidity sensor, AHT20 temperature and humidity sensor, Relay Module 5V, 12 V DC fan 80 mm, 12 V 2 A DC adapter and 16x2 LCD with I2C backpack (PCF8574). It takes 7 steps and about 120 minutes.
- Level
- Intermediate
- Time
- About 120 min
- Parts
- 7
Parts list
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- SensorsBuy
- InterfacesBuyRelay Module 5V × 1
- Motors & ActuatorsBuy
- PowerBuy
- DisplaysBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| SHT31 (inside) VCC and GND | Nano 5V and GND | Power, check your module accepts 5 V |
| SHT31 SDA and SCL | Nano A4 and A5 | I2C address 0x44 |
| AHT20 (outside) VCC and GND | Nano 5V and GND | Power |
| AHT20 SDA and SCL | Nano A4 and A5 | I2C address 0x38, keep the cable short |
| LCD I2C SDA and SCL | Nano A4 and A5 | Display |
| Relay module VCC, GND | Nano 5V and GND | Coil power |
| Relay module IN | Nano D7 | Fan control |
| 12 V adapter + | Relay COM | Fan supply |
| Relay NO | Fan + | Switched positive |
| Fan - and adapter - | Joined | Return |
Code
Comparing relative humidity alone can mislead, because cold air at 80 percent holds far less water than warm air at 80 percent. The code converts both readings to absolute humidity, grams of water per cubic metre, and runs the fan only when the outside air holds noticeably less moisture than the shed air, so ventilation dries the onions instead of wetting them. The fan stops when the difference falls or the shed is dry enough. Keep the outside sensor in shade and rain protection, and because both sensors share an I2C bus, keep the cable to the outside one short, or use a second Nano. Onions store best dry and cool, with good air movement; follow local advice for target conditions. Arduino IDE, board "Arduino Nano" (processor ATmega328P, or ATmega328P (Old Bootloader) for clones).
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Libraries: Adafruit SHT31, Adafruit AHTX0, LiquidCrystal_I2C.
#include <Wire.h>
#include <Adafruit_SHT31.h>
#include <Adafruit_AHTX0.h>
#include <LiquidCrystal_I2C.h>
#include <math.h>
Adafruit_SHT31 inside;
Adafruit_AHTX0 outside;
LiquidCrystal_I2C lcd(0x27, 16, 2);
const byte RELAY = 7;
const bool ACTIVE_LOW = true;
bool fanOn = false;
unsigned long fanStart = 0, fanTotal = 0;
// Absolute humidity in grams of water per cubic metre of air
float absHum(float tC, float rh) {
return 6.112 * exp(17.67 * tC / (tC + 243.5)) * rh * 2.1674 / (273.15 + tC);
}
void fan(bool on) {
if (on && !fanOn) fanStart = millis();
if (!on && fanOn) fanTotal += millis() - fanStart;
fanOn = on;
digitalWrite(RELAY, (on == ACTIVE_LOW) ? LOW : HIGH);
}
void setup() {
Serial.begin(9600);
pinMode(RELAY, OUTPUT); fan(false);
inside.begin(0x44);
outside.begin();
lcd.init(); lcd.backlight();
}
void loop() {
float ti = inside.readTemperature(), hi = inside.readHumidity();
sensors_event_t h, t;
outside.getEvent(&h, &t);
float to = t.temperature, ho = h.relative_humidity;
if (!isnan(ti) && !isnan(hi)) {
float ahIn = absHum(ti, hi), ahOut = absHum(to, ho);
float diff = ahIn - ahOut; // positive: outside air is drier
if (!fanOn && diff > 2.0 && hi > 65) fan(true); // outside air can carry moisture away
if (fanOn && (diff < 0.5 || hi < 60)) fan(false);
lcd.setCursor(0, 0);
lcd.print("In "); lcd.print(hi, 0); lcd.print("% Out "); lcd.print(ho, 0); lcd.print("% ");
lcd.setCursor(0, 1);
lcd.print(fanOn ? "Fan ON " : "Fan off ");
lcd.print((fanTotal + (fanOn ? millis() - fanStart : 0)) / 3600000.0, 1); lcd.print(" h ");
Serial.print(ahIn); Serial.print(","); Serial.println(ahOut);
}
delay(5000);
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
0.00,0.00
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Outside drier than inside | Fan on |
| Outside humid | Fan stays off |
| Inside dry enough | Fan off |
| Fan hours | Increase on dry days |
If it does not work
Outside sensor not found
Check its address and wiring; long cables cause errors.
Fan never starts
Check the thresholds and the relay logic.
Both readings the same
Check the sensors are not side by side.
LCD blank
Try address 0x3F.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the onion storage ventilation controller?
Arduino Nano, SHT31 temperature and humidity sensor, AHT20 temperature and humidity sensor, Relay Module 5V, 12 V DC fan 80 mm, 12 V 2 A DC adapter and 16x2 LCD with I2C backpack (PCF8574).
How long does the onion storage ventilation controller take to build?
About 120 minutes for a intermediate maker, in 7 steps.
How do I know the onion storage ventilation controller works?
Outside drier than inside: Fan on. Outside humid: Fan stays off. Inside dry enough: Fan off.
Outside sensor not found: what should I check?
Check its address and wiring; long cables cause errors.
Fan never starts: what should I check?
Check the thresholds and the relay logic.
Both readings the same: what should I check?
Check the sensors are not side by side.
LCD blank: what should I check?
Try address 0x3F.
