Buy from USA | Buy from UK | Buy from DE | Buy from IT | Buy from FR | Buy from ES | ここでご購入を! |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
In the lesson, we will imitate an automatic light system: when Photoresistor sensor detects that natural environment light is dark, computer will turn on man-made light( LED ) , when natural environment is bright, then computer will turn off LED.
Through this project, we will learn how to use variable block and analog input blocks.
In above circuit graph, you can see that:
LED negative pin connected to GND
LED Positive pin connected to GP15 through 220 Ω resistor
photoresistance pin 1 connected to 3.3V through 10 kΩ resistor
photoresistance pin 2 connected to GP28
1)Click New Project icon, you will see a My project icon with a fancy name will pop up. as following picture,
2)Click the new icon in My Projects
Now you will enter a new graphic programming page. Please click CONNECT Button in the bottom of the page and connect your Pico board to your project,then your browser will pop up a Serial Port option menu, please select Pico from the menu and click Connect button;
If you can not see Pico in the Serial Port menu, it means your Pico is not setup properly. You need go back to Lesson 1 Step 1 and setup Pico again.
After you connect Pico to Serial Port, your GUI Connect button will switch to Disconnect button as following picture
1)Click Chip -> Start , then move Start chip to coding area as following picture:
2)Click Loops -> repeat while true and move this block just below start block as following picture:
3)Now need to create a Variable , Click Variables ->Create Variable and name the variable light_value as following picture:
4)Now you will see some new variable blocks, move the set light_value to block inside repeat loop block as following picture:
5)From Chip category, add a Read Voltage block to set light_value to Block ,change the port from A0 to A2, as following picture:
Explanation: this block will read the voltage value from ADC 2 pin(GP28) and give the value to light_value variable.
6)From Chip category, we add a print block below set value to block, right click and delete the ” “ block inside print block:
7)From Variable category, we add a light_value block to print block as following picture:
8) From Logic category, add an if_do_else block under print block as following picture;
9)From Logic category, add an 0=0 block under print block as following picture;
10) Click Variables category, add a light_value block to if block as following picture;
11) Change the “=”to “<”,add “0” block to if block, then change block value from 0 to 2, as following picture;
12)From Chip category, we add “turn pin 0 ON” blocks to “do” area, change the pin number from 0 to 15 as following picture;
13) Add “turn pin 0 ON” blocks to “else” area again .Change the pin number from 0 to 15 ,change the else area “ON” status to “OFF “status as following picture;
14) From Chip category, add a Wait 1 seconds block below if do else block, change wait time from 1 to 0.5 as following picture;
Now we have finished building the program, we can click START button to run the program.
When the Photoresistor is under bright light, the LED will turn off, when you use hand to shield light from the sensor, the LED will turn on. Is it similar to automatic street light in your city?
You can click the Console tag in the bottom, you will see the light_value is printed in the console, when light is blocked by your hand, the value is very small. as following picture.
DownLoad Url osoyoo.com