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

4. What will the following Arduino code do? Please explain in a few words. (4 po

ID: 3905146 • Letter: 4

Question

4. What will the following Arduino code do? Please explain in a few words. (4 points) You may want to revisit the Arduino coding assignment from previous week for this question. In this setup, a motor is connected to an H-bridge, which is controlled by pin11 and pin 10. A distance sensor is connected to pin 2. Here is the code: int motorPin1-11; Variables defined before setup and loop functions can be used anywhere in any function. int motorPin2= 10; int distance_sensor_pin 2; long int pulse_duration, distance_in_inches; //l The setup function void setup0 pinMode(motorPin1, OUTPUT); pinMode(motorPin2, OUTPUT); Serial.begin(9600); ) // end of setup function // The loop function void loop0 // read the distance pinMode( distance_sensor_pin, OUTPUT); digitalWrite( distance_sensor_pin, LOW; delayMicroseconds(2); digitalWrite( distance_sensor_pin, HIGH); delayMicroseconds(5); digitalWrite( distance_sensor_pin, LOW; pinMode( distance_sensor_pin, INPUT); pulse_duration-pulseln( distance_sensor_pin, HIGH); distance_in_inches pulse_duration /74/2; Serial.println(distance_in_inches); delay(200); // do stuff if (distance_in_inches> 10) ( digitalWrite(motorPin1, HIGH); digitalWrite(motorPin2, LOW) else if (distance_in_inches

Explanation / Answer

In the Setup portion of the code the various peripherals are being setup

For example motor_pin_1 and motor_pin_2 is configured as output.

and Baud rate for serial pin is set.

In the loop portion of the code the actual logic/working is wriiten.

Initially distance sensor is triggered by sending a pulse waveform by configuring distance_sensor_pin as output.

The distance sensor which is used is Ultra Sound Sensor.

Then the distance_sensor_pin is configured as INPUT.

Then it measures the pulse duration till the distance_sensor_pin is made HIGH.

From the pulse duration the distance between the source(Ultra sound sensor) and the object is determined.

The distance is output to serial monitor by using Serial.println()

Then using this distane_in_inches motor is controlled.

if distane_in_inches is greater than 10 then motor 1 is ON and motor 2 is OFF.

if distance_in_inches is less than 2 then motor 1 is turned OFF and motor 2 is turned ON.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote