Skip to content

Category: arduino

MPU-6050 easily get x y z values tutorial

Hello, a few weeks ago I started working on a time tracker project. And one of the vital components was an MPU-6050 gyroscope, I needed a tutorial to get the x y z values. And I found many tutorials on it. But whenever I tried them I had a lot of problems noticeably with drift. The drift means that the readings were not stable at all. After 30 seconds some values had quadrupled even though the card itself was still. So I found a lot of answers that told me “yeah this is a common problem”. But not really any help in solving it. So here’s a full MPU60-50 tutorial from start to finish that I wish I had when I wanted to use it.


The wiring is pretty straightforward :

  • VCC to the 5V pin
  • GND to ground
  • SCL to the A4 pin
  • SDA to the A5 pin
  • INT to the 2 pin

The other pins are not useful for the most of the use cases. If you are interested nonetheless or want to know more about this chip I encourage you to read the documentation here :

MPU 6050 wiring on an arduino UNO board
MPU 6050 wiring on an arduino UNO board

Reading the x y z values

Now that the wiring is done, it’s time to move onto the actual software. In order to get the x y z values we need to be able to read the raw values, there are a ton of tutorials on how to do that. But ultimately it’s not that useful as you need to make calculations on it for these values to really have meaning. After digging quite a while and trying out various tutorial like this one I realized that, while it’s quite interesting to make everything from scratch, when you want to build things quickly, it’s often better to use a library from someone who’s spent much more time than you on the problem.

Also none of those tutorials seemed to handle the part where you’re supposed to calculate offsets and calibrate the damn thing. And if you don’t calibrate it, you most likely will run into problems sooner or later.

The MPU6050 tockn library

Github user tockn created this awesome library called MPU6050_tockn (leave him a star if you can). Which does pretty much everything for you. Better yet, it’s available on the arduino library manager. So it’s extra easy to download it.

Screenshot of the arduino library manager with the MPU-6050_tockn library selected

Go ahead and download the library (I’m using 1.5.2). And now load up this code :

#include <MPU6050_tockn.h>
#include <Wire.h>

MPU6050 mpu6050(Wire);

void setup() {

void loop() {
  Serial.print("angleX : ");
  Serial.print("\tangleY : ");
  Serial.print("\tangleZ : ");

After a few seconds of loading you should get this :

Serial monitor with X Y Z data
Serial monitor with X Y Z data

Success ! Keep in mind that you might still encounter drift issues especially on the z parameter. Also once your offsets are calculated, use mpu6050.setGyroOffsets(x, y, z); rather than calculating them each time. It’ll allow for a faster startup and less chances of you messing up the offset calculations by unintentionally moving it.

And that’s it for this tutorial on how to get x y z values on the MPU-6050. Feel free to leave a comment if you have any questions. And if you want to dig deeper, there is another example with more data from all the elements on the board (accelerometer/gyroscope and temperature) here.

Building a time tracker using arduino and blockchain tangletime part 1

This is my first try at IOT, in this series I’ll be using the IOTA blockchain and arduino to build a time tracker and take you along for the ride 🙂

Blog banner, with "tangletime part 1" as header and "Building a time tracker using arduino and blockchain" as subheading

For a whole year I’ve been working full time on my own projects, namely SteemPress and more recently my blog ! And I really like to optimize my time. But without reporting, it’s pretty hard to really know what to work on. I tried to just use my phone timer to try to see how long I was doing various things (reddit/code/email/etc). But when I’m focused on various things, I often forget to start/stop it. And it also ment that I had to do a lot of reporting by hand. Which was a pain. So I figured that I would be building a time tracker using arduino and blockchain.

Here’s the project idea : I want to build a small cube/hexagon or a polygon (I’m not sure on the number of sides I want on it yet). So that if I put it on a sides for an activity. Let’s say coding. It’ll start a timer that will only stop when I put it on another side. Technically I am always doing something so there shouldn’t be a need for a “doing nothing” side.
Here’s a few ideas for sides that I had :

  • Programming
  • Gaming
  • Sleeping
  • Grocery shopping
  • Reading/replying on slack/emails/discord
  • Reddit-ing
  • Going out

Arduino for the time tracker hardware

Arduino is one of, if not the most accessible platform to build hardware on. It’s basically lego mindstorms on steroids. There are tons of tutorials in every possible form imaginable and tons of compatible parts that you can buy everywhere. I advise you to find a local shop and go to them to talk about your project. They will be able to give you advice and prevent you from buying tons of hardware that is ultimately useless for your project.

This was also a prime opportunity for me to start working on it since I’ve been wanting forever to work on some hardware things. And create more internet of shit (great twitter account, highly recommend that you check him out).

Why blockchain ?

If you know me (or read my github) you’ll quickly notice that I work a lot with various blockchains. So I like to see how blockchains can improve things. One big issue that I have with IOT products is the fact that it only works until the people behind it continue to run their server. So you pay 50 euros for hardware that might at any moment turn off. And I don’t want this kind of stuff. Another thing is that I want to have control over my data and not have a random company be aware of pretty much all of my activities.

The IOTA blockchain

Disclaimer : I have a small stake in IOTA

The IOTA blockchain is one of a few blockchain that’s designed for IOT usage, some would argue that it’s not a blockchain and they would be kind of right : It’s a tangle. I’ll pass the details but long story short it has super fast transaction times, transactions are free (as long as you validate other people’s transactions). Since it’s one of the biggest cryptocurrencies, there’s a lot of support online on how to do IOT with it.

I’ve been wanting to do a small projects to test out that blockchain in real conditions so this sounds like a perfect use case. And this means that :

  • It’s decentralized : No need to run a server to host the data
  • Anyone can run a web app to display the data. If Alice doesn’t like the default setup she can go online and make her own or try the one that Bob put online.

I believe that for an use case like this, the hardware is not the limiting factor : it’s the software, what graphs you do, how you extrapolate on the data that’s important. And If this can be made open for anyone to hack, and anyone can have their own custom dashboard with exactly what they need. This would be really cool.

“Yeah you don’t give your data to a single company, you give it to everyone instead”

Not really because if I control what I send and how I send it, I can easily put encrypted data or just send like “activity 1” instead of “programming” (Sleep would be relatively easy to spot though, so encryption might be in order). But this is far down the line.

The plan

So there are four big parts to this project. First I need to make a proof of concept using hardware, just a very basic thing using gyroscopes that displays the orientation, send that using bluetooth to my computer or phone.

Then the second phase will be saving all of that on a local database and building a basic dashboard, most likely in the form of a phone app.

Then for the third phase I’ll add blockchain support. And if everything still holds together I will buy a pcb board, the smallest Arduino that I can find. Solder everything together, 3d print my cube/polygon and actually have my finalized product.

So hang on for the ride, consider subscribing if you haven’t already to get notified when I’ll publish the next part of this series.

And before we finish I got a question for you all. If I made this, would you be interested in downloading files to create your own ? Or if you are not really the tech type, to buy a pre-assembled one ?