In this chapter, we learn to
program light sensor to measure ambient brightness.
program AHT20 sensor for humidity and temperature measurement.
program EDU PICO V2’s Raspberry Pi Pico 2 W into a WiFi access point.
Introduction: Light Sensor, Humidity and Temperature Sensor.
AI Task #1: Use the light sensor to automatically turn the RGB LED ON and OFF.
AI Task #2: Display temperature and humidity live readings on the OLED display.
Activities: Build a climate control greenhouse using temperature and humidity sensor, light
sensor, DC and servo motor, RGB LEDs, and OLED.
Bonus: Control the USB relay through a webpage using the Raspberry Pi Pico 2 W acting as a
WiFi Access Point (AP).
Aside from using the OPT4048 sensor for colour sensing, there ’ s still one feature left that we have yet to explore, and that is none other than the commonly measured, brightness! In this activity, we will learn how to measure different levels of ambient light, allowing you to create projects that respond to changes in lighting conditions.
-> Libraries: board, time, digitalio, adafruit_opt4048, busio.
-> Light Sensor I2C Pins Configuration: SCL = GP5 and SDA = GP4.
-> Input:
Shine light to the light sensor to increase the brightness level.
Block light from entering the light sensor to decrease the brightness level.
Upon completion of the activity, you should be able to:
-> Print brightness percentile in shell console.
Task:
-> Use the light sensor to automatically turn the RGB LED ON in the dark and OFF in bright environment.
Upon completion of the activity, you should be able to:
-> See when cover the sensor, all the LEDs should turn ON. When shining a light on the sensor, all the LEDs should be turned OFF.
The AHT20 sensor is a powerful component that provides accurate measurements for both humidity and temperature. Imagine having the ability to monitor and respond to changes in your project' s environment, whether its a home automation system, a weather station, or a smart gardening project.
-> Libraries: board, time, digitalio, adafruit_ahtx0.
-> AHT20 I2C Pins Configuration: SCL = GP5 and SDA = GP4.
Upon completion of the activity, you should be able to:
-> Program will print temperature in Celcius and relative humidity percentile in the shell console.
-> Enable view > plotter in Thonny IDE to allow you to visualize the temperature and humidity data in the same graph, making graph analysis easier.
Task:
-> Use the temperature and humidity sensor to display live readings on the OLED display.
Upon completion of the activity, you should be able to:
-> See that the OLED display should show both Temperature (°C) and Humidity (%) and continuously update the values every 2 seconds.
By the end of this activity, you 'll be able to setup your own WiFi AP network and enable EDU PICO V2 to communicate wirelessly with other devices. Let' s start with the basics – an access point, or "AP" serves as a central hub for wireless communication. It acts as a bridge between the EDU PICO V2 and other WiFi-enabled devices, like smartphones and laptops, to enable data sharing.
This setup is incredibly helpful for various applications, including IoT (Internet of Things) projects and remote-control systems. This bonus section will guide you through the configuration for your EDU PICO V2 to work as an access point. This means that you can connect to it, share data, and control it remotely, all over WiFi.
-> Libraries: board, digitalio, wifi, socketpool, adafruit_httpserver.
-> USB Relay Configuration:
Assign to GP22, and connect USB light stick to the USB port.
-> Connecting with computer:
The program starts the server and prints "Starting server..." followed by "Listening on http://[IP_ADDRESS]" where [IP_ADDRESS] is the IP address of the WiFi access point.
You can access the control interface by connecting to the WiFi access point (AP) (SSID: "EDUPICO_AP" , Password: "12345678") using a device like a smartphone or a computer.
When you open a web browser with the server ' s IP address, you will see a webpage with "Light On" and "Light Off" buttons.
Save the file, you're all set!
Once you ’ re on the webpage, clicking these buttons will send a signal to the server, and the relay state will change accordingly. Messages like "Light ON" and "Light OFF" will be printed on the shell console when the buttons are clicked.
-> Connect your PC to WiFi:
Connect your PC to the same WiFi network as connected by the Raspberry Pi Pico W.
Upon completion of the activity, you should be able to:
-> The program starts the server and prints "Starting server..." followed by "Listening on http://[IP_ADDRESS]" where [IP_ADDRESS] is the IP address of the WiFi access point.
-> You can access the control interface by connecting to the WiFi access point (AP) (SSID: "EDUPICO_AP", Password: "12345678") using a device like a smartphone or a computer
-> When you open a web browser with the server ' s IP address, you will see a webpage with "Light On" and "Light Off" buttons.
-> Once you’re on the webpage, clicking these buttons will send a signal to the server, and the relay state will change accordingly. Messages like "Light ON" and "Light OFF" will be printed on the shell console when the buttons are clicked.