# Continuous Servo using Raspberry Pi Pico

**URL:** <https://forum.core-electronics.com.au/t/continuous-servo-using-raspberry-pi-pico/19943>\
**Category:** Support\
**Created:** [13 May 2024 16:52 UTC](https://forum.core-electronics.com.au/t/continuous-servo-using-raspberry-pi-pico/19943 "2024-05-13T16:52:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Erin271469](https://avatars.discourse-cdn.com/v4/letter/e/278dde/32.png) [@Erin271469](https://forum.core-electronics.com.au/u/Erin271469)\
**Post date:** [13 May 2024 16:52 UTC](https://forum.core-electronics.com.au/t/continuous-servo-using-raspberry-pi-pico/19943/1 "2024-05-13T16:52:23Z")

</div>

Hi! I am new to coding and am using a Raspberry Pi Pico to control a continuous servo motor. Using the guide from Core Electronics on YouTube I have been able to wire the servo and make it move with the code. Does anyone know how I can have the servo turn on for 5 seconds (clockwise) and then stop. Eventually I want to add a button to the circuit to carry this out when it is pressed.

---

<div class="post-metadata">

**Author:** ![Samuel](https://yyz2.discourse-cdn.com/flex028/user_avatar/forum.core-electronics.com.au/samuel/32/11763_2.png) [@Samuel](https://forum.core-electronics.com.au/u/Samuel)\
**Post date:** [14 May 2024 02:13 UTC](https://forum.core-electronics.com.au/t/continuous-servo-using-raspberry-pi-pico/19943/2 "2024-05-14T02:13:47Z")

</div>

Hi Erin, welcome to the forums!

Assuming you are following this guide:

> **[Getting Started with Servos | Examples with Raspberry Pi Pico - Tutorial...](https://core-electronics.com.au/guides/getting-started-with-servos-examples-with-raspberry-pi-pico/)**
>
> In this guide, we'll learn what a Servo is, when we might use one, how to choose a Servo, and finally how to use one with a Raspberry Pi Pico.
> To follow along you'll need:
> 
> A Positional Servo, such as the Feetech FS90 Micro Servo
> A Continuous...

The easiest way to do this would be to change the **while** loop to a **for** loop.

the **“while True:”** line will repeat the code inside it forever. If you add a second variable below your **“delay\_ms”** variable that looks like

_ **delay\_seconds = 5** _

you can use this to determine how long this loop will run for. Then you would change the while loop to a for loop so that it runs for a specific time like this.

_**for x in range((1000 \* delay\_seconds)/delay\_ms):**_

That for loop will take into account the approx. time each iteration of the loop is taking to complete and is calculating how many times the loop would need to repeat for 5 seconds to pass. then it runs the loop for this number of iterations.

As for activating this with a button, this is a super common task on a Pico and Raspberry Pi has some great documentation for how to achieve this here.

[https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/10](https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/10)

If you need me to explain this in more detail let me know! Feel free to share your code if you need help with specific modifications

Hope this helps. 😃  
Sam
