Question: Add the following code to your program. must be included to activate the function of sonar(). #include #define TRIGGER_PIN 12 // Arduino pin tied to
#include #define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor. #define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor. #define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm. NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
Add sonar.ping_cm() to read the distance in terms of cm in loop(). Send the distance information back to PC through serial communication.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
