Authorized Online Retailers:

Buy from USA Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES Buy from JP

In last lesson, we learned how to read Analog data from ADC pin. In this lesson, we will   also read analog signal from ADC 2 pin.  But this time, the input device is a potentiometer(adjustable resistor) instead of  photoresistor.

We will also connect a Servo motor to GP16 which can generate PWM signal. The servo will rotate its arm when you rotate potentiometer.

Through this project, we will learn how to use Servo blocks to rotate servo arm.

  1. Raspberry Pi Pico board and microUSB cable
  2. A computer to run Thonny Python IDE
  3. Breadboard x 1
  4. Potentiometer x 1
  5. Servo motor x 1
  6. some jumper wires

In above circuit graph, you can see that:
Servo red wire connected to Pico Vbus pin(5V)
Servo brown wire connected to Pico GND
Servo yellow wire   connected to Pico PWM pin(GP16)
Potentiometer GND connected to Pico GND
Potentiometer VCC connected to Pico 3.3V
Potentiometer  middle pin connected to Pico ADC pin(GP28)

Making Blocks
Step 1: Create a New Project and Connect the Pico to Serial Port

1)Click New Project icon, you will see a My project icon with a fancy name will pop up. See Picture 2.1,
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:

3)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:

Step 2: Build   Graphic coding chips

1)Click Chip -> Start , then move Start chip to coding area as following :

2)Click Loops -> repeat while true and move this block  just below start block as following:

3) Click Variables ->Create Variable and  name the variable   servo_val as following:

4)Now you will see some new variable blocks, move the set servo_val to block inside repeat loop block  as following:

5)From Chip category, add a Read Voltage block to set servo_val to Block, change the port from A0 to A2, see following:

Explanation: this block will read the voltage value from ADC 2 pin(GP28) and give the value to servo_val variable.

6)From Chip category, we add a print block below set value to block

7)Right click and delete the ” “ golden block inside print block:

8)From Variable category, we add a servo_val block to print block as following:

9) From Logic category, add an if_do_else block under print block as following:

10) Add an “= “block in “if ” block as following:

11)From Variables category, add a servo_val  block in “If “block ,change “=” sign to “<"  as following:

12)From Values category, add “0” block to if block, then change  block value from 0 to 1 as following:


13)From Action category, we add  “serve pin set angle to” blocks to “do” area, change the pin number from 0 to 15, and change angle from 90 to 0 as following:

14) Right click the light purple area, duplicate a new if-do-else block, then insert the new block into the “else” ares , Change new if statement area from <1 to <2, change   set angle to area from 0 to 90 as following

15)From Action category, we add  “serve pin set angle to” blocks to “else” area, change the pin number from 0 to 15, and change angle from 90 to 180 as following:

16)From Chip category, add a Wait 1 seconds block below outer if do else block, change wait time from 1 to 0.5 , as following:

Now we have finished building the program, we can click START button to run the program.

Step 3: Test the program

When the rotate the Potentiometer, Servo arm will rotate accordingly.
You can click the Console tag in the bottom, you will see the console printing value is changing as long as you rotate the Potentiometer.

Learn More about parts SKU:2021005900

No. Picture Product Name Link
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
2 Servo motor https://osoyoo.store/products/micro-servo-sg90-blue-for-arduino-v2-0-robot-carmodel-lacc200610?variant=31648847560815
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
7 Servo motor https://osoyoo.store/products/sg90-micro-servo-for-arduino-raspberry-pi-robot?variant=31957821096047
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
10 Philips Screwdriver https://osoyoo.store/products/phillips-screwdriver?variant=31930635780207https://osoyoo.store/products/single-channel-relay-module-for-arduino-raspberry-pi?variant=31955954401391
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