Introduction: Arduino UNO, LCD 16x02 and Rotary Encoder Controlled Plant Environment
Home grown food, medicine, mushrooms, some incense maybe? You can try this instructable for starters. It's a plan for a grow box with the focus being on the lcd(output)/rotary encoder(input) system. The instructable is for one connection to each a water pump, light, vent, air humidifier as outputs and a soil humidity sensor, air humidity and temperature sensor, and of course the user, as inputs. There is a similar instructable here
that I came across a bit too late. I was already too hooked on making it my way. The mentioned instructable looks great and a bit long, so in the spirit of diversity I will make this one as plug-and-play as I can. Going as cheap as I can and making a sistem independent of a PC were my guides through this project. It can, like most arduino projects, be expanded to great heights.
To do this instructable you must have some knowledge of electronics and know how to load code to an Arduino and how to power an Arduino.
The schematic and even more so the code might evolve a bit, so don't be a stranger and check from time to time, even if you happen to build it and it works fine.
Step 1: (optional)Vaguely Familiarize Yourself With the Arduino Code Involved
Link to the code is in step 4.
First I will explain the variable most likely in the need of some tweeking. It is named msPERdL(miliseconds/decilitre) and it tells the programme how many miliseconds it takes for the water pump to pump one decilitre. It's currently set at 2000. Take a stopwatch, do some testing with your water pump, and remember that 1 second = 1000 miliseconds.
The setup portion of the code initializes the 16x02 LCD(screen), DHT11(air humidity and temperature sensor), the interrupts for the rotary encoder, the EEPROM(memory for values) and other stuff.
The loop portion checks:
- every 10seconds: the values of soil humidity, air humidity and temperature, and the output states of lights, vents, and part of the humidifier(the part of turning it on, don't ask me why)
- all the time: a function for watering, a rotary encoder/LCD menu function, and whether or not the humidifier has to be turned off(again, don't ask me why=)).
Because of the relay modules I used, the pin output that turns on the light, air humidifer and watering is LOW.
The air humidifier on/off time intervals are currently 5s/5s. The output to the ventilation depends on air temperature and humidity, maintaining humidity is made more important in the current function.
The watering function lets watering start every 2 minutes, and only if the soil humidity is below the chosen threshold.
The rotary menu function is actually the one I built this code upon. I got it from yet another great instructable https://www.instructables.com/id/Easy-Arduino-Menus... and if you happen to dive into the code I recommend understanding the original first, or it's outputs at least. For those of you who dont feel like diving - the function, in combination with interrupts and the button press, provides the navigation through the menu, which will be explained in the next step.
The other functions are for lights, vents and air humidifiers. Plus two functions for what goes on on the LCD.
Step 2: The LCD Menu
- 1st slide:
RHa[%] is relative air humidity and is given in percentage. Ta[*C] is air temperature and is given in degrees Celsius. There is nothing to modify here.
- 2nd slide:
shows/lets change the boundaries of relative air humidity you are trying to create (hi = high, lo = low). To change press/rotate/press/rotate/press.
- 3rd slide:
same thing as second slide, but for temperature.
- 4th slide:
shows the light per day set by the user in the first row. If the lights are currently on, the second row shows the time passed since the last time lights were turned on. If the lights are off the second row shows how much time is left till they are turned back on, and the value is negative then. To change the values repeat the above(2nd slide) routine. The second row value you set will be the delay till the "sunrise" in the environment. All values are in hours.
- 5th slide:
RHs[%] is relative soil humidity, again given in percentage. waterVol[dL] is the volume of water you want delivered through the water pump each time it's watering time, it will show correct values only if the first paragraph of the 1st step of this instructable is followed. Changing the values in this slide is done as before. By setting the first row value, you set the watering threshold soil moisture. And this will only work properly if you follow the procedure in the next slide.
- 6th slide :
Get a container of what you would consider the driest soil possible and one of what you would consider the wettest soil possible (or just get a glass of water if you're lazy). Press the rotary encoder so that the LCD says dry, put the soil moisture sensor into the dry soil and press again so the LCD says wet, put the sensor into the wet soil and press again so that the screen changes again (lazy ones use air and glass of water as substitutes for dry and wet).
Step 3: A Note About the Hardware
This instructable is basically a schematic to wire the electronic components and some Arduino code to load. The wiring includes dealing with 220V and this can KILL you so educate yourself and apply self-criticism. The majority of the setup such as the room or box and the choice of almost all electronic components, I leave to the DIY-er. What you need to follow follows.
The LCD screen must be size 16x02 and with an I2C interface. Mine said "IIC/I2C/TWI/SPI Serial Interface1602 16X2 Character LCD Module Display Blue", online order. You might have to change the address in the code, especially if you are not using an identical LCD, I guess.
The other component you have to get exactly as mine is the rotary encoder. Mine said "10pcs 12mm Rotary Encoder Push Button Switch Keyswitch Electronic Components", online order.
All components (except for the two above) are optional. You might want to change the relays with transistors, but the code is currently set so that you have to use PNP ones. The code practically runs the same if components are missing. But if you would like to cancel some LCD menu slides you will have to dive into the code a bit.
Step 4: The Actual Instructions
Follow the schematic on the picture.
I will also try to present you soon with some files for a PCB (printed circuit board) so that this becomes even simpler, in case you have the resources to provide yourself with one.
Download and setup the two libraries from the last step.
Download the .ino file from here:
Load it on the Arduino UNO and you're done.
Step 5: Some Photos of Known Compatible Components
2N2222 transistor, 100nF capacitor, power supply unit 12VDC, PSU 5VDC, relay module, water pump 12VDC, ultrasonic humidifier 24VDC, LED 220VAC.
Step 6: An Example Installation
I made mine with two pieces of 12VDC PSU wired in series to power an ultrasonic air humidifier, and using 12V to power a vent and two very dim LEDs. Other components used are a DHT11, a 5VDC PSU, a 2N2222, a 100nF capacitor, some resistors and two relay modules. The soil humidity sensor in the picture is there by accident. It's a mushroom setup, fruiting me some Oyster.
Step 7: References and Links
A similar, but more detailed instructable:
Other similar projects:
Based the Arduino code on:
With some help from:
And the 3D prints I used: