In the the Boston area we get nearly 15.5 hours of sunlight in the middle of Summer, however, in March and April Boston receives around 11 and in the middle of winter we get about 9 hours of sunlight. Most plants require 12 hours of sunlight per day to grow well and if you are a greenhouse owner and you want to grow plants year round artificial light will be needed to grow plants. Or if you want to grow light plant indoors artificial lights will be needed. However, lights cost money to run so it would be good to know if your plants are getting enough light from natural sources and only use additional artificial light when needed.
In this lesson you will learn how to measure light intensity, measured in lux and how to use that information to turn on and off a GrowLight.
Wio Link board, digital light sensor, two connector cables, 1 LED GrowLight, rulers, Reading Material
In your composition notebook, write down answers to these two questions:
In the last lesson we learned how to turn on/off our LED grow lights. The LEDs are in red and blue, the desired colors for the plants. However, have you wondered whether these lights will be bright enough sufficient for your plants? Can it replace sunlight for our plants? Today we are going to learn how to measure the light intensity of our grow lights. This is going to help us make decisions about where we put our LED lights in the smart greenhouse.
get
a Light Sensor ReadingStart by introducing the do now:
from sensors import LightSensor
ls = LightSensor(port=6)
ls.get_lux()
To get a light sensor reading is relatively straightforward. One just needs to import the LightSensor, assign a variable, say ls, and use the .get_lux()
function to get the lux level. The code for this is just three lines and is:
Note that the light sensor has to go on port 6, because it is an I2C device. Also, when you are working with sensors, (that is, whatever you import from the sensors
module), you always use get_xxx()
to get a reading, whether it is moisture, light intensity(lux), or temperature/humidity, which we are going to use in the future.
Create a new file and write down the above lines. Run the script, and you should be able to see a light sensor reading in the terminal.
Move your light sensor around and run the program a few times to make sure that your light sensor is working. Now like we will want to be able to use the light sensor information to do something.
Alter the ambient light condition and repeat the readings. What are the light readings with the lights on/off? With the curtains drawn/not drawn? Are there differences between light sensors close/away from the windows? Facing the windows?
Now that we can measure light intensity, how about our own grow lights? If you are going to install the grow lights inside the greenhouse, what are some decisions you might have to make? Discuss with your partner.
Here are a couple of questions that might be helpful. Where do I put the grow light? How close should they be to the plants? Are my grow lights strong enough to replace sunlight?
There are two types of lights on the grow light - red and blue ones. Are they as bright as each other? Why or why not?
Now let’s use our light sensor to answer these questions. Turn on your Grow Light (see the script below). Place your light sensor at different distances from the red and blue lights, for example, 0 inches, 0.5 inches, 1 inch, etc. Record the lux readings on this worksheet .
When you have finished recording your data, graph the data in the blank spaces on the worksheet. Use different color lines for blue and red lights.
Answer the following questions:
The first step of controlling individual lights on the LED strip is the same:
from displays import GrowLight
gl = GrowLight(port=1)
Now you can assign individual colors to the GrowLight with this syntax:
gl[0] = [255, 0, 0]
gl.write()
This sets the first light to red. In the square bracket on the left of the equal sign, the number is the index of each individual light on the strip. This index starts with 0
, so the first light is 0, and the second is 1
, and so on. On the right of the equal sign is the color in [R, G, B]
. The square bracket makes sure that the three individual numbers are read as a whole by Python, not three individual numbers. They collectively have a meaning. The gl.write() actually sets the colors. This means, you can set more colors before calling gl.write:
gl[0] = [255, 0, 0]
gl[1] = [0, 255, 0]
gl[2] = [0, 0, 255]
gl.write()
We can think of the LED matrix as a list holding each individual colors like this:
We can put each individual colors in these cells, and then call gl.write()
to actually set all these colors to the LED strip.
We will need a for loop to do this. For loop is a more sophisticated structure that we might come back to in the future, so don’t worry about it if you don’t know what the following means:
for i in [0, 1, 2, 3, 4]:
gl[i] = [255, 0, 0]
gl.write()
Run the code and see what happens.
Now try to change the numbers in [0, 1, 2, 3, 4]
and see what happens. How about this line?
for i in [0, 2, 4, 6, 8]:
gl[i] = [255, 0, 0]
for i in [1, 3, 5, 7, 9]:
gl[i] = [0, 0, 255]
gl.write()
Again, feel free to modify the code and see what happens.
Please upload your final code to Google Classroom. Save your file in the format of wa1-0529.py
.