Did you know that different species of plants have different lighting, temperature and watering needs? Today, we will learn how to use a Photoresistor and a Water sensor to measure some of these variables and store this information in a CSV file to track the health of our plants.
Plant or garden
|Power Station||WiFi/Bluetooth||Motor Driver|
Connecting your sensors
1. Connect the Photoresistor (also known as LDR or Light-Dependent Resistor) to the Breadboard block:
2. Add the Breadboard block to the Workspace and open up the Pin Configuration Assistant from the Properties Panel:
NOTE: Make sure the 'Input Sampling Rate' is set to 20. This forces the Breadboard block to send 20 readings per second to your computer.
3. Configure the pins to read Analog data from the Photoresistor:
4. Connect the water sensor to the breadboard as shown in the image below. If you have questions about how to configure the breadboard pins or how the water sensor works, we have covered this in the Water Sensor article.
Once everything is connected, you should end up with something like this:
Now just insert the water sensor into the soil and attach the photoresistor to the pot. You can use sticky tape to keep the photoresistor and cables in place.
Note: You can alternatively add hot glue around the sensor's contacts to waterproof it
Go inside the Breadboard’s Logic Maker:
Add and connect the following gates:
the recipe will average the reading of the Breadboard block over 15 seconds and send the value to the output gate.
Visualising The Data
To see the changes of light and water levels over time, you can add a couple of DataGraph Widgets from the 'Dashboard' screen:
Add a second 'Data Graph Widget' and repeat this process for the 'water' output.
If you leave the recipe running for a while, you'll see the graph shows the changes in light and water over time.
Now you just need to find a good location to place your plant!
Exporting data to CSV
You can alternatively export the block's data to a CSV file via the Data Logger Virtual Block. If you haven't added it to your collection of Virtual Blocks already, just open up the Market Place and install it (you need to login in order to see the list of available blocks).
Add the new block to the workspace and connect it as a child of the Breadboard.
Open up the Data Logger's Properties Panel and add two columns with the names 'light' and 'water', these will become your CSV headers.
Make sure you select a location to store your file, then click on 'Save':
Finally, go inside the Breadboard's Logic Maker and add a couple of 'Action' gates after the 'Suspend' gates:
And that's all! This will generate a .CSV file in the directory you specified, and data should be stored automatically every 15 seconds there. You can then use any other program such as MS Excel to graph or manipulate the data in any way you want:
You can download the recipe from this link.
NOTE: The recipe does not contain Widgets, you will need to add them manually.