Hello! the purpose of this device is to determine the distance to the object using a sonar, rangefinder. Learn how to install sonar on Arduino, for example, a code that includes an explanation, calibration, and how to use the device to calculate the distance. Please note that some images will use the circuit board to mount the fish finder to the Arduino, and some will not, however they are interchangeable since they are the same.
Materials
We will need:
1. Arduino Board
2. Hydroacoustic Rangefinder
3. jumpers
3.5. wires (optional, for use on breadboard)
4. breadboard (optional)
Hydroacoustic Rangefinder Connection Diagram to Arduino
1. Trig connect to pin 11
2. Connect Echo to pin 10
3. GND Connections to the corresponding GND pins on the Arduino
4. Connect vcc to 5V position on power supply with Arduino
Connection technology
1. Connect vcc to the positive terminal of the breadboard, and GND to the negative terminal
2. Connect the negative GND terminal to the Arduino, and the positive terminal to the 5V position of the Arduino
3. Connect trig, on pin 8
4. Connect Echo on pin 9
The code
The following code has already been calibrated, as it was obtained from an external source that included calibration.
#define trigPin 9 // tells Arduino that the trig pin is pin 9
#define echoPin 10 // tells Arduino that the echo pin is pin 10
void setup () {
Serial.begin (9600); // sets the data rate of transmission to 9600
pinMode (trigPin, OUTPUT); // sets the trigPin as the output
pinMode (echoPin, INPUT); // sets the echoPin as the input
}
void loop () {
float duration, distance;
digitalWrite (trigPin, LOW);
delayMicroseconds (2);
digitalWrite (trigPin, HIGH);
delayMicroseconds (10);
// digitalWrite (trigPin, LOW);
duration = pulseIn (echoPin, HIGH);
Serial.println (duration);
distance = (duration / 2) * 0.0344; // calculates the duration into centimeters
if (distance <= 2) {
Serial.print ("Distance =");
Serial.println ("Out of range"); // doesn't print distance if less that a certain interval
}
else {
Serial.print ("Distance =");
Serial.print (distance); // prints distance within the interval
Serial.println ("cm");
delay (500);
}
delay (500);
}
Run the program
After starting the program, write down the data and good luck to you!
Cost: ~ 143