How do you make a range sensor using one transducer:
- EZ01 ultrasonic sensor is a 42kHz transducer
- Arduino-based
As you can see from the EZ01 datasheet, it has the ability to do both. It is the same pinout as my MB7380 sensor:
How do you waterproof electronic sensors?
→ silicone heat shrink tubing and waterproof epoxy
There are $13 waterproof ultrasonic sensors on eBay ($15 on Amazon). As Chris Stratton says, the EZ01 is not designed to work in aquatic environments. After all, water is 850 times denser than air.
C
unsigned long startMillis;
unsigned long currentMillis;
const byte pinTX = 9; // trigger
const byte pinRX = 10; // echo
void setup() {
startMillis = millis(); // initial start time
pinMode(pinTX, OUTPUT);
Serial.begin(9600);
}
void loop() {
currentMillis = millis(); // milliseconds since start
// Reads & returns sound wave traveled in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculate distance
distance= duration*0.034/2; // DO: Change this calculation...
// From here it depends on how you want to output the data: datalogger, LCD screen, etc.
// See https://howtomechatronics.com/tutorials/arduino/ultrasonic-sensor-hc-sr04/
}
// Function you probably don't need:
void read(){ // for connecting to pin 4 on sensor
int len, m;
char testStr[] = "R012\r"; // <test> This version takes 1870 bytes
// in = Serial.read(pinRX);
len = strlen(testStr); // <test>
// len = strlen(in);
return m = atoi(&testStr[len - 3]); // <test>
// Serial.println(m); // <test>
// m = atoi(&in[len - 3]); // measured TTL serial output converted
}