water level sensor
water level sensor
A few days ago I have upgraded my water level sensor. It is based on this idea, but previously proximity sensor was connected directly to one of analog Arduino inputs with a cable about 2m long, and there was a lot of noise. Now it is modified to use Dallas DS2438 chip, which is a nice device in its own right and I might be upgrading all my temperature sensors from DS18B20 to it as it has got superior speed, it can read temperature in below 15ms comparing to DS18B29’s over 750ms. Proximity sensor is Sharp GP2D12 and the cable connecting it to the Dallas chip is now just a few centimetres, the noise is all but gone. While rebuilding the old one I made one additional copy, so I could sense the level not only in the sump but the weir in the main tank as well, as on one occasion I had a small leak from the tank due to overflow in the sump after power shortcut. The water level in the weir was too high and I didn’t notice until too late, it can go up if the valve in the down pipe builds a cover of algae or some other blockage. Of course the sensor in the weir is not connected yet, but I’ll get there eventually ;P
This is the bit of Arduino code which reads the ADC on DS2438:
ds.reset();
ds.select(addr); // 8-byte array with DS2438 address
ds.write(0x44); // start T conversion
delay(10);
present = ds.reset();
ds.select(addr);
ds.write(0xB8); // Recall Memory
ds.write(0x00); // Page 0
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
ds.write(0x00); // Page 0
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}
LowByte = data[1]; //LSB
HighByte = data[2]; //MSB
TReading = (HighByte << 8) + LowByte;
TReading = TReading >> 3;
SignBit = TReading & 0x8000; // test most sig bit
if (SignBit) { // negative
TReading = (TReading ^ 0xffff) + 1; // 2's comp
}
Serial.println(TReading * 0.03125);
If you have any questions, fire away.
Friday, 25 June 2010