I purchased two SEN0208 from core electronics (order # 100276969) and they arrived well packed and on time, thank you.
I installed then in a small tank i purchased from Bunnings https://www.bunnings.com.au/maze-100l-rainwater-mini-tank_p3130198 to try them out.
Arduino’s pulseIn() function seemed the easiest way to get these up and running, and I used DFRobot’s suggested sketch to get started. I had quite a few timeouts where pulseIn() returned zero - which is fine - so I ended up using the sketch below to filter and average the readings.
The value returned from the sensor seems to bear no relationship to the level of water in the tank. It returns 1320 +/- 15 on every valid reading - when the tank is full, and when it is empty.
Being an enginner, I love redundancy! So I have tried each of the two sensors i bought with each of the two JSN boards that came in my order - but they all returned the same value (+/- noise).
When NOT in the tank, they seem to work better If I hold them ~500mm above my bench, the pulseIn function returns ~3031, and at about 1m above, it returns ~5690. These figures are more like the “number of cm x 58” quoted as the calibration.
Can you offer any advise on how to get these working in the tank?
Is it just the small tank size that is the issue? My real water tanks are larger, and one is concrete, the other is poly.
Do I need a ‘funnel’ to focus the ultrasonic signal in such a small tank?
Should I fiddle with the adjustable component (is it an inductor) on the circuit board?
Cheers
#define ECHOPIN 2// Pin to receive echo pulse
#define TRIGPIN 3// Pin to send trigger pulse
void setup(){
Serial.begin(9600);
pinMode(ECHOPIN, INPUT);
pinMode(TRIGPIN, OUTPUT);
digitalWrite(ECHOPIN, HIGH);
digitalWrite(TRIGPIN, LOW); // Set the trigger pin to low for 2uS
delayMicroseconds(100); // Ensure the loop begins with the trig pin having been low for some time.
}
const int samples = 20;
void loop(){
int validReadings=0;
unsigned long total = 0;
for (int i=0; i<samples; i++) {
digitalWrite(TRIGPIN, HIGH); // Send a 10uS high to trigger ranging
delayMicroseconds(10);
digitalWrite(TRIGPIN, LOW); // Send pin low again
unsigned long raw = pulseIn(ECHOPIN, HIGH,200000);
if (raw == 0) {
// pulseIn returns 0 implies a timeout occured.
Serial.println(".");
} else {
validReadings ++;
String raw_s = String(raw);
String i_s = String(i);
Serial.println(i_s + "SEN0208 returned:" + raw_s);
delay(500);
}
total += raw;
}
Serial.println(total/validReadings);
}
/**
* Calibration:
*
* At a distance of 870mm from sensor (a) to the top of a small (100L) water tank, the device reads 1308 +/- 5
*
* A second sensor (b) of identical model returned 1320 +/-11 and 870mm./
*
* Full Tank (<200mm to sensor):
* Sensor (a) 1320 also.
* Sensor (b) 1315 / 1320 also - no discernable difference to empty tank.
*
*
* using the provided calibration of raw value divided by 58 to get distance in cm, 1317/58 = 22.7cm, which is clearly wrong.
*
*/