Friday, June 2, 2017

Keeping balance with a gyroscope




Intro

"I like to move it, move it! I like to move it, move it!"
If you want to measure movement, you probably will use one of these sensors. Why you want to measure movement anyway, you ask? Hey, who doesn't want to build a quadcopter? Or a self-balancing robot?
 There are 2 common senors, that will do the trick. The GY-61 (ADXL335) and the bigger brother the GY-291 (ADXL345).

The sensors

The GY-61 is the easier sensor to handle. It has VCC and GND and three analog outputs. One for each axis. You can read the sensor values with the analog inputs of an Arduino.
These are quite raw values. And even, when the sensor doesn't seem to move, the values does. So you have to program some method to smooth these values and probably a calibration routine, if you want to use it in a matter of a balanced project.
The GY-291 is a little different. It has an I2C bus. And I recommend to use the library, that is provided by Adafruit. If you're using the Arduino IDE, just search for ADXL345 in the Library Manager.



Video






Which sensor for which project?

Well the advantage of the GY-291 is, that you don't need to interpret the sensor values for yourself. The library does all the work for you. And it has a I2C bus. That means, you won't waste any pins on your controller. Because you can attach several devices to I2C, as long as they have different addresses. The smaller brother, the GY-61, doesn't need much code to operate. The sensor delivers it's values through 3 analog outputs. Well, at least it delivers something. You have to interpret the values for yourself. If you want to build something like a self balancing robot, I would recommend, that you build a small calibration routine. 
Both sensors costs about the same. 
For one of my next projects, where I want to use an ATtiny. Since the ram of this board is extremely limited and I just want to know, if the sensor is moving anyhow, I'll stick to the GY-61.

Links

Amazon

2 comments:

  1. hey,
    i am looking for a programming in arduino uno for a inverted pendulum using gyro sensor. can you please help me to solve this.
    you can contract me at stanzin14u@gmail.com

    ReplyDelete
  2. don't forget that you can re-assign the values using MAPs:
    MAP blah blah x( 1023, 0, 0, 1023 ) which will invert your findings.

    ReplyDelete