Have you ever struggled to keep a plant alive? Wished your plant could tell you whether it needed to be watered or moved a little closer to the window? Build a Leaf Light for your indoor plants to help you tell if they are getting enough light and water!
The Leaf Light consists of a soil moisture sensor, light sensor, and multicolored LED/NeoPixel connected to an Arduino that sits in or near a plant. It's surrounded by a frosted plexiglass container, which makes it an attractive light, and glows different colors based on the status of your garden. Here's what the colors mean:
Translating the Leaf Light
- Green: Everything is great! Soil moisture and light are at or above desired levels
- Blue: Water your plant. The soil is dry.
- Orange: Give your plant more light. It hasn't gotten enough today.
- Red: Your plant needs some love. Water the plant and give it some more light.
- White: Error. Check your connections and Arduino (not shown).
This project was designed for my class, Making and Makerspaces, which is part of the Master of Library and Information Science Program at St. Catherine University. For our final project, we were challenged to create something using a new skill. I had been itching to try something with the Arduino for awhile, and given my tendency to kill plants regularly, this became the project I tackled.
Who Is This Project For?
Really, anyone who has an interest in combining electronics and gardening (smart gardens, automated gardening systems, etc.). Not only was this my first project using an Arduino, but my first time soldering, building circuits, playing around with programming (outside of Scratch with kids and markup languages like HTML/CSS). If I can figure it out, I'm willing to bet you can to, with a little time and effort.
I studied a lot of different projects that involved Arduinos and gardens in some way, but there were several I studied extensively and borrowed from to create this project. I encourage you to check out these other projects:
- Erbbie - Desktop Smart Garden by zacharyianhoward
- Garduino: Gardening + Arduino and Potted Plant Protector (Make Magazine) by liseman
- Moisture Detection with Two Nails and Soil/Moisture Detection System by ronnietucker
- Twitter Mood Light by RandomMatrix (used for the light box design and NeoPixel instructions/code)
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Materials and Tools
Here's what you need to make the Leaf Light.
- Arduino Uno R3 or another microcontroller
- Mini breadboard
- Adafruit TSL2561 Digital Light Sensor or similar
- Neopixel Mini PCB (sold in packs of five, only 1 needed)
For the soil moisture sensor
-  galvanized steel screws or galvanized nails
- 10K ohm resistor
- Packet of Sugru
For the light case
- clear acrylic sheet (aka plexiglass)
- hot glue sticks
- something to hold the Arduino and breadboard. I used a small, plastic snack container
For the circuits
- 22-Gauge, solid core wire in a variety of colors and/or breadboarding wires
- 60/40 rosin-core solder (.032" diameter or similar)
- Blue painters tape or other easily removable tape (not necessary, but I found it helpful to hold pieces down or together when I needed more than two hands)
- Several containers of dirt (used to test different soil moistures and calibrate your sensor)
- A indoor plant or herb garden (not strictly necessary, but the project is kind of pointless without it)
- Soldering iron with pencil tip
- Wire stripper
- Flush diagonal cutter
- Needle-nose pliers
- Glass cutter
- Hot glue gun
- Straight edge (not shown, I used a long piece of wood I had on hand)
- Computer with Arduino IDE installed (not shown)
Step 2: Assemble the Soil Moisture Sensor
There are three different components that we are going to attach to our Arduino: a soil moisture sensor, a light sensor, and a NeoPixel light. All three have some sort of assembly or set up needed before they can be connected. First, let's create our soil moisture sensor from two screws and some wire!
Soil Moisture Sensor
I followed this Moisture Detection with Two Nails very closely to make the sensor. Here's what you need to do:
- Cut two pieces of 22-gauge, solid core wire. I used red and black to keep track of which wire will be connected where (red will be connected to 5V/the power source and black to ground). Estimate the length you think your sensor will need to travel from the Arduino.
- Strip the coating off of both ends of using the wire stripper. One side should be long enough to wrap several times around your screw/nail and the other long enough to fit into a pin in your Arduino or breadboard.
- Wrap the long end of uncovered wire just under the head of the screw or nail. You want it to be wrapped pretty tightly, because it needs to maintain a connection with the wire.
- Optional: Solder the wire together at the base of the head, and to the nail/screw if possible (not shown).
- The two nails cannot touch and need to maintain a stable distance from each other. I molded some Sugru I had on hand around the two nails to keep them apart at the same distance. I have also seen this achieved with a square of styrofoam. Be creative!
Step 3: Assemble the Light Sensor
For the light sensor, I used an AdaFruit TSL2561 Digital Light Sensor. You could achieve the same effect with a different light sensor or a photoresistor. To use the light sensor, we need to solder four wires to the sensor. AdaFruit has complete instructions for Wiring the TSL2561 Sensor on their website, but here are the basic steps (we aren't using the 6-pin header strip, so just replace wires for the header).
- Cut four pieces of 22-gauge, solid core wire. Color code them, if possible. Again, I used red for power (Vin on the sensor) and black for ground (GND), but I only had green wire left, which I used for both the i2c SCL clock (SCL) and i2c SDA data (SDA). You do not need wire for the middle three spots.
- Strip both ends of each wire using the wire stripper, enough for one end to go into the Arduino/breadboard and the other end to go through the spots on the sensor.
- Poke the end of each wire through the hole you will be soldering it to (see the earlier mention of color coding). Once the wire is through, bend it at a 90-degree angle under the sensor so the remaining wire is parallel to the face of the sensor.
- Solder the end of each wire to the sensor. Haven't soldered before? No worries! There are a lot of tutorials out there. This SparkFun How to Solder article was useful for me.
- Use the flush diagonal cutter to cut off the excess wire flush to your solder joints (aka just above your solder).
Step 4: Solder Wires to the NeoPixel
I only used one NeoPixel for this project, because I don't need any patterns or multiple colors at once. An RGB LED would also do the trick. I chose the NeoPixel based on a recommendation in the Erbbie tutorial, because it would be easier to solder and have all the resistors and capacitors attached (an alluring promise for a newbie like me).
- Cut three pieces of 22-gauge, solid-core wire. If you have three colors, that is great. I followed the same pattern as the last two sensors. Red for power, black for ground, and green for communication with the Arduino.
- Strip both ends of each wire using the wire stripper.
- Look at the back of your NeoPixel. There are six spots for soldering. You want to solder the wires to the Din side (not Dout). The red wire will be connected with the +, the black with the -, and the green in the middle.
- Before we solder the wires to the NeoPixel, we want to pre-tin the ends of the wire. Use your soldering iron to apply a thin layer of solder covering the tip of each wire. This will help us make the connection.
- The soldering spots are very small and the solder should not touch any other sections. Since I don't have a helping hand, I used blue painters tape to hold everything in place before I soldered.
- With the tip of the wire touch the spot it will be connected to, solder each wire into its correct place.
AdaFruit has a NeoPixel Überguide if you have more questions or want to learn more.
Step 5: Build the Circuit
You have all your pieces ready. Now, it's time to build your circuits.
At this point, it is helpful to be familiar with the basic ideas behind circuits and the Arduino. If you've never worked with Arduino before, I recommend working through some beginning lessons (that's what I did). There are a plethora of great Arduino tutorials out there. I used LadyAda's Arduino Tutorial and found the lessons very helpful. However, there is a plethora of great lessons out there. Google [Arduino beginner] to find one that looks useful for you.
Here are the step-by-step directions to build the Leaf Light. For more help, look at the images above, which include a circuit diagram and a photo of my messy looking set-up.
- Use two breadboarding wires to connect one line of the breadboard to 5V and another line to Ground.
- Use a small wire to connect the lines horizontally. Now any time you need power, you can take it from the power row and any time you need to connect to ground, you can tap into the ground row.
- Moisture sensor. One wire (red) goes in the 5V row on the breadboard. The other (black) goes into a new row on the breadboard. Use the 10K ohm resistor to connect to ground and another breadboarding wire to connect to A0 (Analog pin 0).
- Light sensor. Connect Vin (red) to 3.3V on the Arduino (not the breadboard). Connect GND to ground on the breadboard. Connect SDA (green) to A4 (Analog pin 4) and SCL (green) to A5 (Analog pin 5).
- NeoPixel. 5V/+ (red) connects to 5V on the breadboard. gnd/- (black) connects to ground on the breadboard. Din (green) connects to D6 (Digital pin 6)
Step 6: Set Up the Arduino and Test the Circuit
Grab your computer, because it is time to set up the sketches and program your Leaf Light.
You'll need to have the Arduino IDE installed. This is the free, open-source software you'll use to write, edit, and upload code or "sketches" to your Arduino. The Arduino Getting Started guide includes links to instructions for Windows, Mac, and Linux.
You'll also need to download and install several Arduino libraries. Libraries are collections of code that are pre-written and shared for commonly used functions. They simplify the process for you, so we don't have to create code from scratch. SparkFun has general directions for installing a library for different operating systems. Here are links to all the libraries you need to download and install:
So, once we have the Arduino IDE installed as well as all six libraries (check whether they are installed correctly by looking for them under the Libraries menu), it's time to test the circuits.
Download the Arduino sketch leaflighttest.ino (at the end of this step). This is a simplified version of the full Leaf Light test sketch. Open up the sketch and look through it. See if you can make some sense of what it is trying to achieve.
When you are ready, connect your Arduino with all the components attached with your computer. Verify and upload the leaflighttest.ino to your Arduino (to verify, or check the code for errors, choose the checkmark button. If no errors are found, then you can upload the sketch to the Arduino by clicking the right arrow button). Things to check:
- Does the NeoPixel turn on?
- What color does it start with?
- What happens when you put the soil moisture sensor in damp soil?
- What happens when you put the soil moisture sensor in dry soil or no soil?
- What happens when you hold the light sensor near a bright light?
- What happens when you cover the light sensor with your hand?
Try these in different combinations. If working correctly, the NeoPixel should change colors to match the following conditions:
- Green: In moist soil and near bright light
- Blue: Not in moist soil but still near bright light
- Orange: In moist soil but blocked from light
- Red: Not in moist soil and blocked from light
- White: This means there has been an error.
There is a short video above that shows how the Leaf Light should react in to different sensor readings.
If things are not working, you need to start checking for errors. First, look at all your sensors and your light. Are they soldered well? If not, desolder and fix. Second, double check how the circuit is set up. Try moving pieces around or connecting things in different ways. Third, especially if you've made alterations, look through the code. Is something not matching up?
Step 7: Upload the Full Leaf Light Sketch and Calibrate Sensors
Once you've determined the circuit is set up correctly, now you need the full leaflight.ino sketch (found at the bottom of this sketch).
First, open up leaflight.ino in the Arduino IDE. Take a look through the code. You'll see added material with the light sensor and also with time. There are a few elements in the sketch you need to update yourself. But first, you'll need to understand a little bit about how the sketch functions. Here's a brief overview of how the code works:
Every ten minutes, the Arduino gathers data from the two sensors. The soil moisture data is immediately used to set the color of the NeoPixel. So, once the soil gets too dry, within ten minutes the Leaf Light should switch to blue or red.
The Arduino also gathers data about the amount of light that it is receiving. Unlike the test code, which reacts to whether or not it is light at the moment of testing, the Arduino will calculates whether it has received enough light. There is a variable, seconds_light, that keeps track of the number of seconds of light received each day. We track the amount of light we receive over the day, and create a proportion of time lit out of the time elapsed. After 2pm, the Arduino checks this proportion. If the amount of light proportional to the amount of time passed does not reach our desired levels, the NeoPixel will turn orange or red.
The Arduino doesn't have an internal clock. What this means for you is that you need to manually input the time and date in the code just before you upload it, so this time calculated in code reflects reality.
Find this section of the code (labeled with **Action needed!):
<p>//set up the timers<br> setTime(0,0,00,1,12,15); /**Action needed! Every time you update your Arduino, change this section to set the Arduino to the current time (hour, minute, second, month, day, year) so (8,29,40,12,1,15) equals 8:29:40am Jan 12 2015*/</p><p> Alarm.alarmRepeat(0, 00, 0, midnight); //runs midnight function at midnight to clear out previous day's data Alarm.timerRepeat(10, checkSensors); //grabs data from sensors every 10 minutes (checkSensors()) }</p>
Before you upload, change the numbers in setTime(hr, min, sec, day, month, year) to reflect your current time and date.
The next edit you need to make to the sketch is to calibrate your moisture sensors and update the minimum variables to match your readings.
Using the test code from the previous step, do the same test as before, but with the Serial Monitor running. The Serial Monitor will report every time sensor readings are taken. Put your sensors in different settings (different pots of soil with varying moisture levels or different types of lighting). What is the lowest number for each sensor you would accept to consider the plant receiving light and to consider the soil moist?
Calibration may take time. If you are unsure, choose numbers that seem appropriate and use them for awhile. If they don't seem to be work, update the numbers until you find the right levels.
Now you need to set these minimum acceptable levels in the sketch. Find this section, and change the values to the numbers you've recorded.
<p>//Set minimum values for sensors **Action Needed: update these values to match your sensors and plants<br> int lightMin = 30; int moistMin = 400;</p>
Finally, you need to decide how much light per day you think your plant should receive at minimum. If you aren't sure, look up your plant. Again, this will take a process of trial and error, but think about the quality of light received in conjunction with the amount. Does it get direct sunlight? Does it mainly receive light from lamps? The default is set to 12 hours a day. Find this section, and change the number after hours_light_daily_desired to the (minimum) number of hours you'd like your plant to get light per day.
<p>//Stored light variables. Set up variables to store and accumulate light amount throughout the day<br> int hours_light_daily_desired = 12; //**Action needed: Update # of hours of light you think your plants should get per day float proportion_to_light = hours_light_daily_desired/24; //calculates proportion of desired light per day int seconds_light = 0; //this variable stores the number of seconds of light received each day. We initially have it set to 0. float proportion_lit; //this variable will be used to calculate the actual proportion of light to dark received each day (to compare with proportion_to_light) int time_elapsed = 0; //used to measure the amount of time that has passed in seconds int lightLevel = 1; //used to assign true/false value to the accumulated light level. 1=enough light, 0=not enough light</p>
Once these three sections have been updated, you're ready to go. Verify your sketch (check for errors by clicking the checkmark) and then upload it to your Arduino!
Step 8: Build the Case and Assemble the Light
Your Leaf Light is working--gathering data and reacting to it by changing the color of the NeoPixel LED. Now, all we have to do it make it look nice.
I considered a lot of different ways to make a container for the Leaf Light. It needs to protect the electrical components from the dirt and moisture, while also diffusing light and hiding all the wires. Some options I considered:
- Using materials on hand: an old plastic sandwich container for the Arduino with holes cut in it for the sensors and lights to go out, with an upside down mason jar covered with white tissue paper and ModPodge over the LED on top to make a lamp.
- 3D printing a case. I designed a case to be printed on a 3D printer, but then decided against using it. I haven't printed it, but you can find the designs on Thingiverse.
- Make an acrylic cube like the Twitter Mood Light.
I decided to build an acrylic cube for my Leaf Light. I followed the instructions pretty closely for constructing the case from LED Cube Night Light, except using hand glass cutter instead of a jig saw.
Here are the steps:
- Take the acrylic sheet, a marker, and a rule, and draw lines for five squares of the exact same size. I used 95 mm. Do NOT do what I did in the picture and start 2cm in from the edge. I was not able to break those small pieces off.
- Using a straight edge (I have a long, thin piece of wood I happened to have on hand), use the lower tip of the glass cutter to score along the line multiple times. Flip the acrylic around so that you start from both ends and score both sides.
- Place the scored edge along a hard, flat edge and apply pressure. The sheet should snap in half along the line you scored.
- Continue until you have five squares.
- Remove the protective film from both sides of each square.
- Move the sandpaper in circles over both sides of each piece to scratch it up until it has a translucent effect.
- Use the hot glue gun to glue the pieces together into a five-sided cube.
- Adjust the lengths of the wires so that the Arduino and breadboard fit into a repurposed plastic container (I have a thin, shallow plastic container meant to store tiny amounts of food from IKEA).
- Set everything up. First, place the plastic container with the Arduino and breadboard in the dirt of your plant. Place the sensors where they belong (in the dirt, on the end of the plant container). Connect your Arduino to a power source (battery or the AC-to-DC adapter). Once the light is running, cover everything in the plastic container and the NeoPixel LED with the plexiglass cube. Do not cover the sensors!
- Enjoy your Leaf Light!
A note on cutting acrylic sheets by hand. It was very difficult to cut exact squares this way, so I have a slightly misshapen cube with edges that don't line up perfectly. I'm considering my current cube a draft version until I can borrow someone's jigsaw and cut more accurate pieces.
Step 9: Enjoy Your Leaf Light
I hope you enjoy building your Leaf Light. If you have any comments, improvements, questions, or upgrades, I'd love to hear them.
Looking forward, there are lots of potential improvements, some of which I'm working on:
- Add a mirror with a hole in it between the NeoPixel and the Arduino components. This will not only push all the wires out of sight, but improve spread of the light.
- Find a better way to contain all the parts beneath the light.
- Improve code to only run electricity through the galvanized screws when sensor readings are being taken. This will prolong the amount of time before the screws corrode and have to be replaced.
- Add maximums. Right now, the Leaf Light only measures whether minimum conditions (amount of water in the soil, amount of light received). Maximums could be added to make sure the plants are not drowning in water or not getting enough darkness.
- Nix the breadboard. I'm leaving everything on the breadboard for now, because I'm still testing and prototyping this light. Once everything seems to be working, I might explore more permanent options (soldering to a veroboard/stripboard or designing a printed circuit board).
- Timing. If you wanted timing to be more exact, you could add a real time clock (RTC) to the Leaf Light. This would also replace having to manually update the date and time in the sketch each time you upload it.
Thanks for reading!