Arduino Digital Level using Nano + MPU6050 Gyroscope/Accelerometer + OLED display

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
today we're going to take a look at building a digital level using an arduino nano and an npu 6050 gyroscope our device will be able to check that we are level in both the horizontal plane as well as the vertical plane known as plum and it will feature a rotating screen so as we move the level around the screen will rotate its display similar to what your phone does we'll also set up a menu so that we can calibrate and maybe switch modes without having to hook back up to a computer [Music] so what we're going to use for this project is an arduino nano the mpu 6050 breakout board an i2c oled display this one's 128 by 64. a switch for power two push buttons for the menus one to act as a menu and selector button one will set up to be the accept button you could power these with double a batteries if you want i'm going to add in a lithium 18650 cell because i have one laying around and with that a tm 4056 board for charging it also has a battery protection circuit in it so it will automatically cut off the battery when it gets too low and a boost converter to take our 3.7 volt cell and bump it up to 5 volts as well as a 3d printed enclosure that will house all of our components and act as our finished level product so let's check it out on a breadboard first so both the mpu 6050 gyroscope and the oled use i2c protocol so we'll hook both sda and scl lines to the arduino sda is pin a4 and pin a5 is your scl line and these are just hooked in parallel both going to the same sets of pins of course we need to supply 5 volt power to both boards as well and ground our buttons will hook up to pins 3 and 4 and we'll be using internal pull-up resistors with these so they are active low when a button is pressed the pin will be pulled low and that will be the sign in our software that the user has actually pressed the button now in my case i just had these two buttons laying around harvested from something else i took apart the mpu6050 was really cheap on amazon and came in a set of five the link will be down below in the description as well as the oled screen came in a set of three for just about 10 11 i'll also link that down in the description we'll look at the charging circuit and powering after we prove that this works on a breadboard we'll use the adafruit arduino libraries for the oled display and for the mpu-6050 we'll use libraries set up by jeff roberg that includes the firmware for the 6050 chip that can handle dmp and that's an onboard digital motion processing that kind of offsets some of the computing power to the 650 chip instead of on our nano and that will save us a little bit of coding complexity while at the same time the nano sketch will have to house all of the data for the firmware to push it to the chip with each boot up now there are two versions of the firmware that you can do with jeff's library i'm using the motion processing 2.0 because it is slightly smaller and the menus that i set up for the oled take up a lot of space but the newest firmware version is 6.0 where 6.2 is also included in the library but it's a much larger firmware and it's going to eat up too much space for this project the 6050 has three axises x y and z now with the chip in this position with the mounting holes at the top you have x rotating this way y rotating this way and z is kind of in the center coming out rotating around this way however when you change your orientation in our case to do level or plumb the device is meant to be working this way as a bar level would be so when you're checking if something is horizontally level it's not an x-axis as you would think in like a 2d plane you're actually rotating around the z-axis now and when you're checking plumb you're still kind of rotating around that z-axis so it gets a little confusing figuring out kind of where you are in the real world space and that took some time the code to figure out so let's load the sketch and see how this device works with our sketch loaded and the device powered up for the first time we can take a look at some of the features the screen will show the angle that we're currently at the two buttons will allow us to control some menu options the menu button also acts as select so press once to enter the menu press again to scroll through the options normal mode will always round the angle to the nearest whole number precision mode will show you one decimal place calibrate will allow us to calibrate the second button acts as an enter option to actually make your selection the menu also has a timeout so each time you press the button the timeout is reset but if you press nothing for a few seconds it will automatically exit back to the normal operation now to calibrate the device even though it's meant to work this way it needs to be laying down and horizontally on a already known level surface that is both level in this direction as well as this direction front to back so we'll go through the menu select calibrate the calibration menu has an exit and a start we'll choose start and once you see complete on the screen we are now ready to go so with our device calibrated move it into the working position which is meant to have the mpu-6050 board with the mounting holes towards the top and sitting in this vertical position so when it's on a level surface you'll get an indicator that shows level and as you move off of that it disappears so once you see the bar show at the bottom with the words level you know you're pretty good it's set to do plus or minus one degree so one and zero you'll see level as you move up to two and further that indicator goes away now as you rotate the device you'll continue counting your angle if we take a known 45 degree angle here you'll see we are dead on and as we continue to rotate to check for plumb your angle maxes out just about 55 degrees and then the screen will rotate and now you'll start counting back again towards finding level in the vertical which is called plum so again if we take our speed square and butt up against it we're just about there oh there we go this breadboard probably not the best thing to test with it's got little nubs at the bottom also the edges are kind of glued in and flexible so this will do much better in the permanent 3d enclosure so there we are and you can continue to rotate and the screen will flip around so right now we're completely upside down just like your cell phone would when you're watching a movie and rotating the screen so it's always basically in an orientation that's readable to you as you use the device now i coded it to make that angle cut off before rotating around 50 55 degrees specifically because when you're working with a level you're probably not using it to check anything more than 45 degrees in fact if you look at most bubble levels you'll see there is a horizontal bubble a plum bubble and then a 45 degree bubble so kind of kept in that same fashion but you could change this code to actually show you 0 all the way to maybe 180 or anything you would want to see on there so now that we've tested it on a breadboard and we know everything is working it's time to actually build it into its final enclosure so i designed this with the idea that the mpu6050 will sit on these two nubs mounted right about in the center of the level and also about in the center of the depth of the level but kept in the correct orientation the arduino nano will slip into this pocket here the lcd screen will will fit into the back recess of the cover plate as well as the two buttons so it will the screen will fit into the recess a little bit of hot glue in the corners will hold it in place and from the front side you'll have a nice clean view of the screen and easy access to the buttons now the one thing i forgot to do in this cover was make a place for a power switch to be able to turn the device on and off so i'll probably just cut one in or maybe add that in and print it again since it's just a small piece well speaking of power i want this to be mobile and modular so i have a bunch of these 18650 cells laying around so i figured why not make use of one of these it will sit and this recess down at the bottom connected to a tp40 56 charging board with regulator on it so that if the battery voltage gets too low it will automatically be cut off to protect the battery that will output to a small boost regulator and this will bump the 3.7 volts up to the 5 volts to be stable for both the nano the screen and the mpu itself now even though the mpu is a 3.3 volt device it does have an onboard regulator of 5 volts so it's a it's actually better to supply 5 volts to it to satisfy the regulator so you don't get too much of a voltage drop or any weird issues trying to feed 3.3 volts into it so i'll put this schematic up on the screen the parts that i'm using are really cheap on amazon i'll put links in the description below the schematic and wiring diagrams will also be on designbuilddestroy.com for you to grab as well as the source code so please see the links down in the description below so you can build this project yourself now getting back to this board will actually sit inside a slot down here and this i'm thinking is just gonna kind of fit underneath it so this board will actually go in first this one kind of wedged on top and the idea was at the top of the level there will be access to the usb charging port and also access to the arduino's usb port here so that i can update software do debugging whatever needed without having to disassemble the entire thing now even though the boost regulator has its own usb port we're going to be taking the output of the charger board applying that to the input of the boost converter and the outputs will be wired directly to our devices so let's get building this next part actually took about an hour and a half so i spit it up because i figured nobody wants to sit there and watch this but basically just follow the diagram connect the wires as you would on the breadboard i chose to solder everything in place so that it fits inside the case neatly and use some hot glue to keep things in their place if you found any of this interesting or helpful i would really appreciate it if you liked and subscribed if you want to see a more detailed video on how the actual code works let me know in the comments down below and if you have any questions leave them there too you can grab all the files and source code at designbuilddestroy.com and we'll see in the next video [Music] you
Info
Channel: Design Build Destroy
Views: 30,220
Rating: undefined out of 5
Keywords: Arduino, Arduino Nano, Digital Spirit Level, MPU6050, Gyroscope, Accelerometer, IMU
Id: 232jer4HIZc
Channel Id: undefined
Length: 16min 3sec (963 seconds)
Published: Mon Nov 02 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.