Building a Raspberry Pi greenhouse

Lead Image © Dietmar Hoepfl,

Green Garden

A greenhouse environment has to be just right. The temperature can't climb too high or sink too low, and the plants need water. Why not put your Raspberry Pi to work as the gardener?

We have a new greenhouse in the back yard, and I am singlemindedly thinking up new ideas to accomplish the daily tasks that go with operating it. Will I have to open and close windows and water plants manually? I had the bright idea of using a Raspberry Pi as the control unit for the greenhouse, with a few sensors and a solar panel to provide electricity (Figure 1).

Figure 1: The finished Rasp Pi greenhouse with a solar panel on the roof.

Raspberry Pi Gardener

The interior of a greenhouse is not supposed to overheat, especially in the middle of the summer. The need to provide summer cooling is one of the reasons that several vents are typically built into the roofs of greenhouses.

Building a mechanical device that would permit these vents to open and close via remote control is not trivial, and you would need to purchase several expensive components to complete the project. Therefore, I installed fans normally used for a PC in the greenhouse. It is not clear yet whether these fans will be able to survive in the long term in a rough climate. On the other hand, the fans didn't cost anything, because I had them lying in a box of spare parts.

Simple serial sensors can act to gather measurement data. The Rasp Pi reads these sensors via the GPIO interface and controls the fans via the GPIO PWM port. I prepared some of the ports to control simple operations like lighting and operating the pumps used to water the plants.

Simple PHP scripts are the control software. These scripts write the measurement values into a MySQL database so I can later display the information graphically. An Apache web server functions as a front end, and a line of cron jobs takes over the scheduled execution of the tasks.

Green Electricity

The first problem is a supply of power for the Rasp Pi. Because the Raspberry Pi only consumes about 3.5 watts, it should be possible to meet all of its power needs with solar energy. However, I can't count on a steady supply of sunshine. Sunlight is easy to find in the summertime, but gray winter skies are a problem where I live. The control system must provide a way for the greenhouse to continue operating, even in the complete absence of sunshine.

My approach to the design of a solar-powered electricity supply is that the system should be usable even in the depths of winter and during protracted periods of rainy weather. Moreover, the system should produce enough energy so that reserves are available for other projects. You are free to modify these goals as necessary to fit your own system.

I assume the Raspberry Pi needs 12W with all of the add-ons and losses. The actual amount is probably somewhat lower, but taking 12W as a suggested value makes the arithmetic easy because the battery provides 12V. Therefore, 1A of electricity gives a rate of power consumption of 12W. The following list shows that I come fairly close to actual values when using the 12W figure as an estimate:

  • Raspberry Pi: 3.5W
  • Fans during operation: 6W
  • Power loss: 2-3W

In general, you need to assume a loss of 20-30 percent of the net power of the system (see the box titled "Power Loss").

Power Loss

  • Power is lost in every cable, but, in this case, not very much. Losses increase with wires of smaller diameter.
  • The batteries themselves contribute to losses because they self-discharge, and they produce heat when they discharge too quickly or too deeply.
  • Linear charge regulators literally burn the energy that a battery cannot absorb. PWM regulators equipped with microcontrollers work much more efficiently.
  • Linear voltage converters can also become very hot, thereby losing a lot of power. By contrast, a switching regulator transforms the power at an effective rate of 80 percent.

Additionally, the life of the battery decreases more rapidly with deeper discharge. Therefore, it makes sense to get a slightly larger battery than necessarily needed for the design. You can use the formula P = U x I to compute the power (P, watts) from voltage (U, volts) and current (I, amperes).

You can figure out the capacity requirements of the battery from the length of time the Raspberry Pi needs to function without sunshine. A 12V battery with a 100Ah capacity provides 1A of electricity over a period of 100 hours. It therefore delivers 100 hours of the 12W that are required. This would suffice for four days of complete darkness, which should be more than enough.

The capacity required from the solar panel can be determined from the number of hours of sunlight during which the battery can be charged. A 120W solar panel at 12V delivers 10A per hour in maximum sunlight. Therefore, the panel can completely charge a battery having a 100Ah capacity in just under 10 hours. The amount of charge can be calculated using the formula W = P x t, where work (W, Amp*hours) is obtained from power (P, watts) and time (t, hours).

The Wp (watt peak) value assigned to solar panels approximates the so-called peak capacity (i.e., the maximum capacity possible under optimal conditions). Normal conditions of operation result in up to 20  percent less capacity. You must also take into consideration that the charge regulator needs to be able to tolerate the theoretical value.

After thoroughly researching the matter, I decided on a 100W solar panel with an 80Ah battery and a simple PWM charge regulator (see the "Warning" box). Batteries and solar panels of a smaller size are usually more expensive than those intended for use in home construction.


Twelve volts does not represent a physical danger for a human being; however, you should still exercise caution because a short circuit can cause a battery to deliver several hundred amperes of electricity. For this reason, powerful batteries always have very large terminals. The amount of electricity produced by a short circuit can cause the clamps on battery cables to start glowing. The inside of the battery also heats up significantly. When this happens, battery acid can leak out or the housing can burst. For all of these reasons, you should make sure that you connect the battery carefully and always use the correct terminals.

Using these component parts, I hope to be able to bring the system through the winter and plot temperatures for an entire year. As soon as the outside temperature drops, the fans should not require much energy at all. The electrical power generated by the solar panel should be sufficient for the operation of the Rasp Pi even during periods of little sunlight.

When wiring the solar electric power system, I made sure I used wires with a minimum diameter of 2.5mm2. I adopted the connection layout from the instructions for the charge regulator I selected. In turn, I protect the regulator and the wiring from rain and bad weather with a waterproof housing.

Once the solar electrical power system was in place, I put together the hardware that controls the greenhouse.

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content