Introduction: Mushroom Environment Control - Arduino Powered
This is my first Arduino project aimed at helping me with my other hobby which is growing oyster and shiitake mushrooms indoors.
In a nutshell, the controller takes in two temperature readings, 1 Humidity reading and 1 Co2 reading and triggers a set of four relays connected to mains power.
Intended to be connected to the mains are two heating pads, a sonic humidifier and an air pump (although the choice isn't limited to these of course).
Step 1: Items
Here is the list of items I used for the project.
-LCD Keypad shield.
- 7-12 volt power supply.
- USB cable (socket that connects to USB on Arduino).
-Box To house the whole thing.
- 4x solid state 5v- 240v relays.
- Mains Power board with four sockets.
- Jiffy box to house inline socket/screws to connect Sensors.
-Thermistors 10k x2
-Resistor 10k x2
-HS1100 humidity reader
- 555 timer (cmos type)
- resistors: 576k, 49.9k, 1k and 909k
- Jiffy Box
- Digital divide by ten Chip
-MG811 C02 sensor (I got a breakout board with op-amp amplifier built in. You can make it yourself, it is a high precision op amp set up as non-inverting with gain around 10).
- Jiffy Box
- 2 x heating pads
- Sonic Humidifier
- Aquarium Tubing
- Air Pump (aquarium)
- Plastic lunchbox (airtight)
- HEPA Filter for Vacuum cleaner.
- Plastic tub
- Aquarium Air pump
- Aquarium Tubing
- Plastic Lunchbox (airtight)
- HEPA Filter for Vacuum cleaner
- Hot Glue gun
- Soldering Iron
- Home brew larger.
Step 2: Thermistors
Solder two wires to each thermistor.
On a breadboard solder on a 10k ohm resistor, one end will connect to the Arduino ground, the other to Analog input 1 and to one of the thermistor wires.
The other end of the thermistor wire connects to +5v from the Arduino.
Do this for another Thermistor and connect it to Analog input 2 instead.
Basically it is a voltage divider with the thermistor defining the Voltage going to the Arduino analog input. One analog divider for each thermistor.
I added the circuitry in a separate jiffy box where the thermistor leads could be screwed into inline screws protruding from the box.
To test this sensor, use a multimeter to look at the voltage change as you put your finger on the Thermistor.
Step 3: Humidity Reader
The humidity sensor is a variable capacitor which changes linearly with the relative humidity.
The datasheet shows how to hook up the sensor using a 555 timer (must use CMOS type).
I used this circuit to send data pulses to the Arduino. At first I found the pulses were too close together and did not give high enough discrimination, so at the output of the 555 I put a digital divide by ten chip. This made it so the pulses wavelength was in the hundreds of microseconds rather than the tens of microseconds.
Please find attached the datasheet which has the circuit diagram using the 555 timer.
I used the same style inline screws as described with the Thermistor step as a go between for this sensor and the Arduino.
To Test this, hook up the output to a speaker supply power (6volts will do) and breath on the sensor, you should hear a drop in frequency.
Step 4: Co2 Sensor
Initially I had ordered an MG811 Co2 sensor by itself, after setting it up I couldn't make it work properly so I ordered one already on a board with an op amp amplifier built in.
I later found that the power supply I was running it with was faulty and the heating element in the Co2 sensor was running on overdrive.
Basically the circuit has the sensor hooked up to a non-inverting op-amp with roughly a gain of ten, and the heating element is supplied by a 6 volt voltage regulator. The set up is shown on the datasheet attached with pinouts of the sensor which is self explanatory, what isn't self explanatory is the graph on the datasheet which gives a totally inacurate picture of the expected output of the sensor.
Give it a test by placing a Multimeter on the sensor and breathing on it, it should change reading.
Step 5: Connect the Arduino
In this step I connected the Arduino to the go between board.
The Keypad shield goes just on top of the Arduino.
Solder onto the shield the separate Thermistor voltage dividers inputs to Analog 1 and Analog 2, Analog 3 takes in the Co2 input.
Solder to digital 2 the Humidity input.
Solder on the power supply, I recommend 7 volts supply as the C02 reader needs 6 volts at least. I soldered the power supply onto the go between board and then soldered from there to the Arduino.
I fed the 6 volts to power the humidity sensor and C02 sensor directly(as the C02 board had a voltage regulator), but used the 5volt reference voltage from the Arduino for the temperature sensor voltage divider.
Step 6: Mains Relays and Connection to Powerboard
***MAINS WIRING HERE SO BE CAREFUL***
Solder the four Mains relays to some Veraboard.
My relays had marked on them "+" "-" and two load pins. The - pins are connected to Arduino ground, each + is connected to the arduino digital pins 3, 11 ,12 ,13.
The load is what switches the mains active signal, and I used this to switch each individual active within the powerboard.
Opening up the power board I removed the copper strip connecting the actives, and cut them into four separate peices. Soldered onto each peice was one of four wires which were soldered back onto one of the load pins of each of the relays.
The active wire from the mains was then connected to the other load on the relay.
I put hot glue where normally the gromit would go on the powerboard outlet, and I also put hot glue around the mains wires near the relays, just to give it some extra strength.
Step 7: The Code
This was the first time I have coded in C in a long time (and my first real Arduino project). I am sure that there are many changes that could be made to streamline it, but it does the job and what's required of the Arduino board isn't really that intensive for this project.
...please note the original lcd4bit library has a lot of unnecessary delays in it which slows the code down A LOT, these should be removed (look in the cpp library file for clues).
In brief the code (in order of how it appears in the attached code) does:
- #defines M and C values for the linear and log equations required to translate the bit values for the inputs. i.e. y=mx+c and y= Mlog(x)+C
-#defines sizes for averaging array, sampling times, histerisis levels, Pins, EEProm storage size.
-defines variables, trigger values etc.
-Read in sensor values every "SENSOR_INTERVAL" milliseconds.
-Puts the new values in an array and averages this array.
-Performs calculations on the averages to give a 'proper' value i.e. centigrade (apologies to my american cousins but I am metric), ppm (co2), Relative Humidity.
-Prints updates of new temp, humidity and Co2 levels to LCD shield.
-Stores values to eeprom every "EE_PROM_INTERVAL" milliseconds.
-Trigger relays if bellow/above trigger, every "INTERVAL" milliseconds.
-Keypad code that implements a rudimentary menu system allowing triggering values to be changed and EEPROM values to be dumped to serial.
-Funtions to help with averaging and key selection.
I have tried to give an explanation within the code as to what each section does, by all means go in and take a look. If you are more inclined to shy away from reading the code, please note the main things to note are the #define statements for manipulating intervals for reading,triggering and averaging and the #define statements for calibrating M and C values.
These are all situated at the top of the code so take a look and have fun fiddling.
Please note that the code uses the EEprom library for reading writing eeprom values, the lcd4bit library (modified, delays are removed and the pinouts changed) for the lcd shield, and stdlib for converting int into char for writing to the LCD display.
Step 8: House the Project
....what?? you're asking me, the guy who had to add an extra jiffy box because he misjudged the size of the project and got a box that was too small!
Just a couple of notes here, make sure whatever you do that there is no chance that any of the mains power will ever in any way come into contact with any other wires. For me this involved having the mains veraboard as far away as possible within the project housing and to tie up all the wiring, and a dash of hot glue here and there to hold down the wiring. Basically keep it neat and tidy.
For the front panel I made a stencil of the LCD/Keypad shield of the arduino and drilled/cut to get the front panel to fit, and then with some nuts and bolts bolted on the keypad shield onto the front. You can also see that I drilled holes for the buttons.
Step 9: The Humidifier
To keep the temperature up you would plug in a beer heating pad (of course beer has to be involved).
To keep the C02 levels low you would add a fan.
...But what to add to keep the humidity up?? A humidifier and here's how I made mine.
First I got a small tub and drilled a number of holes in the top cover, and one bigger hole in the center. Next you thread the sonic humidifier wiring through and seat the humidifier on the bottom.
In one of the holes I attached some aquarium tubing.
On the other end of this tubing was an air pump held within a airtight tub. The lid of the tub had a hole cut out and was covered by a HEPA filter. The reason for the HEPA filter is so that air going into feed the mushrooms isn't contaminated with bacteria and other fungi.
This system of air filtration is also used for the air supply when the co2 gets too low.
After putting water in the tub, turn it on and watch.
Step 10: Humidity Calibration
This bit is tricky in that unless you have another humidity reader that you trust you can't be 100% sure that what you are calibrating is correct.
After some investigation I did find that I could get two readings (two is all you need) to calibrate.
First get a a plastic lunch bag and in it put a mug of salt which you have dampened just enough to make it feel like wet sand. Put the humidity reader in with it and wait for about 12 hours. From what I understand the humidity should be at 75% inside the bag.
Read off the serial out on the Arduino to find what value you are getting
Average this value over a number of readings. Write this value down, this is your X1 val, your Y1 value is 75.
Next go take a shower (take your computer with you), make sure it is a cold morning, after having a shower make sure there is a fine mist and take a number of readings with
Average this value and write it down, this is your X2, your Y2 value is 100.
Alternatively the last step can be done using the humidifier inside a large bag with the humidity reader inside it.
Now remember your algebra! Solve these two equations:
Y1 = m*X1 + C
Y2 = m*X2 + C
...and hope that m is as big as possible!
Using the M and C values fill out the portion of the code:
#define HUMIDITY_C 680
#define HUMIDITY_M 1.6
Step 11: Temperature Calibration
This one is relatively easy, I used my Digital multimeter and got two readings, one from under my arm (this was after the shower!) and one at normal room temp. Yes it does look funny having two sets of wires protruding from your armpit.
to output values.
Average those values to get your X value, your Y value comes from the temperature reading off the digital multimeter.
Your first set of readings comes from under your arm, your second set from normal room temperature.
Once again solve th equations to get M and C
Y1 = M*X1 +C
Y2 = M*X2 +C
Update M and C values in the code:
#define TEMPERATURE_M 13.31
#define TEMPERATURE_C 188.1
Step 12: C02 Calibration
This one is difficult.
The way I went about this was to look at the current value of C02 ppm in the world today (yes it is going up!), it's around 400ppm. Assuming that it is a bit higher if you live in the city (my one is relatively clean) I assumed normal outside Co2 levels to be 500 ppm.
So I opened my window and after allowing the Co2 sensor to heat up I took a number of
I averaged these out, and set my X1 value to equal this, my Y1 = 500.
The datasheet showed that the sensor maxed out at 10000ppm, so for my second reading I got some bicarb and vinegar put that in a plastic bag with the sensor and sealed it up and set the reaction off.
After a minute or so It reached its lowest reading using
so I used this value as my X2, my Y2 I set to 10000.
Now I solved to find M and C: (or use excell :) )
y1 = MLogn(x1) + C
y2 = MLogn(x2) + C
And plugged these values back into the program:
#define Carbon_M -83.45
#define Carbon_C 768.62
By the way for this step I am not convinced about my assumptions made about X2 and Y2 values (or Y1 values for that matter :) ), if anyone has some suggestions I am open to them.
Step 13: Test It Out
Hook up the gear and see how it performs, have fun fiddling with the histerisis, the averaging array size, the trigger temps, placing of the sensors and heaters humidifier etc.
A quick starter:
In normal display mode (where the temps hum co2 are shown) the only button that does anything is the right button which pushes the last days readings to serial tx.
To the far right of the display appear asterixes if the relays are triggered.
Press button 1 to go into configure mode, here you can adjust the triggering for temperature, relative humidity levels and C02 relays. Right scrolls through the different values, up/down lowers and raises the values.
Left button does nothing, my shield had a problem with the left button so I didn't program it in :).
Participated in the
Question 3 years ago
I'm implementing a similar project, but based on a nodemcu and Blynk, to cultivate mushrooms. What were your findings in the long run? Anything to watch out for?
Answer 3 years ago
Newer all in one temp humidity readers (digital) are much better at temp/hum reading and don't need calibration. Use these instead.
I'd suggest Having a base of perlite for humidty, and using the ultrasonic humidifier to top up the humidity when required (especially when cycling air).
CO2 reader wasn't very good (calibration wise, and also the fact it needed to be heated to give a good reading). I would scrap that all together and just go with a timed circuit that turns on air exchange x min every y minutes where x<y.
When bringing in new air, run the humidifier at the same time (stops the mushrooms drying out)
Reply 3 years ago
Thank you for your answer, this were more or less the same lines I was thinking in. Strangely, it looks like an aquarium pump through a water bath gives me much higher humidities (if I recycle the air) than an ultrasonic humidifier. So I'll run an aquarium pump always as a humidifier, and a second pump timed for fresh air.
Yes, I'm doing an absolute overkill on a timed oxygen cycle, so it is overly complicated to have an exact CO2 reading, which would anyway only be as exact as the money I'm willing to spend.
Many thanks for your fast answer
3 years ago
Hi , it looks great , can you tell me the rough cost of getting this set up please , I am UK based and would love a project like this for my mushroom growing rooms. Thanks
Reply 3 years ago
From what I remember:
$100 for most of the other stuff
$50 Extra just to be on the safe side
4 years ago
Nice! Did not complete my project but my idea was the same, after temperature setup, arduino would activate relays connected to peltier ceramic board with fan to cool and or a mosquito repellent resistence to warm untill reach setup temp.
Reply 4 years ago
6 years ago
7 years ago
Yo man i was thinking of using this For a terrarium control, and im completly new to arduino. But was thinking can i just leave out the c02 meter ? Or will it crash the code?
7 years ago on Introduction
may i know how to make breakout board for mg811. can u send the circuit diagram
8 years ago on Introduction
What is a digital divide by ten chip. Having issues finding this and would like to complete this project. Awesome job by the way. But please tell me what chip to order
Reply 8 years ago on Introduction
I've done a revision on this, I use RHT03 for temperature and humidity sensing:
It's digital so a lot more accurate, and less fuss.
Also rather than using a C02 sensor I'm just scheduling airflow (i.e. fan on for one minute ever 10 minutes....but it depends on your fans airflow).
If you want the code for this, let me know and I can supply.
Reply 8 years ago on Introduction
I am replicating this project for a wide format production print room humidification system. Would you please provide the updated code for the RHT03? Thank you.
Reply 8 years ago on Introduction
Hi Anthony, would you mind providing us with your code? it would be of great help, and if you can your schematics. Regards.
8 years ago on Step 2
9 years ago on Introduction
How did you deal with the 'bounce' on the SSR's due to low power consumption? I'm finding I get intermittent activation when the relay is supposed to be off. Very irritating!
9 years ago on Introduction
Nice project. I'm working on similar using a DHT-22 for Temperature and Humidity. Sweet setup with the CO2 sensor N all. I may put some ferns in the grow room just for now. Thanks for posting.
9 years ago on Introduction
Hello Anthony sir,
Very nice project. Keep up. Can you please help me too?
Based on this instructable can you please modify the code to use with sensirion sensor - sht75 to control relays for humidifier and heater instead of dht-22 sensor? Thank you.
10 years ago on Introduction
Great project! I'm trying to rebuild it but have this programming problem. I'm using the arduino uno which uses the liquid crystal library. For some reason I cant get the code to work at all and my knowledge in programming is sub par. Any tips or advice would help a ton. this is a project I'm very interested in.
11 years ago on Step 3
I'm new to electronic. I got my self cd4017 for the divider, can you please tell me where you the output from 555 goes to? Or how do I know which one divides. This one is tricky to follow.
By the way this is my very first electronic that's not a kit from Jaycar. I'm almost there with it but this one has got me stuck.
So I followed your instruction.