I was inspired by this idea which allows cars to pass with a specific type of cards which action like entering a passcode code but I tried it using ultrasonic sensor and servo motor
Procedure for using time-charge parking spaces|ナビパーク (navipark1.com)
TinkerCAD it's a platform used to conduct and simulate my circuits and building the code using blocks
Arduino IDE software
+
Objectives:
1. connect Ultrasonic sensor with servo motor
2. using the ultrasonic sensor as input and servomotor as output
Components:
Arduino Uno
Servo Motor
Ultrasonic sensor
Breadboard
Jumper Wires
Steps:
Connecting the circuit as shown as Ultrasonic sensor has 4 legs both for Ground and VCC and both for signal and control, for the Servo motor has 3 legs two for Ground and power and the 3rd for signal and the all connected together
to make sure of the connections Servo motor has been connected individually so Ultrasonic sensor too
after this, we use building blocks to tell Arduino what functions we want to be executed on this hardware
we start the simulation process to see how the functions work and validate the code (A video has been uploaded to the assets)
we connect physical components as the tinkerCAD connected and make the whole Circuit
we take the code from TinkerCAD and paste it in the Arduino IDE then we validate and upload it
The sequence of the code was as next:
1. Read from the sensor First ( as Input) and the reading will be within the range I gave in the code
2. If the reading was as I gave then Servo Motor will respond as an (output) and it will move 180 Degree opening the gate
3. wait for 2 second before returning to its' initial state
4. if no reading from the senor in the range it stays in the initial state till it gets a reading
#include <Servo.h>
int i = 0;
int Position = 0;
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);
}
Servo servo_9;
void setup()
{
servo_9.attach(9, 500, 2500);
}
void loop()
{
if (0.01723 * readUltrasonicDistance(3, 2) <= 20) {
servo_9.write(180);
delay(2000); // Wait for 2000 millisecond(s)
} else {
servo_9.write(0);
delay(2000); // Wait for 2000 millisecond(s)
}
}
We had many discussions me and my group mates and we tried other things and it was useful as next:Fatma had some troubleshooting with Ultrasonic and our instructor Menna helped us very much and elaborated a lot of things that helped me when I applied other things on my own.
I had to use Youtube and use some Resources like
Arduino Hub for projects
Instructable
and I found this project which is similar to mine
How to connect ultrasonic sensor and Servo Motor😍😍🤗 - YouTube
I tried to do this one
chrome t-Rex hacked by Arduino || simple project Arduino + servo motor + LDR - YouTube
but I couldn't
I had problems also as the voltage required wasn't effiicient to run both Ultrasonic + Servo motor so when I tried to connect the Arduino with 6v/9v there was a slight change in the response time.
I learned a lot of skills and it made me understand my project with around 50% better and use more effiecient electronics and add new modifications