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. 
- Wires.
- 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
       - Veraboard/breadboard
      - 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
- Screwdrivers
- Multimeter
- Drill
- 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


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

Get a mini greenhouse and...
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 :).


QosayI made it!(author)2016-08-18


%C3%93skar+UCU made it!(author)2015-12-23

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?

imsubuji made it!(author)2015-08-22

hello ,

may i know how to make breakout board for mg811. can u send the circuit diagram

DustinSievers43 made it!(author)2014-06-07

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

anthony_p1234 made it!(author)2014-06-12

Hey Mate,

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.


ahillenb made it!(author)2014-11-01


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.

paolo.clavijo.73 made it!(author)2014-10-17

Hi Anthony, would you mind providing us with your code? it would be of great help, and if you can your schematics. Regards.

Akin+Yildiz made it!(author)2014-08-10

good stuff..!

HeliosV2 made it!(author)2014-02-24

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!

ahorn8 made it!(author)2013-11-30

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.

princenk007 made it!(author)2013-11-30

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.

AlanFFM made it!(author)2012-10-15

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.
thanks :)

jbark made it!(author)2011-06-04

Hi Anthony,

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.



anthony_p1234 made it!(author)2011-06-05

Hi Jbark,

Sorry, I didn't put much detail in about that. But basically it's something like this:
555 Timer --> pin 14 of cd4017. Then output of cd4017 pin 11 to arduino. Ground pin 8, 13 and 5.


ricbordenave made it!(author)2011-07-27

Sorry... Ground are pins 8, 13 and 15. Thanks

jbark made it!(author)2011-06-06

Thanks Mate

thebestofall007 made it!(author)2011-07-23

Co2 too low??? You said "This system of air filtration is also used for the air supply when the co2 gets too low". Dont you want the co2 to be as low as possible?

anthony_p1234 made it!(author)2011-07-24

Yes, it's meant to read "CO2 gets too high". The program switches the relay on when the CO2 level goes over a certain threshold. I just wrote the wrong thing and my editor didn't pick it up before it went to print.

bsnob made it!(author)2011-07-14

i saw someone make a similar device a long time ago , but no co2 sensor though and they connected it to the lpt1 port of a pc to control it , but it was used for mushrooms , i wish i could find the site where i saw it he had a basic software he wrote for it and everything and he was even selling kits or providing exact part lists with item # and where to get them ,i was interested in makingg one of these for a greenhouse ,but with a pc control or interface and a data logger, anyone know where i could fing plans for something like that?i thought i sa it on the shroomery but i forget and a search there turned up nothing

Asameea made it!(author)2011-05-11

Hi Anthony, I want to know the amount you paid for CO2 with singal conditioning as shown in the diagram.
As you told about that website, i have checked the product, its cost is around $35, but i want to know exact amount i should pay for delivery to India.
Hence i am asking you to tell me the amount you paid for the same.
Thank you.

anthony_p1234 made it!(author)2011-05-11

I think the shipping was roughly around the same price of the item (35$).
It is a bit pricey. You can always skip this equipment and just set up the relay to turn on to drive a pump to exchange air for a specific amount of time every hour or so. (or use a timer :) )
I have had good results with this.

Also, the Co2 sensor is the most sensitive being logarithmic and is difficult to calibrate.

This is up to you though.


tsenarathna made it!(author)2011-04-07

Hi Anthony,

What sort of output data did you end up getting with the Parralax sensors? Great work btw!

anthony_p1234 made it!(author)2010-06-25

What you're doing sounds great, mushrooms are excellent in the way that they can transform wastes into fertile soils etc. ... and good for eating too! I never knew projects like yours existed, awesome!

rocketsurgery made it!(author)2011-03-28

Hey again... If you are interested in what we have been doing with oysters in Afghanistan, I have recently published a couple of instructables...

How to Grow Oyster Mushrooms Low Tech and
How to Grow Oyster Mushroom Spawn Low Tech

I have just constructed a hepa filter laminar air workstation to help with producing spawn... might like to try your instructable out with regard to our test growing room... Thanks again for sharing...

rocketsurgery made it!(author)2010-06-25

Currently we are growing them in straw (which then, after harvesting, gets given to their animals)... the great thing is that they don't need lots of land and the locals love them (other types grow naturally in spring and in the mountains)... we need to get them reproducing the spawn to complete the cycle... we'll see how that goes... thanks again for your 'ible!

Paghman Mushrooms.jpg
ratheeshbr made it!(author)2011-03-01

Can you please tell me from where did you got this CO2 Sensor in India?

anthony_p1234 made it!(author)2011-03-02

Hi Ratheeshbr,

It was the MG811 co2 sensor, I got the sensor in kit with omp amps from parallax on the web. Google for parallax co2 sensor gets you there.


rt61 made it!(author)2010-06-24

I would like to learn how to grow oyster and shiitake mushrooms. Where should I start? Thanks!

wifigod made it!(author)2010-06-24
Raziel7 made it!(author)2010-11-30

DVDs and books are good starting points for learning about growing mushrooms, but will not teach you how to grow them well. Most of the material is somewhat outdated.

New methods conceived by mycologists and growers can be found at

Search the forums for all the knowledge you will ever need, plus it is free.

articice made it!(author)2010-07-02

