Go Down

Topic: Using GY-521 Accelerometer + Gyro (Read 37660 times) previous topic - next topic


I used the datasheet(s) as a framework to set up a basic sketch.
The idea is that if the code has been proven to be okay (it is), someone might use it to extend it and put it in a class.

So all the defines are the registers and the bits in the registers. I named them the same as in the datasheet(s).
You have to keep the datasheet next to it, to know what it is about.

But that is not all, there are also undocumented registers.
If you take a look at the code by Jeff Rowberg, you see he has more registers.


Oct 17, 2013, 02:25 am Last Edit: Oct 17, 2013, 03:57 am by gebell Reason: 1
[EDIT: problem solved.  It *was* a lose connection.  On to the next problem I can't solve . . . thanks to anyone who contemplated my problem.]

I am having this exact same problem, but I'm at a lost as to how to 'fix' it.  

I run the scanner and get no devices found.  I switch the connection to go to the board's dedicated SCL and SDA slots, but it didn't fix it.  

I'm really at a loss, any thoughts, ideas or suggestions would be really appreciated.

I am very much a noobie at all this.  

could it be as simple as a loose connection?

Some pictures of the setup:


hiii gebell,

how u calibrate your sensor?mind to share :)


Ich bin leider neu im Arduino. Ich frage Euch deshalb, weil ich mir gedacht habe, dass Ihr vielleicht etwas wissen würdet, und zwar  habe ich einen Arduino Uno und einen Gyrosensor den GY-521. Ich mache gerade eine Diplomarbeit über einen Fitnesstracker. Die Aufgabe ist es, dass wir den Gyrosensor z.b. auf den Handglenek tragen und das halt bei jeder Bewegung ein Signal rauskommt. Ich habe mir auch die Wire Bibliothek angeschaut, weiß aber trotzdem nicht, wie ich einen Code schreiben soll, damit ich so ein Signal herauskriege. Könntet Ihr mir helfen, indem Ihr vielleicht ein ganz einfachen Code  schicken, wie man das programmiert oder irgendwie sagen könntet, was ich machen muss.
Danke und mit freundlichen Grüßen



du bist hier im falschen unterforum.. bzw musst du hier in die deutsche Sparte um solche Sachen zu fragen. Schätzte jedoch dass es bereits zu spät ist um dir noch zu helfen wenn das überhaupt noch ginge, wenn nicht schreib doch mal im deutschen Forum

I just told him, that he has to move to the German Part of the forum, if he wants an answer on a german question.


P.S. to the hint that the R3 has it's own IC2 ports... :D I had this problem myself too ......... ^^


So here is a quick info for GY-521 to work with Arduino Uno R3 for I2C scanner

Arduino     gy-521
Digital pin 2 ===> INT

Once this setup is completed, write the following code in the I2C setup function

pinMode(A4, INPUT);
pinMode(A5, INPUT);

Now you'll definitely see the I2C device being scanned. Else you will have to pull all the hair from your head :)


I will add my experience in case it is helpful to someone.  I also had trouble getting my Arduino to recognize the GY-521 at all (and then, when I first got it recognized, I would get the error code = 2).

Like appears to have been the case for a couple others here, my troubles all turned out to be due to poor connections.

Using a breadboard, I set up my pins as other have outlined here, but could not get I2CScanner or anything else to recognize the sensor.  Eventually with much jiggling of wires and pin/connections, I was able to get the Arduino to intermittently recognize the sensor - but I was now getting "error code = 2" and bad readings.  I also noticed that the LED light on the GY-521 was weak and pulsing, which didn't seem right.

Eventually I chucked the breadboard and connected the sensors directly (i.e., no breadboard, just pins right through the holes on the GY-521), and everything works - a nice steady bright LED on the GY-521, no error code, and readings that appear to be accurate.

Not sure if the GY-521's connections are finicky, or if it was just my lack of experience.
Hope that is helpful to someone!

Go Up