If you have to drill a certain depth for a project, you need a bench drill with depth display. Most bench drills have a ruler with an arrow for reading. The success of the drilling depends on how accurately you can read the desired position. In this Arduino project I present an alternative proposal: A drilling depth display with a gyro sensor and 7-segment display with Arduino support.
The machine I use most frequently in my workshop is not a saw or a grinding machine. It is by far the bench drill. Regardless of the project, it is actually always used. If I need a certain drilling depth, I can use the built-in ruler on the machine. And remember the depth to which I have to drill. It actually works well.
But with increasing age - yes, yes, yes - it becomes more and more difficult for me to read the depth with millimeter accuracy. And if the light is not bright enough, it is almost impossible to read it. But just put on glasses for this? And after drilling, where store the glasses? I am not that far yet.
True to the motto of Paul Akers from "2 Secon Lean":
Fix what bugs you!
There has to be a better solution, you just have think and make it.
Measuring PossibilitiesI could of course put a magnifying glass in front of the scale to make the ruler easier to read. It would improve the reading, but it wouldn't help that I have to remember the measurement in each case. And if you are doing handicrafts, it should be fun too.
That is why an electronic solution is much better. Preferably in a small space so that everything fits next to the on / off switch of the drill. For such cases I like to use an Arduino Nano. It has enough pins to control pretty much everything and is correspondingly small.
But how do you measure the drilling depth? There are several possibilities for a length measurement. Install an ultrasonic measurement? Could work, but only with a little mechanics, which move along with the drill as a reflection surface. Or use a wire-actuated encoder? Would be possible, but very complex, if you build it yourself: with a turntable, fork light barriers and spring return. Better to take a rotary encoder right away? That would mean a lot fewer components - yes, but it would be too coarse, you would have to install gears for a translation.
Ok, so think more about it.
My drill, like most, has a handwheel on the side to adjust the depth. It can be rotated approx. 270 °. So not even a full turn.
This is perfect for an angle measurement with a gyro sensor. The cable connection cannot twist and only one inexpensive component is required. The gyro sensor can also be attached very easily directly to the rotary axis of the handwheel.
ConceptI always proceed in the same way when specifying a drilling depth: scratch the surface with the drill, note the coordinate, then add the desired drilling depth and finally drill until the depth is reached.
I would like to keep the basic process. In order not to drill too deep, I would like to receive information about when the drilling depth has been reached.
A button takes over this function. When you press it, the Arduino saves the current drilling position as a stop value and can always remind me of it when it is reached later.
The remaining components, take up more space and weigh significantly more. Fortunately, the housing of my machine is made of metal. That's why I use a neodymium magnet to fix it.
The question remains, how should the sensor be attached to the machine?
The axis of the drill has an SW17 hexagon nut. So I only need a 3D printed component that accepts the sensor and can be plugged onto the hexagon nut.
- Arduino Nano
- Gyro sensor GY-521
- 7-segment module with 8 digits (SPI version with MAX7219 IC)
- Pushbutton
- On / off switch
- Power supply: battery clips for AA or AAA batteries or power bank
- 3D printed housing
- Neodymium magnet
The gyro sensor is connected via the I2C. So we have to use A5 and A4 for the Nano.
- VCC -> 5V
- GND -> GND
- SCL -> A5
- SDA -> A4
- XDA -> not connected
- XCL -> not connected
- ADO -> not connected
- INT -> not connected
Any digital pin can be used when connecting the 7-segment module. The pins are set using the Arduino sketch.
- VCC -> 3.3V
- GND -> GND
- DIN -> D12
- CS -> D10
- CLK -> D11
The input pin of the button can also be freely selected. I'm using pin D9.
Power supplyFor power supply I use 6 AA batteries. After the on / off switch, they supply the entire system with electricity.
CasingI designed the casing with Autodesk Fusion 360. I created the 3D print with an Anycubic i3 Mega.
The neodymium magnet for attachment to the machine is glued in. If the entire drilling depth display gets in the way, everything is quickly removed.
Arduino SketchI used the LedControl.h library to control the 7 segment display. If you have not yet installed these, you must first install them using the library manager.
The gyro sensor is connected via the I2C bus. When looking for possible libraries for the sensor, I then decided not to use any. Communication is via Wire.h.
At the end of the article you will find some links that helped me understand.
The control of the 7 segment display works very well with LedControl .
After the initialization with the pins, the setup procedure only needs a few preparations to wake up the display and adjust the intensity.
In the loop part, the display only shows the current drilling depth and, if set, the stop position, also as numbers.
The display expects each digit as a character type. I would like to use a decimal place as an accuracy. The function dtostrf converts a float into a character array. Then into a string to show it character-wise on the display.
dtostrf ( currentPos, 4,1, txt ) ;
s = '' + String ( txt ) ;
lc. setChar ( 0,4, see charAt ( see length () -1 ) , false ) ;
lc. setChar ( 0.5, see charAt ( see length () -3 ) , true ) ;
lc. setChar ( 0.6, see charAt ( see length () -4 ) , false ) ;
lc. setChar ( 0.7, see charAt ( see length () -5 ) , false ) ;
When the stop position is reached, "StOP" appears on the display. The small "t" can be generated using the setRow procedure and the appropriate bit pattern B00001111.
Reading out the gyro sensor works via functions of the wire library. I only use the accelerometer to determine the angular position.
When working with USB connection to the Arduino IDE, everything worked perfectly. After unplugging and connecting to the external power source, the sensor did not provide any data. It only worked again after a reset of the Arduino.
That gave me the most headache in the entire project. You could say that the drill depth indicator might have saved my eyes, but that is why I pulled out almost all of my hair!
After a long search, installing a waiting time after waking up the sensor was the solution. This makes the delay (1000) the most important command in the whole source code.
//prepare GY-521 sensor
//we use only accelerator data
Wire.begin();
Wire.beginTransmission(MPU);
Wire.write(0x6B);
Wire.write(0x00); // wake up MPU
Wire.endTransmission(true);
//this delay was very necessary in my case!
delay(1000);
Wire.beginTransmission(MPU);
Wire.write(0x1C); //register ACCEL_CONFIG
Wire.write(0x10); //Set as 00010000 for +/- 8g full scale range
Wire.endTransmission(true);
Offset values must be determined for the sensor at the beginning, otherwise the values will fluctuate. In the setup part, 100 values are measured and the deviations are averaged.
Calculating the angle from the sensor data is not that easy. But there are many instructions on how to do the calculations.
The X angle in degrees is calculated using this formula:
AccAngleX = (atan ((AccY) / sqrt (pow ((AccX), 2) + pow ((AccZ), 2))) * rad_to_deg);
However, the values of the acceleration sensor fluctuate greatly. Therefore, the currently calculated value is averaged with the previous value at 50% each.
TotalAngleX = 0.5 * TotalAngleX + 0.5 * AccAngleX;
The angle values are output from -90 ° to + 90 ° by the sensor. But I need an angle from 0 ° to 360 ° for the conversion into a drilling depth.
I haven't found a simple solution to this yet. For my application, however, it is sufficient to see whether the sensor data Z and Y are positive or negative. And convert the angle accordingly.
delta=0;
if ((AccZ<0)) {
delta=180.0-TotalAngleX*2.0;
}
if ((AccZ>0)&&(AccY<0)) {
delta=360.0;
}
DrillingMachineAngle=TotalAngleX+delta;
//if near 360°, display better 0°
if (DrillingMachineAngle>350) {DrillingMachineAngle=0;}
What is still missing is the maximum possible angle of rotation that the handwheel enables. The easiest way to do this is to have the determined angle output via a Serial.print and note the maximum value.
For me it's 316 °. With a maximum drilling depth of 50 mm, the current position is calculated as follows:
currentPos=50.0/316.0*DrillingMachineAngle;
If the button is pressed, the Arduino saves the current drilling position. 8888 is shown on the display and there is a short wait of 1 second.
If a stop position is set, the remaining drilling depth until the stop is shown on the right display.
Assembly and TestThe gyro sensor is best fixed with a point of hot glue. Guide the connection cables through the cover. That's it for this part.
In the first test, the gyro sensor must first be aligned. I installed it horizontally. Since the holder is designed to be rotatable, it can be easily adjusted until 0.0 is shown on the display.
Then the first test can begin.
Overall, I am very happy with the solution. The sensor reacts very quickly and the calculated values match the drill depth exactly.
And thanks to the large LED display, I don't have to worry about glasses up to 85 years old to read off an exact drill depth.
So always remember what Paul says: Fix what bugs you!
Have fun building it!
___________________________________________________________
Some maybe helpfull links:
https://medium.com/@kavindugimhanzoysa/lets-work-with-mpu6050-gy-521-part1-6db0d47a35e6
or https://playground.arduino.cc/Main/MPU-6050/
or also https://circuitdigest.com/microcontroller-projects/mpu6050-gyro-sensor-interfacing-with-arduino/
Library of GY-521 by Rob Tilaart: https://github.com/RobTillaart/GY521
And check out Paul Akers book on https://paulakers.net/books/2-second-lean
Das Projekt gibt es auch auf Deutsch unter: https://techpluscode.de/bohrtiefenanzeige-mit-gyro-sensor/
Comments