DIY Digital Spirit Level || Accelerometer Tutorial

The Importance of Spirit Levels and Accelerometer ICs in DIY Projects

If you have ever put up a shelf or similar structure, you are likely familiar with the concept of a spirit level. This handy tool is used to ensure that surfaces are level and plumb, preventing objects from rolling off or becoming unstable. However, many people may not be aware of the technology behind these levels or the challenges they pose when trying to achieve high precision.

One common issue with traditional spirit levels is the poor precision of the air bubble eyeball technique. This method relies on the air bubble remaining perfectly centered in the level, which can be difficult to achieve due to various factors such as gravity and movement. In this project, we will explore an alternative solution using accelerometer ICs to create a battery-powered digital spirit level.

The Selection of Accelerometer ICs

--------------------------------

When it comes to selecting an accelerometer IC for our DIY project, there are many options available. One popular choice is the MPU-6050, which can be purchased for just one dollar. This IC uses I2C communication and requires minimal setup, as we can use example code from the Arduino playground to interact with it. By connecting its power pins to a 5V and GND pin on an Arduino Nano and hooking up its serial clock pin to A5 and serial data pin to A4, we are able to read out the acceleration values.

Understanding Acceleration Values

------------------------------

So, what do these acceleration values represent? To understand this, let's create an imaginary level Y axis with our accelerometer IC in the middle. Gravity pulls our IC downward in the Z axis with an acceleration of 1 G (9.81 meters per second squared). When the IC is level, there is no acceleration in the Y direction, and thus the numbers shown on the serial monitor will be almost zero.

However, if we have an un-level surface, a part of the gravitational acceleration affects the Y axis. This means that by tilting the breadboard left and right, the serial monitor values oscillate around the zero point in the positive and negative range. The maximum number of plus or minus 16384 represents 1 G at a full scale range of 2 G, achieved when the angle equals plus or minus 90 degrees.

Creating a Serial Monitor Breadboard Spirit Level

-------------------------------------------------

By doing some code editing, we can already create a serial monitor breadboard spirit level. This is because there is a proportional relation between the acceleration values and the angle of the IC. By combining an accelerometer IC with complementary components and a 3D printed enclosure, we can create a prototype digital spirit level.

Adding a Small OLED Screen

-------------------------

To take our DIY project to the next level, let's add a small OLED screen to display the readings. This will allow us to see the values in real-time and get an accurate reading of the surface's levelness. We will secure the slide switch to the enclosure with small wood screws and glue the OLED display to the top side of the enclosure.

Designing the 3D Printed Enclosure

---------------------------------

To create our DIY digital spirit level, we need a custom-designed 3D printed enclosure that can hold all the necessary components. Using Fusion 360 software, we measure the dimensions of a proper air bubble spirit level and the required electrical components, including a small slide switch. We then design the upper and lower parts of our DIY digital spirit level model and slice it for 3D printing.

Printing and Assembly

---------------------

With our design complete, we can start printing the enclosure. Using brown PLA filament, which took around 6 hours to print, we determine that the prints are not half bad. We place the M3 and M4 nuts into their designated indentations and remove the support material. Next, we secure the male headers from the accelerometer IC with wires and attach it to the bottom part of the 3D print.

The Final Assembly

------------------

We wire up the rest of the electronics system according to our schematic. Once the wiring is complete, we secure the slide switch to the enclosure with small wood screws. We glue the OLED display to the top side of the enclosure and stuff the rest of the electronics into the housing. Finally, we connect both halves together using long M4 bolts.

Conclusion

----------

Our DIY digital spirit level project has been completed, and it works quite well. However, as with any DIY project, there can be inaccuracy problems due to warping during 3D printing or incorrect mounting of the accelerometer IC. Additionally, our device only works properly if held still and not accelerated by external forces.

A potential solution to this problem is utilizing the gyroscope component of the IC. This would allow us to create a more stable and accurate digital spirit level that can handle movement and vibrations. However, for now, we will leave this subject for another video.

Don't forget to like, share, and subscribe to our channel for more DIY projects and tutorials! Stay creative, and I'll see you next time.

