Learning Outcomes
- Be able to program a simple light sensor based on previous weeks
- Use multiple sensors, program functions and conditionals
Note: As I keep saying you will have to do the previous week’s work to be able to do this successfully unless you have experience already!
Task 1
We are going to bring together everything that you have learned over the last few weeks and expand on the use of sensors.
Visit the grove website for more information on the sensor http://wiki.seeedstudio.com/Grove-Light_Sensor/
From the library select Grove_Light_Sensor and you will see the following code. Connect the light sensor to A0 on the shield.
We want to change just the output and display whether it is dark or light on the serial monitor. Therefore, remove or comment out the pinLed declaration, and the digitalWrite code within the conditional. In the conditional I want you to write to the serial monitor whether it is light or dark.
Use the Millis function that we demonstrated in the lecture to delay the sensor so that it only takes a reading every 5 seconds. See https://www.norwegiancreations.com/2017/09/arduino-tutorial-using-millis-instead-of-delay/
Task 2
Building on from task 1 now we need to add the code to display and alter an LCD screen. In the last class we used the LCD screen, refer to the code example used in this or have a look at the example files.
I want you to create a function that will display whether it is light or dark on the screen. This should be called from within the conditional.
You will have to clear the text as light has more characters than dark and it will output darkt as it just writes over the display.
Extra: See if you can change the colour of the display so that it is green if it is light and red if dark.
Task 3
Reset the board to clear the code.
Install the WiFiNINA library. Go to Sketch/ Include Library / Manage Libraries and search for the library and install.
Once installed go examples / Wifinina and select the scan networks option and upload the sketch.
Extra
It you finish this have a look at some of the example files in the library so you get familiar with the code. For example look at the ping example, we will be looking at some of these in more detail next week.