Swinging Robot

Introduction: Swinging Robot

About: I do software and other stuff too.

This robot pumps its leg as a person does on a swing to get higher and higher. On board this simple rig is an Adafruit 9 degree of freedom accelerometer ( We only use one of the degrees though ), an Arduino Uno, a servo, and a "leg". The Arduino reads accelerometer data to decide when and how to pump the leg to gain height.

Step 1: The Science and the Code

I suppose that the principle behind swinging is that you want to continually get your center of gravity as high off the ground as possible. So, when you swing forward you outstretch your legs, and at the apex of your trajectory your feet and legs are high in the air. This gives you extra gravitational potential energy. When you go back you bend your knees, getting your legs as far back and high as you can.

The Arduino moves its leg with this principle in mind. When the accelerometer detects that it is moving backwards it has the legs tucked back. When it detects that it has stopped moving backwards and is now going forwards, it stretches the leg out forward so that at the apex of the trajectory the leg is high in the air. When it detects that it is no longer moving forwards, it tucks its leg back. In short, the bot acts just like a child on a swing does.

There was much to experiment with. The servo can only rotate so fast, so if the range of motion of the bot is small, the servo should probably rotate through small angles. If it tries to outstretch the leg fully while the period of motion is small, it won't be able to recover in time when the swing moves back. If the leg rotation is too small, not enough of a pulse will be given to move the bot. Also, what should the maximum and minimum rotation angles be in general?

The code is, as always, available on github for your inspection and use.


The libraries used are described here:


The code examples are incomplete, they don't show you the #includes you need and the constructors for the various objects used. If you look at my code you'll see the necessary includes and constructor calls. Or you can just do what I did and read through the library code real quick, it's not terribly long.

Step 2: Construction

The bot is very simple. There is an Arduino, a solderless breadboard, and a servo with a leg all attached to a thin plank of wood. The plank of wood is placed on some axis about which it rotate.

I just measured the thickness of the axis, cut out the arm and the axis thru-hole,

Essentially I wanted to keep this project barebones. I go to a Makerspace and we have lots of tools and materials and I didn't want to buy anything custom for this project because that would be a waste of all that's available to me. I looked through all the stuff we had at the space and decided that an old motor shaft would be the idea axis of rotation. That's because the shaft is on a bearing so it wont wobble out of the plane of swinging. Also, the motor weighs a ton so a light, swinging robot woudn't budge it.

We have a lot of thin wood at the space so I cut out the arm with a lasercutter. My buddy Paul had an accelerometer so I borrowed it from him. The Arduino and servo I had.

Step 3: Preliminary Runs

Here is the robot being tested and tweaked at home. It was working okay, so I brought it to the shop and tried to get it running for real.There the behavior was worse. I'd already run the robot for a while and the servo seemed to be getting worn out. It was vibrating and lagging in making the requested rotations. When I tried adding some weigh to the leg to get more momentum as shown in the video the servo complained.

Step 4: Future Work

This bot is, for all intents and purposes, a prototype. After showing that this works in principle, a natural next step is to scale it up, put the circuitry in a toddler looking toy, mount that on a swing, and make a real swinging plastic kid.

I need a more powerful servo that can rotate through the angles more quickly, or else to extend the pendulum so that the servo has more time through a single period to rotate.



    • Tiny Home Contest

      Tiny Home Contest
    • Creative Misuse Contest

      Creative Misuse Contest
    • Water Contest

      Water Contest