The idea of the assignment of this week is a tool to measure lengths remotely using the ultrasonic sensor.
This week's assignment is a more developed product of last week's involving more complex code and extra functionality and can provide more accurate readings.
The concept of measuring things remotely has been popularized recently in the AEC industry as it provides a faster and more convenient alternative to the old measuring tape, commercial product adopting this concept tend to work with laser beams instead of ultrasonic waves for extended ranges and more accuracy, however those devices are expensive so this is a less accurate, cheaper, not so convenient yet a more fun alternative.
Laser measuring tool used by an engineer to measure distances accurately and more conveniently
Materials used:
1x Breadboard
1x Arduino uno
1x 7-segment display
1x push button
1x Ultrasonic sensor
1x Servomotor
Resistors and jumper wires.
Software used:
Tinkercad for building the circuit and simulating it.
Arduino IDE
I started out by building the circuit in Tinkercad to make the sure I got the wiring and everything correct.
Then I started typing the code in the Arduino IDE
After verifying the code is free from syntactical errors by verifying it in the Arduino IDE it is time to test for logical errors in the tinkercad simulated circuit.
The circuit concept of how the circuit works in simple, the measurement of the ultrasonic sensor is taken, converted to centimeters, the tenths place of the number is displayed on the 7 segment display.
If the measurment requires more accuracy, pressing and holding the push button reveals the units place of the number.
The servo motor indicates the distance through it degree of rotation, where at 0 distance it is pointing up, and at 100 cm distance it is pointing down.
Simulated circuit in tinkercad
I started by building the same circuit I modelled on tinkercad and downloaded the code onto the arduino board.
Testing the circuit, the 7 segment display and the ultrasonic sensor.
Testing the accurate measurement mode enabled by pressing the push button.
Putting the circuit inside the enclosure.
Demo: using the rough measurement mode.
Demo: using the accurate measurement mode.
I don't know why this is the case but I found out that during debugging your eyes are totally blind to your own mistakes and an outsider eye is much better at picking out those mistakes, sharing code and asking what's the problem or why it doesn't work as intended is greatly helpful and it had helped my thoughout this project.
Well during this week I found out 2 very useful tricks to help beginners write code especially when dealing with complex components.
Tinkercad code blocks are an amazing tool to get read code for hard to write functions, I used it to convert the reading of the ultrasonic sensor to cm, which made contuing with the rest of the code much easier.
The arduino examples are a treasure of clearly explained code, I used it to understand how the code for the servo motor is written.
Other than those 2 my third advice is to start slow and test every piece of code on its own, it's a tideous process which takes tons of time but it saves you much headache in troubleshooting.
Coding coding coding, this week was full of it, this week gave my much needed practice on different techniques and I got kinda more familiar with arduino C and more reading for the final project.
Well I think the coolest I learned this week is how the serial monitor works and the concept of the baud, and why do people usually write 9600 in this feild, baud is the number of pulses per second and is used to transmit data serially between devices using only 3 cables, one for sending, one for recieving and one for grounding, faster pulses per second are usually better but beaware that some devices may not support it, some devices can be slow to handle it, and very fasts rates of transmissions can cause interferences.
I tried out this mini project in my free time, a device that helps you cheat on chrome's dino :""D