Environment Control System




Introduction: Environment Control System

In this project I show the construction of an Evironment Control System which is controlled with a Raspberry Pi.

This was for my eighth-grade STLP (Student Technology Leadership Program) project. More information about Kentucky's STLP program is available at their website, which is:


Currently, I can use it to control a small table-top sized demonstration greenhouse. The system can scale to be much larger, however, since it uses relay boards to switch 120v outlets.

My goal was to develop an environment that would be optimal for a food-producing plant so that food and sustenance could be obtained in extremely urban areas, in places with rapidly changing climate, or even on other planets, such as Mars. The ECS system could also be used to grow plants in areas too far away from the optimal growing area to ship. I will do this by controlling three variables: temperature, moisture, and light.

I used temperature and moisture sensors to relay information to the Raspberry Pi computer, which uses the information to decide when to turn on a water pump or a heating device. I also drive an LED grow-light in a computer controlled day-night cycle. In order to show progress as the plants grow, I use a computer controlled camera mounted within the dark enclosure to track the progress of the plants.

Step 1: Building the 4-gang Switched Outlet Part1

In order to switch greenhouse heat, lights, water pump, and ventilation fan, I assembled a 4-gang switched outlet.

It is viewable on the right in the picture above.

Step 2: Building the 4-gang Switched Outlet Part2

A standard US outlet has two receptacles, and normally they are wired all together. Since I wanted to switch four outlets and I wanted to do it in the smallest space possible, I chose to break one of the tabs between each pair of receptacles. In this case, I chose to break the "neutral" side. You can see that in the two photos above. In the second picture, note that there are two neutral wires for each outlet pair, for a total of 4 neutral wires. It is these 4 wires that will be switched when the relays are in operation.

Step 3: Lay Heat Tape and Build Support for LED Grow Light

Early on in the development stages of my project, I realized that the heat lamp I planned on using to heat the enclosure would greatly interfere with the day-night cycle, as well as heating the air too much, while heating the dirt too little. So I scrapped that idea, and decided to use heat-tape instead. I could put a heat-coil under the dirt, which would heat the roots of the plant most importantly, and due to the rising of its heat it would warm the air quickly and easily.

In the first picture above you can see the heat tape held down with insulated staples.

After getting the heat tape fastened down, I made a support for the LED grow light I had bought. As you can see in the second picture, this is just a simple wood frame held together with screws. I used coat hanger wire to attach the light to the support. In the third picture the frame and support are on their side so you can see the bottom surface of the grow light. That's a lot of LEDs.

Step 4: Make and Use the Planter Tray

The planter tray shown above had to fit a very specific small greenhouse I had, so I had to make the tray. I used the bottom of a cardboard box, cut it to size, and water proofed it with layers of plastic wrap and aluminum foil.

Then, as seen in the first two photos above, I planted my demonstration plants. In this case, I chose lettuce.

After planting I put the planter tray into the bottom of the greenhouse, and put the house in place on the heater and directly under the LED grow light.

Step 5: Construct Water System

For this demonstration greenhouse, I chose a small submersible pump. With this, I can use a bucket as water reservoir. To distribute the water into the platter tray, I used tee and a circle of tubing. I drilled 1/64 holes into the bottom side of the tubing. Then, I placed the dribble hose into the planter tray. Before use I attached a piece of tubing between the outlet of the pump and the tee fitting on the dribble hose.

Step 6: Wiring the Control System

A very important step was to wire the wires from the gang outlet to the relay side of the relay board. The second picture shows the power, ground, and control wires on the input side of the relay board. The last picture shows how the breakout board looks after I wired my 2 inputs (soil temperature sensor and soil moisture sensor) and 4 outputs (the relay controls) to the Raspberry Pi. It looks complicated but it isn't really.

Step 7: Sensors

My temperature sensor is a 3 wire device which looks like a transistor, but it's much more. I'm using the DS18B20 from Dallas Semiconductors. This device is directly supported by the Raspberry Pi. After hooking it to power, ground, a signal pin, and running very simple setup, the operating system reads the temperature and puts the result in a file. Can't get much simpler that that.

During the construction of the greenhouse, I realized that the soil temperature sensor wasn’t water proof, so to protect it from moisture, I encapsulated it in heat-shrink tubing, and sealed it with epoxy. The first picture shows three temperature sensors in various stages of preparation. On the left, the leads have been soldered to wires and heat shrink tubing applied to each lead individually. The center sensor has an added layer of shrink-wrap tubing over all the wires and the end of the sensor. The rightmost sensor has all that done, and epoxy applied to each end of the shrunken package to seal out any water or moisture.

