DIY Arduino Compass

by HarshadB9 in Circuits > Arduino

3659 Views, 10 Favorites, 0 Comments

DIY Arduino Compass

compass coverimage.png
IMG_0053.JPG
IMG_0050.JPG

We all know what a compass is and what is it used for. The compass tells us the directions i.e. E-W-N-S . Traditional compass worked with a magnetic needle in the middle. The needle's north pole always points towards earth's geographic north pole with is magnetic south.

The sensor I used MPU 9250 has a magnetometer which can measure the magnetic intensity along a given direction. I limited myself to X and Y axes only so simplify things a bit. Also as I mentioned in the video also, this project as an extension of the previous inclinometer project. Please have a look at the video and the article for the inclinometer. The links for provided are provided below.

LINK FOR YouTube

LINK FOR INSTRUCTABLES

Lets get started.

Watch the New Video

DIY Arduino Compass

This video covers a bit of theory of magnets, magnetic fields and some vector algebra. As mentioned earlier, this is an extension of the previous project. Please watch the other video in the introduction.

Components

FVDPT4PJTMSVFB0.LARGE.jpg
F6HFJ5OJTMSUVA8.LARGE.jpg

The list of components is fairly straight forward. A simple arduino, (Nano in my Case), MPU 9250 IC, and an OLED display to output the data. As usual, having the monitor is not mandatory but thinking of a laptop eveytime you want to test a surface might be a bit absurd.

I got the MPU 9250 from Ali Express for about $3.5. This is not the cheapest IC but the noise levels were considerably lower. I highly recommend this IC. There's nothing special about the arduino or the wood. Arduino is a clone and works great.

The wood and leveling of IC is not as important as in the inclinoeter project.

You have some room for error. CHILLAX!!!!!!!!!

The Structure.

F4XGXH0JTMSUWPF.LARGE.jpg
F8MTMSXJTMSUX49.LARGE.jpg
FEBQ1XGJTMSUWST.LARGE.jpg
FT3J3V2JTMSUWYJ.LARGE.jpg

For the main body, I took some simple square wood and cut it to a rough length of around 10cm. I then marked two holes in length of the IC. It is important that you fit the IC correctly. Also, if you do go wrond, please use some other side or even better, use another wood. Do not try to correct a missed hole. The screw may not hold good grip on such hole.

I then cut female headers on appropriate lengths and pasted them with two component adhesive. Once everything fit in place, I was pretty happy with the looks.

Wire It All Up

FA9C9JYJTMSUWPC.LARGE.jpg
FJVYSVBJTMSUV2W.LARGE.jpg
FT3J3V2JTMSUWYJ.LARGE.jpg

With the I2C protocol, the wiring is always easy peezy.

I then started tinning the wires and the female headers. The wiring is very very simple.


SDA- A4

SCl- A5

Vcc- 5V

GND-GND

Make sure that the wiring connections are secure and proper. Make sure you used enough length of wire.

I made this mistake and trust me, it is very frustrating.

Programming

FOH9UNSJTMSUXAU.LARGE.jpg

There where the two twin project take on different paths.

The library is the same. Download the same library.

The GitHub link-

https://github.com/bolderflight/MPU9250

Having a look at the serial monitor, it was clear that the values were much more out of phase. I did some testing and finally could produce some decent sine function.

I have provided one of my excel sheets. Check it out if you are interested.

Sine wave is beautiful, isn't it?

Enjoy the Project.

IMG_0052.JPG
IMG_0051.JPG

I you didn't get the repeating joke in my video, don't take this compass camping with you. Always use trusty instruments. for both reliability and ease of use.

Anyhow, I liked this project.

If you enjoyed, consider liking and subscribing to my instrutables and YouTube channels.

Thanks a lot.!