just steal it from ED2K ed2k://|file|%5BPsilocybin%5DGrowing%20Gourmet%20and%20Medicinal%20Mushrooms-Paul%20Stamets-2000-1580081754.CV.pdf|36908319|D7C4B3A02C96D1823E012B22315E98CE|/

joystik made it!(author)2010-07-02

Youtube is your friend. Also, check the torrent sites for "Growing Mushrooms" DVD.

carlossantiago made it!(author)2010-07-15

Very cool use of the arduio. It's a great start for your first time coding in "C". GuruSantiago Checkout my arduino projects here: And follow me on twitter @ElectronicsFun

ladrua made it!(author)2010-07-15

I was thinking the same thing. I am building a similar project, and base my relay sircuits from this guide

wifigod made it!(author)2010-06-24

I'm very excited to see somebody working on a very similar project as me! :-D I do have one question, where did you buy the MG811 that came with the op amp board? I too made the mistake of buying just the sensor and couldn't get it to work. (I'm NOT an electronics person, but I'm trying to learn!) Thanks!

anthony_p1234 made it!(author)2010-06-24

I got the MG811 with op amp from parallax a company I found through the internet. Good luck with your project! :)

ksgeek made it!(author)2010-07-10

Very nice project. I am creating a home HVAC data logger. As a side note the documentation on the mg811 sensor is very poor. I have the sensor working, I am concerned about the temperature. Do you keep the mg811 heater on constantly, or preheat it before polling? If so is the sensor hot to the touch?

anthony_p1234 made it!(author)2010-07-12

For my project I keep the heater on all the time, although the MG811+op-amp board had a pin that you could use to switch the heater on/off. I guess it may affect the shelf life of the sensor if it is on less frequently. The sensor is more warm than hot, although when I did put in the wrong voltage it did get too hot to touch (it didn't destroy the MG811 though!). To answer your question I did find that the sensor took a while before the reading became constant and didn't keep dropping, it was about 5 min.

twhaley made it!(author)2010-07-06

That's, i'm doing it!

Clayfig made it!(author)2010-07-05

how is it all working out for you ? I would love to see a kit from you with all the parts to order

tehjrow made it!(author)2010-07-01

Don't you need diodes to protect the arduino?

anthony_p1234 made it!(author)2010-07-02

How so, do you mean on the power supply to the Arduino?

salesmonster made it!(author)2010-07-01

Amazingly thorough writeup. You have done a great job of marrying two wonderful hobbies. I've been considering putting together the mycology environment project that Make magazine had several years ago...but humidity and temperature were my concerns. These systems fit the bill perfectly. Thanks for taking the time to share.

anthony_p1234 made it!(author)2010-07-02

No Probs, thanks for your comments.

Kitoru made it!(author)2010-07-01

It'd also recommend it. It's very highly informative and contains a lot of species specific information that'd be difficult to work out for yourself. I'm loving this project. I started a similar project about three years back that used almost exactly the same methods. The only variance really is that I used a Wine Cooler as the case to battle blistering California temperatures and a Sensiron SHT11 combined temp/humidity sensor. Except my Arduino BT (Sparkfun accidently upgraded my order) melted down and I've been working on rebuilding another board from scratch. T_T; It's not going well~ One question though. Why the choice of Thermocouples over serial interface temperature sensors? I believe the prices are comparable, and serial interface is such a breeze to work with.

anthony_p1234 made it!(author)2010-07-02

At the time I was making the project It didn't occur to me to use serial (is it i2c?) and didn't know arduino was able to use it. The more I find out about the Arduino the better it gets :).

Namban made it!(author)2010-07-01

This is amazing! I would definitely make this. I never thought I'd actually find someone growing their own oyster mushrooms- I used to live in Japan, for about 3 years, and they have the BEST mushroom in the world there- エリンギ, Eringi, or King Oyster Mushroom in English. They taste 100x better than portabellas or even good shiitake- but I can't find them on the east coast US anywhere! And they taste like buttered steak... I've looked forever, but can't find anywhere on the net for king oyster mushroom spores- does anyone sell them? They are so good I must grow them myself, since noone in my area of the world seems to sell them. Can anyone help?

DIY-Guy made it!(author)2010-07-02

Namban said: "They are so good I must grow them myself, since noone in my area of the world seems to sell them. Can anyone help?" DIY-Guy relied: You want to grow "King Oyster Mushroom"? Try using a Google search like this- "King Oyster Mushroom" growing kit Then look at the results- Other sites also are out there. (Disclaimer: I don't work for these guys nor do I have any affiliation at this time.) Thanks for the food description- "they taste like buttered steak..." it sounds really good to eat!

Namban made it!(author)2010-07-02

Thanks for the info. I'd done plenty of Google searches over the years, and nothing came up- these must be recent, as I would have found them before. And yes, they taste exactly like a good steak smeared with butter. They are incredible- if you ever get a chance to try them, take it!

hot-fresh-rider made it!(author)2010-07-02

Let us not forget the king of mushrooms the Maitake, proported to have health benifits in a different league to regular mushrooms. could this breed be cross bred with conventional mushrooms? Cheap regular mushrooms with awesome health properties? we can dream!

About This Instructable




Bio: I pass the time by involving myself in small projects and watching youtube political discussions. I am a jack of all trades and master of ... More »
More by anthony_p1234:Mushroom Environment Control - Arduino Powered
Add instructable to: