Sonic Ruler - Using the Arduino and Sensors As a Measuring Tape

by HDHORSMAN in Circuits > Arduino

102 Views, 0 Favorites, 0 Comments

Sonic Ruler - Using the Arduino and Sensors As a Measuring Tape

DSCF0130.JPG

This is an alternative to a measuring tape.


Basically, a quick rundown of this project is that the ultrasonic sensor shoots a wave (a 'Ping') at a wall and, using math, it figures out how far away that object is. The reason I chose this project is that nothing that I know of even exists in the mass-production, buy-at-the-store world and I think that if one of you reading this could find a way to mass-produce this, it would be extremely helpful to the entire working community as a whole.

Supplies

DSCF0135.JPG
DSCF0136.JPG
DSCF0137.JPG
DSCF0138.JPG
DSCF0139.JPG
DSCF0141.JPG
DSCF0142.JPG
  1. A laptop or computer (you probably own one of these already, because if you don't, how would you be reading this?)
  2. A ruler
  3. Some object of a medium size (I used a bubly can for this)

Really, you could just buy the Elegoo super starter kit (link here)for somewhere around $30-50 on amazon because it has the rest of these and more, but if you don't, you'll need these anyways:

  1. HC-SRO4 ultrasonic sensor - link here
  2. Arduino uno r3 circuit board - link here
  3. A USB cable that fits the Arduino (these usually come with it in the box) - link here
  4. Arduino IDE ( the coding software ) - link here (you probably need to download the legacy edition, because I don't think that the r3 works on the new edition.)
  5. 4 female-to-male Dupont wires - link here

Hook Everything Up

DSCF0143.JPG
DSCF0144.JPG
DSCF0145.JPG
DSCF0146.JPG

First, you need to plug the cable into your computer and the Arduino, and then you plug one of the wires into the left-most pin on the sensor (Vcc), and the other side into the 5v pin on the board. Next, you take another wire and plug it into the pin next to Vcc (Trig, or trigger pin), and the other end gets plugged into pin 12 on the Arduino. After that, you plug another wire into the pin next to the trigger pin (Echo), and plug the other end into pin number 11. Finally, you plug the last wire into the final pin on the sensor (Gnd, or the ground pin), and plug the other side into the ground pin next to the 5v wire. You should double- and triple-check this, because it is super important you get this right.

Coding It

DSCF0148.JPG

Once you've got that down, you need to code it, obviously. So, boot up that old Arduino IDE (seriously, though, why do we have to use the legacy edition?) and plug in the code in the pdf. A basic rundown of this is that the first part, void setup, sets up the program for the main code body, void loop, which is repeated over and over in a loop. Lastly, the int part tells the IDE where to send the code to. After this, you can click on the upload button, which sends the code to the board for use. As soon as it is sent to the board, it starts the system up and runs the code.

Downloads

Running the Code and Troubleshooting

DSCF0152.JPG
DSCF0154.JPG
DSCF0155.JPG
DSCF0151.JPG

Now that you've got it all set up, you can grab your object and the ruler, and put the object at whatever distance on the ruler you want (though I put it at 16 cm), and put the sensor at 0. An important thing to do is to put the edge of the grey part at 0 and not to put the board at 0. Click on the button in the top right corner that looks like a magnifying glass, which, if you hover over it with your mouse, is called the serial monitor, and clicking on that shows you how far away the object is. If it is at the distance you put it at (i.e., 16 cm), then you are good! Congratulations! If it is not, then it is probably the code, and you should redo the code. If it does not work at all, then it is probably the hardware setup, so you should redo step 1 for that. If it still doesn't work, then it is a code problem still and you should redo step 2.

Reflection

All in all, this project was a very cool experience because it was a very simple and interesting project, and I learned a lot more about how Arduino works and how to code better. Again, I hope very dearly that one of you will be inspired to create something like this in the mass-production world so the whole world would benefit from this, not just the people seeing this. And also, I would like to give my heartiest thanks to the code teachers and creators all over the internet, and also to the parents who inspire this interest in their kids. Finally, I would also like it if you would be kind enough to request any code upgrades or debugs. Also, if you have any ideas for upgrades, such as a screen or a case, then please leave a comment!

-HDHORSMAN