Introduction: A Simple and Very Easy Inverted Pendulum Balancing Robot

Picture of A Simple and Very Easy Inverted Pendulum Balancing Robot

Let's make a simple inverted balancing robot, and operate it.
You need only half a day to do them, if you have an arduino and some materials.

[a video of a robot you would make]

After a few work with arduino, I have thought of making an inverted pendulum. Then I had two policies for the project.

  • simple as possible
  • bootstrap (without referring to website)

Though they has been kept (*1), it has demanded more than whole a week to make my robot balance itself. So simplicity of my robot seems to be held in its body, circuit and program (called "sketch"). It has only an analog gyro-module (at $4 (*2)), two plane motors (at $1.5) and two analog ICs (at $1.5) to drive these motors.

(*1) I have referred websites for two matters; a formula for inverted pendulum and a troubleshooting the gyro-module I used.
(*2) 100 JPY = 1 USD I use as exchange rate.

A solderless breadboard in a picture above would show its simplicity. And a video thereunder shows it works well enough.

One who has made a LED blink with arduino ever could assemble her/his inverted robot in half a day or less according to my recipe below. But I think it is similar to solving a puzzle to make it balance on its wheels. Thus I show a solution in three steps not to spoil a puzzle. I wish videos and pictures could cover my poor English.

* A Japanese version of this instructable is available also.

** Additional information, Aug. 20 2014:
A simpler alternative program, ver2.0, has been available in Step 5.

*** Another version has been published later, in which a digital output gyro sensor produced by STMicroelectronics is used instead of two analog output sensors. It is easier to get the digital gyro outside Japan. And the fine soldering in Step 2 is not required for the digital gyro.

Step 1: Gather Materials

Picture of Gather Materials

