This week aimed to Build and Program a smart circuit using an Arduino UNO which reads a signal from an input component to control an action component .
so I wanted to make ultra sonic sensor as input and motor as output. because it would be used in my graduation project.
software:
Arduino
Tinkercad
Hardware:
DC motor (9V)
IC
adapter (9V)
Ultrasonic sensor
jumbers
Arduino uno (5V)
I had searched a lot about this couple connection... I didn't find any thing );
so I lead to My lovely software ever Tinker cad and tried to build this circuit and used code blocks of video tutorial.
much hours later of trying building circuit and cooding. I got it !
In real :
I used mini breadboard and IC and Motor and adapter 9V and ultrasonic sensor
connect positive and negative of DC motor with IC. connect positive and negative with battery 9V and ground with Arduino and 5 volt with arduino to open IC . connect pens of IC with 7,8,9 pens of Arduino as shown .
connect Ultrasonic sensor VCC with 5V pen in Arduino and Gnd with Ground of Arduino and trig in pen 4 and echo in pen 2.
Tinkercad
1- Arduino UNO
2-BreadBoard
3-IC (L293D)
4-Battery 9V
5-Motor
6-Ultrasonic Sensor
7-Wires
Assembly Steps :
Setup breadboard with IC (L293D) To Uno Arduino and connect the board with the ground and 5V from the arduino From Database of IC(L293D) connected the external source power ( Battery 9V) to deliver the power to motor then connect the ultrasonic sensor to Arduino as shown
Coding:
// C++ code
//
long readUltrasonicDistance(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT); // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
// Sets the trigger pin to HIGH state for 10 microseconds
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in microseconds
return pulseIn(echoPin, HIGH);
}
void setup()
{
pinMode(9, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
}
void loop()
{
analogWrite(9, 180);
if (0.01723 * readUltrasonicDistance(4, 2) < 5) {
digitalWrite(7, LOW);
digitalWrite(8, LOW);
} else {
analogWrite(9, 180);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
}
delay(10); // Delay a little bit to improve simulation performance
}
steps of preparing bring the component and wired it and make the code on tinker cad and copied it in the Arduino and upload to Arduino board and connect the 9V adapter.. see the Action
I didn't know how I can use H-bridge with motor so I asked instructors and helped me..
firstly.. when I build the circuit in tinker cad and tried to code it I couldn't make for first time so..
I return to video tutorial and connect Motor only and code it and upload to Arduino and worked it..
get Ultrasonic sensor and connect with led on tinker cad and code it and upload to Arduino and worked it
I made this steps to check that component are working.
I connect them each other in tinker cad and code it and work it by hand but their is a real problem !!
ultra sonic work only when the distance on 5 cm only.. not working in range!!!
when I return and reconnect the wiring and coding this open exactly...
Title of Media
Title of Media
Title of Media
Title of Media
https://drive.google.com/file/d/1FL2mSg6trHalhxTbXc3wDY0FxSJOAZ1V/view?usp=sharing
https://drive.google.com/file/d/17uiFpHuSXWsVhnUzIVMKHpQzrAn6-Zl3/view?usp=sharing
https://drive.google.com/file/d/1ffNk0vyy92SMiyYdhqTGtg1OdN1Qlj0O/view?usp=sharing
https://drive.google.com/file/d/1npgx23q1b-_Hj8Jh-0VPUqYEzdxfYbKx/view?usp=sharing