In the second picture you can see the soil temperature sensor and soil moisture sensors being placed in the soil.

Step 8: Programming and Running

I built a series of small programs to:

  • Turn lights on
  • Turn lights off
  • Turn heat on
  • Turn heat off
  • Turn on water pump for 15 seconds
  • Take picture with Raspbery Pi Camera
  • Read soil temperature
  • Read soil moisture

Many of those programs are included here.

Be the First to Share


    • Woodworking Contest

      Woodworking Contest
    • Stick It Challenge

      Stick It Challenge
    • Home and Garden Contest

      Home and Garden Contest



    7 years ago on Introduction

    Im curious if you've had problems with your moisture sensors at all? Ive been using the same ones but i seem to have run into a small problem... DC current... is causing my sensors to corrode and the resistance between the forks just goes up and up over the course of a month or two and I am replacing them frequently. Ive actually had to put the project on hold because ive been busy doing other things but... Im getting ready to dive back into it, and before i scrap those sensors entirely (in favor of using some nails or something that might last a little longer - I figured id ask around to see if other people have already solved this problem.


    Reply 6 years ago

    I don't know if you still run into those problems, but I got the same some time ago and had a pretty easy solution, at least for me: Since I don't have to continuosly measure the humidity I decided to just do it every 15 minutes. So I connected the VCC pin with a digital out of my arduino instead of 5V and put it on HIGH just moments before my measurement...

    techno guy
    techno guy

    6 years ago on Introduction

    Nice job, I hope to see something like this on Mars in a few years :)


    7 years ago on Step 8

    Very well thought out project. I have been planning to do something like this but on a larger scale. all the components you have used should work perfectly for the size i plan to build. If you build other things using 120VAC i would recommend not switching the neutral wire. the reason behind this is if you switch everything off but don't unplug from the wall, the hot wire is still live and more importantly the the neutral will be also be live since the current will pass through the load(s) and back on the neutral wire. I look forward to reading your code and implementing it in my own project.


    Reply 7 years ago on Introduction

    Glad you liked the project. I have more code that schedules things and reacts to heat, cold, and moisture to switch the outlets. I'll try to get more of it up there soon.

    For your system you could use a bigger relay board or turn on more relays per output if you needed to.

    Also, thanks for the comments on the switching. The neutral wire switching was done on advice of an electrician. As you can see in the pictures, the switched side is pulled outside the outlet box and is very slightly exposed at the relay terminals. I asked the electrician about your concern and here is what he said:

    It is certainly true that the hot lead of the load would be energized even with the relay off, and it's unusual to use neutral-side switching. It was done here because this is a demonstration project to be shown in a technology showcase where lots of people might poke and prod at it. In this case, neutral switching reduces the chance of a shock because:
    1.) The neutral carries no current unless the relay is on and something (the load) is plugged in to the outlet.
    2.) When the relay is on and the load is operating, there is a voltage drop across the load, so that the voltage on the neutral (after the load) is lower than it would be on the hot (before the load,) and
    3.) even with the completed circuit (relay on and load connected) the best path to ground is likely to be back through the neutral wire instead of through your body, so a shock is less likely than if the hot wire were taken outside the outlet box.
    So the neutral-side switching was appropriate here. But in a normal circumstance where the relay boards are going to be protected from prodding, use hot-side switching so that the outlet is dead when switched off.

    Thanks again for looking at the project.


    Reply 7 years ago on Introduction

    It is hard to explain without a picture but when the relay is off the load acts just like a wire and the neutral becomes alive. When the relay is closed the load does act as a voltage drop and the neutral is at zero volts. Rather than believing either of us, try this. Use a multimeter to measure from either the neutral feeding the relay board or from ground, and measure the AC voltage at the output of the relays. From my experience you will find 110 - 120 volts at the relay when off and zero when the relay is on. My goal is to keep you and your spectators safe.



    Reply 7 years ago on Introduction

    Your description makes sense. I see that the load will provide a path for the current all the way back to the relay. I'll ask the electrician about this tomorrow. I'll also measure the voltage with it wired the for neutral switching and report back. Thanks very much for your comments.


    7 years ago on Introduction

    Great project! And very well-documented too. Very well done. I hope we see more neat projects from you! :)