Arduino Pathways: How to Make Informed Decisions

My initial encounter with Arduino through this assignment marked my first independent experience. Reflecting on the challenges I faced during the in-class tutorial, I harbored reluctance towards reengaging with the breadboard. Consequently, I made an early decision to opt for a more uncomplicated circuit. While exploring the Arduino kit’s components, the IR remote and sensor piqued my interest. Subsequently, after conducting online research, I stumbled upon a circuit and corresponding code that appeared relatively simple and easy to understand.

At first, my plan involved activating particular colored LEDs upon pressing specific numbers on the remote. To proceed, I entered the given code into the Arduino software for verification before constructing the circuit. However, as a preliminary step, I needed to install an IRRemote library and designate it for use. Among several similarly named packages, I opted for the first one that appeared. After downloading the IR library, I attempted to verify the code, only to encounter an immediate error message.

At this juncture, I confronted a consistent challenge throughout this task: comprehending the coding language required. The Arduino code is scripted in C++, a programming language with which I haven’t had the opportunity to acquaint myself. My proficiency in computing is primarily centered around MATLAB, hence the syntax used in Arduino coding was unfamiliar to me. Consequently, the error message proved to be less than informative. Seeking assistance, I approached one of my housemates, a Mechanical Engineer experienced in Arduino projects. Regrettably, he too was unfamiliar with the IR remote/sensor library, rendering him unable to diagnose the issue. Opting not to invest more time in deciphering and rectifying the IR remote code, I made the decision to employ a less intricate sensor system instead.

SHIFTING GEARS – DISTANCE SENSOR

In my quest for a fresh project idea, I turned to YouTube. Spending approximately an hour immersed in various videos such as “Arduino for Beginners” and “Easy Arduino Projects,” I discovered that learning through tutorial videos was far more accessible than deciphering instructions on the Arduino Project Hub posts. A recurring theme among beginner project videos was the utilization of an ultrasound sensor for distance measurement. This led me to concentrate my research on videos demonstrating circuits for measuring distance using ultrasound sensors. While several tutorials employed digital displays to showcase sensor data, I stumbled upon one video that transmitted this information to the serial monitor within the Arduino software.

As outlined in the video, the sensor emits an ultrasound wave at a specific frequency, and by analyzing the duration of the wave’s round trip, the distance can be calculated. This process includes configuring the pulse duration while considering the speed of sound, set at 340 m/s. Following the wiring diagram demonstrated in the video, I established the fundamental circuit for measuring distance.

Having established the circuit, my focus shifted to programming the distance sensor. I made sure to connect the echo pin of the ultrasound sensor to Arduino’s pin 10 and the trig pin to pin 9 on the board. During a previous tutorial session, I had encountered an issue by not accurately specifying these pins in the Arduino code. Hence, I was determined not to repeat the mistake. While the instructional video provided the code, I opted to comprehend it rather than simply copying and pasting as I did with the IR remote.

The code initiates by defining the Arduino pins 9 and 10 as the Trig and Echo pins, respectively. In the setup segment, the Trig pin is configured as an output, and the Echo pin as an input. Additionally, the code incorporates a serial function to display sensor readings on the serial monitor. Within the loop section, the code handles the states (low or high) and measures the duration of the ultrasound waves, followed by distance calculation. The code’s output is then transmitted to the serial monitor using the serial print function.

Upon successful verification, I proceeded to upload the code to my Arduino setup. To confirm its functionality, I accessed the serial monitor and positioned my hand in front of the sensor. Fortunately, the sensor accurately measured and displayed the distance from my hand, operating precisely as intended. The recorded distance from the sensor was presented in centimeters.

THE NEXT STEP – PROXIMITY SENSOR

To add a personal touch to the distance sensor circuit, I opted to integrate an LED configuration similar to what we covered in our classroom tutorial. My concept involved activating a green light when an object exceeds a specific distance from the sensor and a red light when the object gets closer than that threshold. Thus, I placed a red and green LED, each accompanied by a 330-ohm resistor, onto the breadboard. I connected the positive leg of each LED to digital pins 2 and 3 on the Arduino board.

Ultrasound sensor circuit with LEDs added in

I proceeded to develop the code responsible for illuminating the LEDs based on the readings from the distance sensor. The class example demonstrated this functionality with temperature readings, prompting me to adapt that code for a different sensor. Initially, I configured the pin modes of the LEDs as outputs in the setup section. Subsequently, I formulated an if-else loop: when the distance reading exceeded 10 cm, the green light’s output would be set to high and the red light’s output to low. Conversely, if an object was within 10 cm, the loop’s else statement would trigger the opposite LED settings. To enhance the impact, I interconnected a buzzer in series with the red light, enabling it to emit a sound when an object approached within 10 cm of the sensor. This coding setup completed my proximity sensor project.

Final Arduino circuit for the proximity sensor
Arduino coding for the Proximity Sensor

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top