For this week's assignment, I had an idea about building a ROBOT that senses what's Infront of him, if there is somethings Infront, It will refuse the user order for moving forward.
I decided the main parts I will use will be:
Ultrasonic Sensor for distance measurement
Buzzer for alerts
Motor
Bluetooth module
H-Bridge
I always had interest in robots, and How it would be smart, I think this project will be a glimpse of what can be done!
I googled to find some inspiration and came across some cool robotics projects, Here are some pictures!
9v adaptor
Buzzer
Ultrasonic Sensor
Arduino Uno
Lots of wires
LM317
AVO For testing and troubleshooting
Crocodile Clips
gear motor
Breadboard
bluetooth module
H-Bridge
Tooth sticks
Glue Gun
Bottle cap
Thinker cad for designing the circuit
Arduino Bluecontrol
Arduino IDE
I started by defining the core function I want, which is wireless controlling my motor using a GUI and Bluetooth communication. I listed the required components and divided them into:
Input components:
Ultrasonic Sensor – To measure the exact distance of detected objects.
GUI input - my phone - using the Bluetooth module - and using Arduino bluecontrol on my phone.
Action components:
Gear motor - to move the robot.
Buzzer – Provides an audible alert when an object is detected.
Circuit components will be:
Arduino UNO – The brain controlling all operations.
Breadboard – For easy wiring and connections.
9V power adapter – To provide power to the circuit.
Bluetooth module - so that I can communicate with it using my phone
Lots of wires and crocodile clips – For connections.
LM317 - to convert from 9v to 5v
After gathering all the components and writing them down, I used Tinkercad to create a wiring diagram and plan the connections. Once I was confident in the setup, I started assembling the circuit on a breadboard and wrote the Arduino code to process sensor data and activate the outputs accordingly.
I couldn't find a Bluetooth module and I Googled, then I found a module called WIFI module, I used it, both wiring is the same.
Before wiring everything, I checked the datasheets for my component to confirm the correct connections. I also tested the sensors individually to make sure it was giving the expected readings before assembling the full circuit. ( divide and conquer) ;p
Find thinker cad link here : link
I started by assembling the circuit on a breadboard, following the plan I created earlier. Since I had already tested the individual components, I proceeded with wiring everything together. I ensured that each sensor and output device was properly connected to the Arduino and powered correctly.
I establishing the power rails on the breadboard, connecting the 9V Adaptor to the positive rail and the GND to the negative. This allowed me to distribute power across all components. that need 9v.
I needed to have another 5v power rail for the other components that need low power like Bluetooth module. so I used LM317 to do that, then I connected it's source to the rail.
Connecting the Input Sensor:
Ultrasonic Sensor: Connected VCC to 5V, GND to ground, Trig to pin 10, and Echo to pin 11. I used the sensor to measures distance and detects what's Infront of MY Robot.
I connected the Bluetooth module VCC to 5V, GND to ground, and I connected the TX and RX bins to the Arduino.
Connecting the Output Components:
Gear Motor is connected Through H-bridge, I wanted to be able to push the robot front and back.
Buzzer: Connected positive terminal to digital pin 6 and negative to ground. The buzzer will beeeb if the user asked the robot to go forward, and there is some obstacle Infront of him.
Programming the Arduino:
Once the wiring was complete, I moved on to the coding part. I wrote an Arduino C script: The logic:
I set up the pins for inputs and outputs, ultrasonic sensor (trigPin & echoPin), as well as other components like the buzzer, and relay module.
I Declared some variables for the ultrasonic sensor.
I used serial begin to establish serial communication to be able to give input through my phone and to get sensor readings.
if there is not serial comm. there will be nothing happening. I made sure to put it in if.
All the logic is if and else mainly.
Main IF is :
-IF the user pressed 1, and the ultrasonic sensor is reading more than 10 - it means that there is nothing in front of the robot, so it will move forward normally.
-IF the user pressed 1, and the ultrasonic sensor is reading less than 10 - it means that there is something Infront of it, so it will beeeb and move backward.
-IF the user pressed 2, the robot will move backward normally.
I used Chatgpt to generate this buzzer tone, it's awesome how capable it is in generating different tone types.
I also got this ultra sonic code form the Arduino Docs.
Annnnd here is the final Output:
I inserted this code that measures the distance of the ultra sonic at the end of my code, not before if condition. so basically it was working without knowing the distance.. that's way I keeeept going here and there to find what was missing.. it was so annoying not knowing XDDD
I discovered that by try and error, going back and forth to know what's wrong.
Also I had another Issue, I was that the dehavior wasn't stoping. I wanted the motor to play for second and stop, expect it wasn't!
I used gpt to check what was the error. I discovered I needed to clear the incoming data constantly after each loop.
adding incomingdata = 0 at the end, clearning the variable solved the problem.
IT will help me to integrate wireless communication to get Realtime data on my phone, or via WIFI like we learned in the green session from anywhere in the world, that's so powerfull.
I loved the Hackathon! it was so cool Fishing with something I assembled with my hands ith aurdino.
Amazing to get connected through WIFI! it awesome .. getting Realtime data from sensors it amazing to monitor stuff and I wanna incorporate it in my project using the esp32