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

Create and demonstrate a system that operates as follows: • The Ardiuno uses the

ID: 3877671 • Letter: C

Question

Create and demonstrate a system that operates as follows:

• The Ardiuno uses the ultrasonic sensor to measure the distance to an object. This distance is transmitted via I2C to the Pi and displayed on the LCD.

*The Arduino also writes the current time and distance through the USB serial link to the serial monitor. This should be set up so that the data display can be turned on and off via commands from the serial link. This program should have a variable sample rate (changed by changing the value of a variable, so re-compiling to change the sampling rate is ok), so that the current time advances exactly at this sample rate. (If you use delays to implement this, you are not doing it correctly.

• A Matlab program communicates with the Arduino, starting and stopping the display of data as needed. This program will collect a desired amount of data from the Arduino (specified in number of time samples) and display the results in a graph.

Explanation / Answer

.Ultrasonic Sensor HC-SR04 and Arduino

const int trigPin = 9;
const int echoPin = 10;

long duration;
int distance;
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance= duration*0.034/2;
Serial.print("Distance: ");
Serial.println(distance);
}

...#include <LiquidCrystal.h>
LiquidCrystal lcd(1, 2, 4, 5, 6, 7);
const int trigPin = 9;
const int echoPin = 10;
long duration;
int distanceCm, distanceInch;
void setup()
{
lcd.begin(16,2);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm= duration*0.034/2;
distanceInch = duration*0.0133/2;
lcd.setCursor(0,0);
lcd.print("Distance: ");
lcd.print(distanceCm);
lcd.print(" cm");
delay(10);
lcd.setCursor(0,1);
lcd.print("Distance: ");
lcd.print(distanceInch);
lcd.print(" inch");
delay(10);
}

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