Body (using TAMIYA's Educational Construction Series)


[tutorial for Step 1]

[commentary 1]
I have felt that analog gyro-module listed above has individual difference. So I think it better to purchase two or three modules together. And as showing in Step 11, an additional module could make robot work more stably.

[commentary 2]
If it is hard to get the gyro-module listed above, similar one with the same analog sensor (ENC-03R) might be substituted. For example a module sold online would be available. (Its price is near 4 times to Akizuki's one.) Though it seems to have op amp, the factor scale to amplify I cannot find.

Step 2: Solder Wires to Some Components

Picture of Solder Wires to Some Components

First you should solder wires to some electrical components.

  1. solder wire to each point of 2 motors (4 points in all)
  2. cut 4 jumper wires in half (8 half jumpers gotten)
  3. solder these half jumpers to 8 wires of 2 motors and 2 battery snaps
  4. cover each point soldered with chip of tape for insulation
  5. solder header pins to an Akizuki's gyro-module
  6. solder a fine wire to either point of a capacitor "C6" on this module

[tutorial for Step 2]

[note 1]
An Akizuki's gyro-module listed above has 2 analog gyro-sensors on its surface. Either sensor is "ENC-03R" made by Murata-seisakusyo. Only one of them is used for inverted robot. This sensor outputs 0.67mV per unit angular velocity (1deg/sec) and it is amplified to ten times with a op amp on the reverse face of the module. (Vo at pin 1 of this module is 6.7mV/dig/sec.)

But this module picks up not only angular velocity but also angular acceleration by its filter (HPF). Capacitor C6 on this module is a main element of HPF. To avoid picking up the latter, soldering a wire to this capacitor is done.

Step 3: Assemble a Body of Robot

Picture of Assemble a Body of Robot

To build a body of inverted robot, TAMIYA's Educational Construction Series are used.

  1. make two V-shaped cuts to a Universal Plate
  2. attach 4 L-angles included Universal Arm Set to this Plate
  3. assemble Double Gearbox to make its gear ratio 114.7:1
  4. mount 2 motors with 4 wires to this Gearbox
  5. attach this Gearbox to Universal Plate above
  6. assemble Slim Tire Set (two 55mm Dia. wheels gotten)
  7. attach these wheels to shafts of Gearbox above

[tutorial for Step 3]


Step 4: Put Electrical Components Together

Picture of Put Electrical Components Together

Put electrical components together and attach them to the body built in the former step. Then a robot without program is gotten.

  1. referring to a picture of breadboard above, plug a gyro-module and two motor driver ICs at your breadboard
  2. wind some rubber bands around the breadboard and attach it on the lower L-angles of body of robot
  3. according to a wiring diagram above, plug jumper wires at the breadboard
  4. and plug either wire of the battery snap which would be connected to a 4AA battery holder
  5. wind a small rubber band around arduino and attach it on the upper L-angles of body of robot
  6. according to a wiring diagram above, plug jumper wires at arduino
  7. insert four AA batteries to 4AA battery holder
  8. wind a bigger rubber band around the body of robot and fix the battery holder to the back side of robot

[tutorial for Step 4]

[note 2]
The robot gotten here has no power switch. To turn on (off) power, battery snap is connected (disconnected).

Step 5: Upload a Sample Sketch to Arduino

Picture of Upload a Sample Sketch to Arduino

Using IDE a sample Sketch for inverted robot is uploaded to arduino.

  1. if you cannot find MsTimer2 library in IDE, install it from website(*)

    (* Another simpler sketch, ver2.0, has been available since Aug. 2014. It does not need MsTimer2.)

  2. connect arduino to PC via a USB cable
  3. disconnect the battery snap from 4AA battery holder
  4. lay down robot on desktop or floor and leave at rest
  5. download(*) a pdf file attached at the last line in this step (* you get a corrupted program if you open this file in web browser and copy its contents)
  6. open the file in proper reader and copy the whole of text in the file
  7. paste the copy to IDE and correct misprints
  8. upload corrected sketch to arduino using IDE

[note 3]
To make an inverted pendulum balance itself, motor torque is controlled dynamically. This control method is expressed as a plane formula with 4 variables related to the state of pendulum.
"motor torque = k1 * angle of pendulum
+ k2 * angular velocity of pendulum
+ k3 * velocity of the lower end of pendulum
+ k4 * displacement of the lower end of pendulum from a reference point"

k1,k2,k3 and k4 are static coefficients with appropriate values. In a sample sketch in pdf file below, a long equation at line 72 expresses this formula. To make inverted robot balance itself, we have to select proper values for these 4 coefficients respectively and know right value of each of these 4 variables in real time.

A gyro-sensor gives the second variable value, angular velocity of pendulum, dynamically as a voltage at its output pin. And arduino estimates the first variable value, angle of pendulum, contemporaneously by integrating the second variable.

On the other hand, the third or the fourth variable value cannot be measured by gyro-sensor. So another kind of sensor or meter should be used to get them in real time. But our inverted robot has no more device than a gyro-module. Thus it becomes a puzzle to estimate these 2 variables values dynamically. In a sample sketch in pdf file below, 2 masked equations at lines 76 and 77 should be used to estimate them. Here they are left masked not to spoil solving this puzzle.

[note 4]
If some other gyro-module than listed one in Step 1 is used, 2 constants at lines 10 and 11 in the sample sketch in the pdf file would be changed. These constants express k1 and k2 respectively in the formula above. For example if an ENC-03R, gyro-sensor on listed module, is used without op amp, input voltage to arduino becomes 1/10 times. Then the constants at lines 10 and 11 in the sketch should be change to ten times scale respectively.

[a sample sketch (program) for inverted robot]
Copy whole text of "invertedRobot.pdf" or "invertedRobot_v20_noTimer.pdf" below, paste it to IDE and upload it to arduino.

(*1) With some language parameters on the site, an icon of the pdf file is not shown below (at the end of line of this step). Then you should type "" in address bar of your browser or refer a Japanese version of this Instructable.

(*2) Save the pdf file in your PC and open it in proper pdf-reader. Or you get a corrupted program by opening it in web-browser.

(*3) If "; //72" is not shown at the end of a equation at line 72, substitute whole a equation below for it.
powerScale = ( kAngle * thetaI / 200 ) + ( kOmega * omegaI / 78 ) + ( kSpeed * vE5 / 1000 ) + ( kDistance * xE5 / 1000 ); //72

(*4) Pasting the copy to IDE or editor, misprints such as "/ /" as "//" (an obstacle space inserted) might happen, then correct them.

(*5) An analog gyro-module used here is influenced by temperature. If your robot cannot balance itself well in summer, constant values (45, 85, 57) at lines 10 to 12 in the original sample sketch "invertedRobot.pdf" should be changed such as "52, 95, 53" (added on Aug. 20 2014).

(*6) A simpler alternative sketch "invertedRobot_v20_noTimer.pdf" has been added as ver.2.0 on Aug. 20 2014. Though it does not contain timer library, MsTimer2, for interrupt handling, it could make robot balance better.

(*7) Copyright (C) 2014 ArduinoDeXXX All Rights Reserved.

Step 6: Get an Inverted Following Robot

Picture of Get an Inverted Following Robot

After a sample sketch uploaded to arduino in the former step, you ought to get an inverted following robot. Though it needs your finger for standing, it follows your finger.

  1. leave robot still laid for 5 seconds after the upload finished (see picture 1)
  2. hold the body of your robot and pick it up (see picture 2)
  3. connect battery snap to battery holder fixed on the back side of robot
  4. wheels of robot start spinning
  5. hold both wheels tight and stop spinning (see picture 3)
  6. set both wheels on desktop or floor and keep static standing to be made center of gravity of robot to be located on its wheel shafts
  7. after a few second motor torque becomes down and faint noise or chirping "miii" is listened
  8. then release your hands from robot gently (see picture 4) and put your finger on the top of the body of robot softly
  9. move your finger forward and backward and see your robot following
  10. release your finger and see your robot trying to balance but failing

[tutorial for Step 5 and 6]

[note 5]
The signal voltage, which the analog gyro-sensor used here outputs in static state, is not set in advance and is not constant. It depends on conditions and drifts over time. Thus after turning on or resetting arduino, do not touch robot and leave it laid for 5 seconds. During the seconds arduino estimates the signal voltage in static state now.

[note 6]
After the seconds in note 5, as picking up the robot it perceives state changing and spins its wheels. Then the robot has to study proper posture (angle of its body) in well inverted state. This robot is programmed that if it has been in static state for 0.05 seconds it deems itself well inverted.

Hence as picking up the robot and its wheels starting spinning, you should hold both wheels tight and stop spinning. And execute Step 6 since its line 6.

Further if you do not feel changes at line 7 in Step 6, torque down and faint noise of motors, for 10 seconds, arduino might have failed the estimation in note 5. Then you should push reset button on arduino to stop wheels spinning. And after pushing the same button again, execute Step 6 since its line 1.

[troubleshooting 1]
If wheels of robot do not start spinning at line 4 in Step 6, some faulty wiring must be suspected first. Go back Step 4 and verify wiring carefully. Another doubt is a defective gyro-module. Indeed the module I have used first was it.

On the other hand, if your robot does not follow your finger in spite of wheels starting spinning at line 4 in Step 6, four kinds of faulty wiring must be suspected: (1) wires of a motor are set opposite, (2) gyro-module is set reversed, (3) wiring to digital pins of arduino is wrong or (4) analog pin is unplugged. Go back Step 4 and verify wiring carefully.

Step 7: Challenge to Solving a Puzzle

Let's make your "following inversed robot" balance itself without your finger by modifying the sample sketch in Step 5. It might be a puzzle.

  1. consider why it fails balancing
  2. get plausible idea and modify the sample sketch
  3. make your inverted robot try balancing
  4. if it balances itself you have solved a puzzle and your robot has become an inverted pendulum (congratulation!)
  5. or else back to line 1 or hesitate to see a solution in Step 8

Step 8: How to Get an Inverted Balancing Robot

Picture of How to Get an Inverted Balancing Robot

Here you see how to get an inverted balancing robot. You need to modify only two lines in the sample sketch in Step 5.

  • copy 3 lines below and paste them over lines 76 and 77 in the sample sketch (overwriting them)

vE5 = sumPower; //76a
xE5 = sumSumP / 1000; //77a
// Copyright (C) 2014 ArduinoDeXXX All Rights Reserved.

  • execute Step 6 (without a finger support in lines 8 to 10)
  • if center of gravity of robot is located on near its wheel shafts, your robot moves back and forward for a few seconds and gets well inverted posture
  • see it keeps balancing itself
  • if it moves with forward or backward bias, add to or submit from proper integer after "power" at the end of line 74 in the original sample sketch

[tutorial for Step 8]

[troubleshooting 2]
If your robot can not balance itself well in spite of executing Step 6 well, “low battery” in the battery holder on the back of robot should be suspected first. If it is not observed, constant values at lines 10 to 13 in the sample sketch should be changed. I think that line 12 is most critical.

Step 9: Operate Inverted Robot Via Serial Monitor

Picture of Operate Inverted Robot Via Serial Monitor

Now you have an inverted balancing robot. Then let’s control it by serial monitor. You could make it turn right/left and go forward/back.

  1. update the modified sample program gotten in Step 8 according to the details below
  2. upload the updated one to arduino using IDE
  3. after the upload end, start serial monitor from IDE
  4. select ‘Newline’ and “115200 baud” at bottom right of serial monitor
  5. leave robot still laid for 5 seconds
  6. make inverted robot balance itself according to Step 6 (without a finger support in lines 8 to 10)
  7. input numerical values in upper left window of serial monitor and push the [Enter] key
  8. see action or change of action of your robot

[tutorial for Step 9]

[note 7]
You can control your robot dynamically by serial monitor from PC via USB cable. For example you input "00" in window of serial monitor and push the [Enter] key, then robot receive ‘0’ and ‘0’ separately. Hence it turns right at a regular angle below twice without stopping.

  • a ‘0’ sent makes robot turn right at a regular angle on the spot
  • a ‘1’ sent makes robot turn left at a regular angle on the spot
  • a number (n) of ‘2’ sent make robot accelerate forward in proportion to the number (n)
  • a number (n) of ‘3’ sent make robot accelerate backward in proportion to the number (n)

[an update on the sample sketch (for 4 places)]

(1) Copy the following 5 lines and paste them between lines 17 and 18 in the modified sketch gotten in Step 8.

volatile int drct = 0;
volatile boolean right = false;
volatile boolean left = false;
volatile int fwdBck = 0;
// Copyright (C) 2014 ArduinoDeXXX All Rights Reserved.

(2) Copy the following 26 lines and paste them over line 32 in the modified sketch gotten in Step 8, viz. substitute these lines for “if ( power > 0 ) {”.

if ( Serial.available() ) {
drct =;
if( drct == 48 ) { right = true; }
else if ( drct == 49 ) { left = true; }
else if (drct == 50 ) { fwdBck++; drct = 0; }
else if (drct == 51 ) { fwdBck--; drct = 0; }
if ( right == true ) {
analogWrite( 6, 140 );
digitalWrite( 4, HIGH );
digitalWrite( 5, LOW );
analogWrite( 9, 140 );
digitalWrite( 7, LOW );
digitalWrite( 8, HIGH );
} else if ( left == true ) {
analogWrite( 6, 140 );
digitalWrite( 4, LOW );
digitalWrite( 5, HIGH );
analogWrite( 9, 140 );
digitalWrite( 7, HIGH );
digitalWrite( 8, LOW );
} else if ( power > 0 ) {
// Copyright (C) 2014 ArduinoDeXXX All Rights Reserved.

(3) Copy the following 4 lines and paste them between lines 55 and 56 in the modified sketch gotten in Step 8.

drct = 0;
right = false;
left = false;
// Copyright (C) 2014 ArduinoDeXXX All Rights Reserved.

(4) Copy the following 2 lines and paste them over line 74 in the modified sketch gotten in Step 8, viz. substitute these lines for “sumPower = sumPower + power;”.

sumPower = sumPower + power + fwdBck * 4; // 74a
// Copyright (C) 2014 ArduinoDeXXX All Rights Reserved.

Step 10: Unplug the Cable

Picture of Unplug the Cable

Substitute a buttery (9V) for USB power (5V) for power supply to arduino. Then arduino is unplugged and your robot stands with no outer wire.

  1. eject a USB cable from arduino
  2. connect the second battery snap to a battery (9V)
  3. attach the battery on the back of robot by rubber band with a battery holder 
  4. plug the positive wire of this snap to Vin pin of arduino
  5. plug the negative wire of this snap to GND pin of arduino
  6. your robot starts spinning its wheels if the first snap is connected to battery holder
  7. make your robot balance itself according to Step 6 (without a finger support in lines 8 to 10)
  8. see it stands with no outer wire as a completed inverted pendulum

[tutorial for Step 10]


Step 11: Develop Robot Further

Picture of Develop Robot Further

Let’s make your inverted robot or your knowledge evolve further. Here three ways are shown briefly. It would be hard to finish the second or the third way within half a day.

(1) Double Sensors

Add another gyro-module on the breadboard of your robot and investigate whether its stability in balancing is improved.

[a record of a robot with double sensors]

(2) Remote Operation with No Wire

In Step 9 your robot is operated via USB cable. Now your robot is unplugged. So let’s operate it with no wire. In terms of simplicity, an infrared module would be the first choice.

[a demonstration of operating robot by a TV remote]

(3) Simulating the Action of an Inverted Robot with Excel

Our inverted robot could be thought constructed from three parts: head, body and wheels. In this simplifying, an equation of motion of the robot can be written with a physics learned at High School. As getting it, the action of robot can be simulated using Excel. The near-proper values of two coefficients in note 3 in Step 5, k1 and k2, could be gotten by this simulation.


ChevassuT (author)2017-05-31

Hi ArduinoDeXXX,

I have some troubles to understand your
program, even if I have read a lot of comments and all your steps.
First, I don't understand why do you calculate integrated value of the
angle like this : theta = theta + OmegaI and not like this : theta =
theta + OmegaI*dt. Then, I can't understand how you choose constant
values k1, k2, k3... I read that you used a Excel sheet to find them,
but could you please explain me more precisely how did you do ?
Moreover, I don't use any of the gyro you mentionned (a gyro of seed :
ADXL345). Could you explain me please how to choose the constant value
you are using here (the one which depends on the temperature) ?

Thanks for your help.

ArduinoDeXXX (author)ChevassuT2017-05-31

1) That's a natural question. Variable “dt” you tell is included implicitly in coefficient “kAngle” in the sample sketch, because it can be thought constant.

2) The values of these coefficients are decided finally by trial and error. An equation of motion of the robot or Excel sheet for it is an advanced topic.

3) I posted another article to get a self balancing robot where a digital output gyro module, a L3GD20 carrier, is used instead. It is easier to get this module if you are a resident outside Japan.

ChevassuT (author)ArduinoDeXXX2017-06-01

Thanks for your response !

I'm making another self-balanced than the one you did, so I have some different connections and components. I try to adapt your method to it and it works almost well. But, even if it is an advanced topic, please could you just explain me your approach ? Do you use Excel in order to solve a differential equation and test constants values ? Or do you calculate several forces such as gravity one and you try yourself to adapt value in function of it ?

ArduinoDeXXX (author)ChevassuT2017-06-01

> Do you use Excel in order to solve a differential equation and test constants values?

Yes, I use Excel to get an approximate solution.
However I don't intend to explain the detail here, sorry.

MitchS26 (author)2017-02-06

I have a SMAKN gyroscope with an ENC-03RC sensor which I believe is the same as your ENC-03R sensor. The one thing I do not see in your instructions is what the pins on this module are. The module I have is seen below. Which wires will I put where?

ArduinoDeXXX (author)MitchS262017-02-07

I found a web site for your gyro module, and saw a schematic attached.

It seems that “C1” in it works as “C6” in my gyro module. Hence you may have to invalidate “C1”. See Step2.

Though I do not know your module well, I think you should connect “VCC”, “GND” and “OUT” in your module to “5V”, “GND” and “A5” in Arduino UNO respectively. However “REF” is connected to none.

See the earlier comments and pictures of xgiantsios and my replies to them to know more.

MitchS26 (author)2017-02-01

I have a MPU 6050, which pins would I have to connect to make this work? The pins on your diagram are not listed for which pins are voltage, ground, and signal.

ArduinoDeXXX (author)MitchS262017-02-01

An analog output gyro module is used in this project, though MPU6050 is a digital output module. Another digital output gyro module, L3GD20 carrier, is used in the later version of this project. See “*** …..” in the bottom part of Introduction above.

DylanM71 (author)2017-01-30

Whay gyro module can be used? The link in comment 2 is no longer available. I am trying to compile my list of part now.

ArduinoDeXXX (author)DylanM712017-01-31

I cannot understand well what you tell. Sorry. I think you may know more in the later version of this project. See “*** …..” in the bottom part of Introduction above.

IliasS5 (author)2016-10-24

Hello, could you please post the schematic of cabling for the robot functioning. Thank you in advance!

ArduinoDeXXX (author)IliasS52016-10-24

See the top picture in Step4.

the07ruben (author)2016-05-25

how can we get code of this robot??

ArduinoDeXXX (author)the07ruben2016-05-25

See Step5 in this article. And click “invertedRobot_v20_noTimer.pdf” attached to the end of the step.
Now another version has been published. See the end of Introduction in this article.

Poltom (author)2015-11-20

Yes sorry may be a was unclear !

to begin i try to drive the DC motor .

I can use the sketch of this projet as a basis ?

ArduinoDeXXX (author)Poltom2015-11-20

At the start of your project I think you had better learn using both motor driver IC and gyro-module you have. Search with the model number of the IC or the module as key-word in the web. You could get the basics with adequate information.

The Arduino sketch attached in this article presupposes using specific IC and module described in Step1. I do not recommend you to start with this sketch if you want to make not inverted robot but camera gimbal.

Poltom (author)ArduinoDeXXX2015-11-23

Thank you again for your precious help ! ( i informing me about my component)

You said that it is very difficult to drive a BLDC it mean that each user of gimbal are using a specific board to drive it ? like Alexmos ? we can't recovered the same kind of code ? ( sorry for the english .. )

ArduinoDeXXX (author)Poltom2015-11-23

I do not know such topic well because I want to make One-off by my own efforts. I enjoy myself to solving puzzle without seeing answer.

I search with “open source project brushless gimbal” and find a related web-site”brushless-gimbal-BruGi”.

In any case a simple inverted robot with cheap brush DC motors is described here, not brushless gimbal.

Poltom (author)2015-11-18

hi it's me again!

I'll start as you advise it by learning how to drive DC brush motor.

some questions :

if I understand the system: the engine is running at maximum speed here?

HIGH or LOW commands are given to the motor drivers, and it sending the right PWM motor?

this program is not used to control the frequency of the PWM?

could we send message to the motor drivers to control the pwm? (to control engine speed)

with your gyro angle you recover the value or the angular velocity?

thank you !!

ArduinoDeXXX (author)Poltom2015-11-18

Did you describe brushless gimbal in your earlier mail messages I have received? Have you changed article or posted wrong one carelessly? The reply below is written keeping your earlier message about BLDC in mind.

ArduinoDeXXX (author)Poltom2015-11-18

Hi, I get your open comment now.

> HIGH or LOW commands are given to the motor drivers, and it sending the right PWM motor?

I attached three sketches to rotate BLDC via Arduino. See Step6 and 10. In the first one of them, “digitalWrite( pin , HIGH or LOW)” is used to generate square wave. There is no PWM in it.

> the engine is running at maximum speed here?

If “engine” means BLDC motor, none of these sketches drives BLDC at the maximum speed.

> this program is not used to control the frequency of the PWM?

We can change frequency of PWM pulse. See the earlier comment from EricL50. But it has little effect to the single axis brushless gimbal described in Step10.

> I'll start as you advise it by learning how to drive DC brush motor.

If you do not have enough knowledge, information and skill about Arduino to rotate motor and to use gyro-module, I think that you had better try to control standard “blush” DC motor with driver IC first, and next to get angular velocity with using gyro-module.

AnveshA1 (author)2015-11-17

will this code works with ADXL335 accelerometer too?

ArduinoDeXXX (author)AnveshA12015-11-17

I have posted two instructabes in English. Each of them shows how to make simple inverted pendulum robot. One who wants to make it can download PDF file in Step5 freely. It contains whole of code to make robots balance itself.
The code should be applied to the robot with gyroscope. The robot with accelerometer instead of gyro would require hard correction in the code.

AnveshA1 (author)ArduinoDeXXX2015-11-17

can you please tell me what should I scaled my accelerometer values to get my robo balanced?

ArduinoDeXXX (author)AnveshA12015-11-17

I have not made any inverted robot without gyroscope. Hence I do not have the answer to your question. Sorry.

AnveshA1 (author)2015-11-10

can i use AdXL335 only to balance the robot, can you please share me the code


ArduinoDeXXX (author)AnveshA12015-11-10

AdXL335 seems to be an accelerometer. I think that though it is not impossible to make a self-balancing robot with only an accelerometer, it would be very hard to do it. The robot with a cheap gyroscope could balance itself more easily.

Another version of this article has been posted. The whole code in pdf file is shared in Step5 in it. You can download it and you could get a digital output gyroscope made by Pololu on line.

May I use the MPU 6050 instead the k-04912?

I have posted another version of this instructable in Japanese site. Here a digital output gyro module similar to MPU 6050 is used
instead of analog output module K-04912. You could see it in English or others with machine translation of your browser.

nswaminathan (author)2015-03-15

I appreciate the effort you have put into your project, and your intention of sharing your knowledge with thers.

kwonhoon (author)2014-12-31

Thank you so much for a nice instructions!

I followed your instructions with the same materials, and code

but I have some problems, help me plz

1. my wheel only rotate in one direction

that means...

if I tilt my robot in front, wheel does not response, anything!

but if I tilt it in back, wheel works. what's wrong??

I checked directions of motors and wires many times..

Is there a possibility that the problem of gyro module?

When I soldering C6 in gyro module ( the exactly same

model with yours), it it too small that I cannot solder it clearly..

2. Plus at STEP6, after I upload code in Arduino,

and connect battery, the wheels does not rotate like yours.

My one only react to when it is <tilting in back>

And when I connect a battery snaps to batterys, an arduino reacts

(sounds like miii~) but the wheel does not move until I tilt it.

3.I cannot understand some parts of your code,

for example, what is chkAndCtl(); , recOmegaI , zeroOmegaI

and countS ??

there are so many questions.. sorry ^^..

again, it was really nice instructions and I really appreciate you.

happy new year!

ArduinoDeXXX (author)kwonhoon2015-01-01

Happy new year!

I have got many comments with successful cases in the Japanese version of this instructable. But none in this English version. I guess the difference would be due to a difficulty to get the gyro-module used here outside Japan. Now you have the same model of this module. Good!

When we take into account your Point1 and Point2 (in Step6), it seems that little power is supplied to motors just tilting in front. I think your gyro-module would work. If so, wrong wiring or misprint in sketch is suspected.

I have got a similar comment to yours with failure case in Japanese version from tokumikatu. To her/him I asked to capture and show time series of two state variables. Can I ask you to capture them?

(1) Use the sketch in "invertedRobot.pdf" in Step5.

(2) Keep comment-out in line 76 and 77.

(3) Add the 3 lines below between line 75 and 76.




  //vE5 = ??? //76

  //xE5 = ??? //77

(4) Upload this sketch to Arduino.

(5) Open serial monitor and select "115200 boud".

(6) Tilt your robot in front to 90 degrees and back -90 degrees gradually.

(7) Copy series in serial monitor and paste it to some text editor (*1-3).

(8) Save it as a CSV file and open it in MS Excel.

(9) Draw line graphs using two series in Excel.

  (*1) select all: "Ctrl"+"a"

  (*2) copy: "Ctrl"+"c"

  (*3) paste: "Ctrl"+"v"

tokumikatu uploaded the graphs. So she/he put all components again from the beginning and got a good robot.

To your Point3:

chkAndCtl...check and control,

omega...a Greek character represents angular velocity,

omegaI...input value in proportion to omega,

recOmegaI...recorded value of omegaI,

zeroOmegaI...input value for omega at rest,

countS...number of observations at near rest in balancing.

vasoula (author)2014-08-18

hello I have some issues here.. I have this gyromodule but I cant understand how you find the variables and the k coefficients can you expain this to me please? Thank you

ArduinoDeXXX (author)vasoula2014-08-18

Hi vasoula I think that the past comments and replies could help you.

(1) The formula in note 3 in step 5 is found in many website. See "(*1)..." in the introduction of this Instructable first.

(2) An interpretation of this formula as "PID control" has been shown in a reply to BigMigbelow. And it is described in a reply to Erik_D how to decide the values for 4 coefficients in this formula.

(3) A gyro module in a website you told looks like the same model of aristos92's and a near model of xgiantsios's below. So I recommend that you would see their comments and my replies.

tmoir (author)ArduinoDeXXX2014-12-12

I expect you are using state-feedback by the look of the equation but you give little information. If it is state-feedback then your gains are found from some matrix algebra. If it is state feedback then it isn't PID, it is PD however. It's too vague for me to comment without a decent diagram with angles etc.

ArduinoDeXXX (author)tmoir2014-12-12

Hi I think you are right in the sense of linear system theory. It is easy to find the formula used in Step 5 on the web. It could be interpreted as a two-variables-PD, if we got these two variables dynamically.

But here we can observe only one of them, angular velocity. The other should be estimated by exploiting it. This is a puzzle described in Step 5. And I show an answer in Step 8 as an indirect integration of observed one.

Though the original formula in Step 5 is two-variables-PD, a modified formula gotten in Step 8 could be interpreted as single-variable-PID. This is the point of the reply to BigMig. There I don’t use “PID” in its strict sense. I am glad to know what call this modified one in strict sense in the theory.


To select values for 4 coefficients in the formula in Step 5, I have made Excel analysis first. There I have relied on numerical method without using the analytical method or solution. See the end of Step 11.

ArduinoDeXXX (author)2014-08-19

[Additional information, Aug. 20 2014]
A simpler alternative program, ver2.0, has been available in Step 5. Though it does not contain timer library, MsTimer2, for interrupt handling, it could make robot balance better.

xgiantsios (author)2014-05-08

Hi i have this gyro module which capacitor is for the HPF?

Can you tell me?

ArduinoDeXXX (author)xgiantsios2014-05-08

Without data sheet of your module, I have no correct answer. I can just tell you where is pin 4 of ENC-03 sensor on your module (circled in red line). In a sample schematic for ENC-03 sensor, the capacitor for HPF is connected to pin 4 of the sensor.
It seems that 3 capacitors, C2, C3 and C5 are near pin 4 on your module. Pattern on its either face might tell you more information. (As seeing a picture in the site, C3 seems to be most plausible.)
Incidentally, the sensor is set at right angles to line of header pins on your module. So some improvement would be needed to be set it parallel to the line. For more detail see the 2nd reply to peraz91 below.

I find an easy way to know the capacitor
for HPF.

If HPF in your module is based on a sample
schematic for ENC-03 sensor. This capacitor is connected to pin 4 of the
sensor. So a simple continuity check between them tells us which is the
capacitor for HPF.

I have executed this check using a
multimeter and known it in practice.

xgiantsios (author)ArduinoDeXXX2014-05-22

i did it but it doesn't work again

ArduinoDeXXX (author)xgiantsios2014-05-22

I got it. I would like to know several points about your gyro-module.

1. Which capacitor is used for HPF on your module?

2. How did you know it to be used for HPF?

3. How did you attach the module to be right position to your robot?

4. Can you upload pictures below?

(a) Close-up picture(s): soldered a fine wire to the capacitor for HPF on your module

(b) Portrait(s): whole body of your robot with gyro-module on a breadboard

xgiantsios (author)ArduinoDeXXX2014-05-23

i found it with a polumeter

ArduinoDeXXX (author)xgiantsios2014-05-23

Thank you for pictures. It seems that a fine wire is soldered to capacitor 2 (C2) and a breadboard is set in portrait orientation (not in landscape) from the front, OK?

If it is set in portrait orientation, your gyro-module is set correctly. But I cannot say any correct about HPF, because I don't know whether capacitor 2 is an element of HPF. (I don't know polumeter, sorry.) I could tell some check points.

