|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.
|1||Raspberry Pi Pico Board||https://osoyoo.store/products/raspberry-pi-pico-flexible-microcontroller-board-based-on-the-raspberry-pi-rp2040-dual-core-arm-cortex-m0-processor-1-pc?variant=39875307864175|
|3||Infrared Sensor Module||https://osoyoo.store/products/hc-sr501-pir-motion-sensor-for-arduino?variant=31957812838511|
|4||RFID Module and card||https://osoyoo.store/products/osoyoo-rfid-module?variant=31970646130799|
|5||Push Buttons and Hats||https://osoyoo.store/products/push-button-and-hats-5pcs?variant=39879253131375|
|6||LED(6 x White, 6 x Red, 6 x Yellow, 6x Green)||https://osoyoo.store/products/led-packs-for-arduino?variant=31957816442991|
|8||Piezo Buzzer Module||https://osoyoo.store/products/piezo-buzzer-module-1pcs?variant=39879251656815|
|9||I2C LCD Display(16×2)||https://osoyoo.store/products/i2c-lcd1602-display?variant=39875437101167|
|11||Solderless Prototype Breadboard||https://osoyoo.store/products/solderless-prototype-breadboard-1pcs?variant=39879255457903|
|12||Potentionmeter (10K adjustable resistor)||https://osoyoo.store/products/potentionmeter-10k-adjustable-resistor-3pcs?variant=39879281016943|
|13||40Pin M to M Jumper Wires||https://osoyoo.store/products/40pin-m-to-m-jumper-wires?variant=39879256539247|
|14||20Pin M to F Jumper wires 15cm||https://osoyoo.store/products/20pin-15cm-female-to-female-cable?variant=31930663305327|
DownLoad Url osoyoo.com