Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MORE INFO: THE VIDEO: https://www.youtube.com/watch?v=sgS0BZN36P0 Using Arduino

ID: 3823237 • Letter: M

Question

MORE INFO:

THE VIDEO:

https://www.youtube.com/watch?v=sgS0BZN36P0

Using Arduino to create a gate that when I move my hand the gate is open and keep open then when I move my hand again it is close using ultrasonic sensor and dc motor and led light How to programming the Arduino to do that? The gate is look like this one and we want to programming the Arduino to operate motor that controlled by an ultrasonic sensor Using the following: Arduino UNO DC motor Ultrasonic sensor (hc-sr04) Driver motor(I298n) And this video explain the idea but it used other component

Explanation / Answer

Solution:-

This is a simulation of a automatic door which open and close automatically using ultrasonic sensor.

The hardware we need -

1) Ultrasonic sensor

2) Arduino uno Microcontroller

3) Servo motor

4) Jumper caple

The ultrasonic sensor will detect the distance infront of the gate if a object came closer than a certain distance to the gate the ultrasonic sensor will send a command to the arduino microcontroller to open the gate , then the ardino will send a command to the servo to open the gate 90 Degree to open the gate.

The below given code for the automatic door simulation in the Arduino microcontroller IDE.

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include

Servo myservo; // create servo object to control a servo

const int trigPin = 2;

const int echoPin = 4;

void setup() {

// initialize serial communication:

Serial.begin(9600);

myservo.attach(9); // attaches the servo on pin 9 to the servo object

}

void loop() {

// and the distance result in centimeters:

long duration, cm;

pinMode(trigPin, OUTPUT);

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(20);

digitalWrite(trigPin, LOW);

pinMode(echoPin, INPUT);

duration = pulseIn(echoPin, HIGH);

// convert the time into a distance

cm = microsecondsToCentimeters(duration);

// the condition for the distance

if ( cm > 7 && cm < 14)

{

myservo.write(140); // sets the servo position according to the scaled value

delay(4000);

}

else if ( cm < 8)

{

myservo.write(40); // sets the servo position according to the scaled value

delay(100);

}

else

{

myservo.write(40); // sets the servo position according to the scaled value

delay(100);

}

Serial.print(cm);

Serial.print("cm");

Serial.println();

delay(100);

}

long microsecondsToCentimeters(long microseconds) {

// The speed of sound is 340 m/s or 29 microseconds per centimeter.

// The ping travels out and back, so to find the distance of the

// object we take half of the distance travelled.

return microseconds / 29 / 2;

}

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------