Raspberry Pi Pico Projects

Interface Servo Motor With Raspberry Pi Pico using MicroPython |

In this tutorial we are going to control an SG-90 Servo motor with  raspberry pi pico board, Servo motors are used in a variety of applications such as RC cars, drones, and robot arms. They are also used in industrial applications such as CNC machines and 3D printers. Servo motors have three wires:

There are many beginners suffering from the basics of the Raspberry Pi Pico Board. So I decided to start a series of articles discussing the basics of Raspberry Pi Pico Projects. Check out our Raspberry Pi Pico Projects Tutorials.

In this tutorial, I’m going to run only one Servo Motor. because the Code is only for one Servo motor. if you want to control multiple Servos motors then you have to change the code. If you understand code you will be able to control multiple servos.

Required Components 

  1. Raspberry Pi Pico
  2. Servo motor
  3. Jumper cable

What Is Servo Motor

SG90 small servo e1654500669269

A servo motor is a rotary actuator that uses feedback to control its angular position. It consists of a motor, a gear train, a control circuit, and a feedback mechanism. The gear train reduces the motor’s speed while increasing its torque. The control circuit monitors the position of the motor shaft and compares it to the desired position. The feedback mechanism adjusts the current to the motor, based on the difference between the two positions.

Schematic Diagram for Servo Motor With Raspberry Pi Pico

Servo With Raspberry Pi Pico

The schematic diagram is very easy To control Servo Motor With Raspberry Pi Pico please follow the circuit diagram.

Servo Motor —> Raspberry Pi Pico

  • PWM Pin —> GP0 Pin
  • VCC Pin —> 3.3V
  • GND Pin —> GND Pin

The Servo motor consists of three wires; red, brown, and yellow. Two wires are for VCC and ground and the third one is the data or control pin.

Source Code 

To program the Raspberry Pi Pico there is various development Software available (like uPyCraft IDE, Visual Studio Code, Thonny IDE, etc.) I used the Thonny IDE that supports Micropython on the Raspberry Pi Pico.

First setup Thonny IDE for Raspberry Pi Pico:-  How to Set Up and Program Raspberry Pi Pico

  • Open the Thonny IDE once it is successfully installed.
  • Choose the “for all users” option.
  • Connect the Raspberry Pi Pico board to your laptop.
  • To create a new project; go to Files > New.
  • Connect the Raspberry Pi Pico board to the laptop using a USB cable.
  • Click on the ‘MicoPython(Raspberry Pi Pico)’ option f
  • Select the interpreter for raspberry Pi Pico

Copy all the below codes and then save all of the codes on Raspberry Pi Pico Board.

  1. Click on the ‘save’ icon to save the program.
  2. After clicking on the ‘Save’, an option ‘Where to save to? can select any of the ‘Raspberry Pi Pico’ options.
  3. Run the program once it is successfully saved and compiled without any bugs.

myservo.py

 main.py

after uploading myservo.py myservo.py  it’s time to upload the main code, upload below code and

Conclusion

Raspberry pi pico with servo motor

When you run the code on the Raspberry Pi pico board, you will see that the servo is rotating from 0 to 180 degrees and 180 to 0 degrees continuously.

Read Similar Articles:

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Ad
Back to top button

Adblock Detected

Please consider supporting us by disabling your ad blocker