WEBVTTKind: captionsLanguage: enIf you ever put up a shelf or something similarthen you should be familiar with a spirit leveland the concept of the air bubble.If not then here's a quick rundown.If your shelf is not level then duethen due to Earth's gravitational forcethe air bubble will not stay in the middleThat makes such a spirit level a handy tool the haveif you do not want your spherical objects to roll off your shelfall the time.But what always bothered me is the kind ofpoor precision of such an air bubble eyeball technique.So in this small project in order tocounteract this problem we will have a closer look ataccelerometer ICs in order to combine one of themwith a couple of complimentary componentsand a 3D printed enclosure in order to createour own battery powered digital spirit level.Lets get started.This video is sponsored by JLCPCBOne fact about them: JLCPCB hascurrently over 300,000 customers worldwide.and 10,000 online orders every day.Upload your Gerber files to orderhigh quality PCBs for low prices.When it comes to accelerometer ICs then the selection is quite big.What I initially wanted to use was this MPU-60503-axis accelerometerwhich you can get for just one dollar.To interact with it all I had to do was to wasto connect its power pins to the 5v and GNDpin of an arduino nano, and hooking up itsserial clock pin to A5and its serial data pin to A4This implies that the IC utilizes I2Cfor communication.Which traditionally means a whole lot of ICregister studying in order to control the IC.But since we live in the age of arduino, I ratherutilized an example code from the Arduino playground.Which after uploading to the boardand opening the serial monitor presented mea whole lot of different numbers.What we only care about, though, are those numberswhich represent the accelerationin the Y direction.But what does this acceleration actually mean?Well it is quite easy to understandif we create an imaginary, level Y axiswith our accelerometer IC in the middle.In this constellation, gravity pullsour IC downward in the Z axiswith an acceleration of 1 G, aka9.81 meters per square second.That means when the IC is level there is noacceleration in the Y direction. And thusthe numbers shown in the serial monitor are almost 0.But if we have an un-level surface, a part ofthe part of the gravitational acceleration affects theY axis. Which means that by tilting the breadboardleft and right, the serial monitor valuesoscillate around the zero point.in the positive and negative range.The maximum number of plus orminus 16384,which represents 1 G, at a full scalerange of 2 G, is then achievedwhen the angle equals plus or minus90 degrees.This way we have a proportional relation between theacceleration values and the angle of theIC. Which means that by doing a bit ofcode editing, we can already create a serialmonitor breadboard spirit level.And needless to say, such an accelerometerdoes also work in the X and Z direction.Your smartphone, for example, utilizes such an accelerometerto automatically rotate the screen.And if you want to dig even deeper and understandwhat MEMS are, and how an accelerometeris made up of them, then definitely check outAfrotechmods' video about the subject.But i'm getting off topic here. Right now we only gotprototype of a digital spirit level.So to turn it more into a proper tool, I addeda small 128x32OLED screen to the breadboard.Which i also hooked up to the I2C linesOf the Arduino.After adding a couple lines of code more tothe codes, by mostly relying on the AdafruitSSD1306 library, I wasthen able to output the calculated angle tothe display. Which revealed a small problem.As you can see, even without moving the breadboardthe angle value jumps around 0.5Degrees. Which is probably a noiseproblem.To decrease it I tried another similar IC.The MPU-9250.Which is slightly more expensive, but reducesthe noise down to around 0.2 degrees.Much better.To communicate with it I partly used codefrom lulu's blog and additionally addedthe line of codes in orderto deactivate the other accelerometer axisand gyroscope axis. In order to savea bit of power.this resulted in a total current demand of roughly25mA at 5V.Which with a LiPo battery capacity of1200 mAh should giveme run time of around 28 hours.To the battery I also added my homemadeLiPo charge protect boost circuit.To create a stable 5v for the circuitand being able to charge the battery.Feel free to watch the video about itif you are interested in creating your own.But of course adding all those components to a breadboarddoes not equal a spirit level.Since a breadboard is not very level to begin with.So, what I did next was measuring thedimensions of a proper air bubble spirit leveland the dimensions of all the requiredelectrical components. Including a smallslide switch which will beconnected to the battery circuit.With those measurements in mind I then createdthe upper and lower parts of my DIYdigital spirit level with Fusion 360.Afterwards I sliced the models and 3D printedwith brown PLA filamentwhich took around 6 hours in total.Once that was done, I removed the support materialdetermined that the prints were not half badand thus placed the M3 andM4 nuts into their designated indentations.Then i removed the male headersfrom the accelerometer ICand instead added wires to the boardand secured it to the bottom part of the 3D printwith M3 bolts.Last but not least, I wired up therest of the electronics system with some simple hookup wireaccording to this schematic.And of course, if you're interested in creating a similarproject, then you can, as always, find the codeschematic, and more information in the videodescription.Once the wiring was completeI secured the slide switch to the enclosurewith small wood screws,glued the OLED display to the topside of the enclosure,and stuffed the rest of the electronics into the housing.All there was left to do was to connect both halfsthrough long M4 bolts.And the project was complete.I have to say, it does work decently,but of course there can be inaccuracy problems.Due to warping during 3D printing or incorrect mountingof the accelerometer IC.And lets not forget that this digital spirit level onlyworks properly if you hold it still.and thus not accelerate it with your own forces.A solution to that problem would be to utilizethe gyroscope component of the IC.But, that is a subject for another video.Until then, don't forget to like, shareand subscribe.Stay creative, and i wll see you next time.