(1) Do wheels start spinning at 1:07 in tutorial video for Step 5 and 6?

(2) Do wheels change its direction of spinning as tilting robot front or back at 1:09 - 1:14 in the video above?

(3) Is a faint noise "miiii" is listened at 1:14 - 1:24 in the video above?

(4) Are wheels still stopping as battery snap is connected and arduino is reset at 1:10 - 1:30 in tutorial video for Step 8?

If some answer is 'No', faulty wiring or failure or malfunction of gyro-module should be suspected.

xgiantsios (author)ArduinoDeXXX2014-05-22

I have cancel the HPF but it doesn't work again

aristos92 (author)2014-05-07

Hi ArduinoDeXXX i have this gyro module and i can't make it works with it. I paste the code and it moves arround like crazy...I use the x -axe.

Can you help me?

ArduinoDeXXX (author)aristos922014-05-07

Hi aristos92
Please let me know some points. First,

(1) Is your module "2-Axis Analog Gyro Module-ENC03"?

(2) Is a small black chip, an op amp like 'LM358', attached on the reverse face of your module?

(3) Do you have a data sheet of this module (not of a sensor) with 2 sensors and an op amp?

(4) Have you cancelled HPF in this module in the way like described in Step 2 of the Instructable?

aristos92 (author)ArduinoDeXXX2014-05-07

(1) & (2) Yes. I don't have the data sheet and i could't find it so i haven't cancel HPF filter .

About This Instructable



More by ArduinoDeXXX:ミニビーストを卓上ペットにするTraining Theo Jansen's Mini STRANDBEESTA Levitating Sphere Rotates Glows and Blinks with Arduino
Add instructable to: