loading

This is an Instructable for making a sensor that is fixed to a certain height and can measure the water height below itself. It was initially planned as a boat that floats atop the water which can measure the waterdepth, hence it's shape.

There is a parking sensor in the bottom of the boat which can measure the distance to the nearest object. At first we thought the frequency was high enough to penetrate water and measure the actual bottom of the river/lake, but unfortunately this is not the case, since the signal bounces off on the water.

The data is uploaded to both the console of Particle (console.particle.io) and checked by an IFTTT.com trigger, to see if a certain water height is achieved (Less than 30cm between the sensor and water height). When this is the case, the red LED will become on, the Mario themesong is played and the owner of the device is warned of the high water level by an email.

Step 1: Requirements

For this project, you would need the following materials: (* = optional)

  • 1x Particle Photon board
  • 1x Breadboard
  • 1x Powerbank
  • 1x Buzzer*
  • 1x Red LED*
  • 1x Yellow LED*
  • 1x Green LED*
  • 1x JSN-SR04T waterproof ultrasonic sensor (a HC-SR04 also works)
  • 13x wires

Also needed:

  • Particle.io account
  • IFTTT.com account*

Please note that the LED's, the buzzer and an IFTTT.com account are optional. These are not required to measure the water level and were only added for 'the lulz'. If you choose to mount these LED's and buzzer, locate them outside the box for optimal viewing and sound distances.

It is adviced to mount the board and materials inside a waterproof box, to prevent rain/water damaging the electronics. The ultrasonic sensor should be pointing down at a 90 degree angle (straight down) to accurately calculate the distance between the sensor and the water surface level.

Step 2: Wiring Scheme

First, we start by wiring up the LED's, the buzzer and the parking sensor. Note that in this example the parking sensor is displayed as a HC-5RD4 since this is essentially the same sensor.

Wiring up the + side of the GREEN LED to D0, YELLOW LED to D1, RED LED to D2. All - sides should go to a GND. Wire up the buzzer to A4. Wire the + side of the sensor to VIN (5V), since 3.3V won't suffice. GND to GND. Trigger should be wired to D6. Echo wired to D5.

Also, we used a powerbank to power up the Photon, which can be placed inside the box aswell.

After wiring up, we can head to the next step: Coding the Photon.

Step 3: Code

int echopin = D5;
int trigpin = D6; int groen = D0; int geel = D1; int rood = D2;

const int speakerPin = A4;

const int songLength = 18;

int tempo = 400;

void setup() { Serial.begin(9600); pinMode(echopin, INPUT); pinMode(trigpin, OUTPUT); pinMode(groen, OUTPUT); pinMode(geel, OUTPUT); pinMode(rood, OUTPUT); Particle.function("analogread", PublishValue); pinMode(speakerPin, OUTPUT);

}

void loop() {

int duration, distance; digitalWrite(trigpin, LOW); delayMicroseconds(2); digitalWrite(trigpin, HIGH); delayMicroseconds(10); digitalWrite(trigpin, LOW); duration = pulseIn(echopin, HIGH); distance = (duration/2) / 29.1; Serial.println(distance);

delay(1000); Spark.function("Publish", PublishValue);

Particle.publish("Distance",(String) distance);

if (distance < 30) { digitalWrite(rood,HIGH); digitalWrite(geel,LOW); digitalWrite(groen,LOW);

float v = 1.8; int delay1 = 50 *v; int delay2 = 75*v; int delay10 = 100*v; int delay8 = 110*v; int delay3 = 150*v; int delay9 = 165*v; int delay4 = 175*v; int delay5 = 180*v; int delay14 = 200*v; int delay6 = 210*v; int delay12 = 225*v; int delay11 = 250*v; int delay7 = 275*v; int delay13 = 287*v; int delay15 = 300*v; int delay16 = 162*v; tone(speakerPin,660,100); delay(delay2);tone(speakerPin,660,100); delay(delay3);tone(speakerPin,660,100); delay(delay3);tone(speakerPin,510,100); delay(delay1);tone(speakerPin,660,100); delay(delay3);tone(speakerPin,770,100); delay(delay7);tone(speakerPin,380,100); delay(delay13);tone(speakerPin,510,100); delay(delay12);tone(speakerPin,380,100); delay(delay14);tone(speakerPin,320,100); delay(delay11);tone(speakerPin,440,100); delay(delay3);tone(speakerPin,480,80); delay(delay9);tone(speakerPin,450,100); delay(delay2);tone(speakerPin,430,100); delay(delay3);tone(speakerPin,380,100); delay(delay10);tone(speakerPin,660,80); delay(delay10);tone(speakerPin,760,50); delay(delay2);tone(speakerPin,860,100); delay(delay3);tone(speakerPin,700,80); delay(delay2);tone(speakerPin,760,50); delay(delay4);tone(speakerPin,660,80); delay(delay3);tone(speakerPin,520,80); delay(delay2);tone(speakerPin,580,80); delay(delay2);tone(speakerPin,480,80); delay(delay4);tone(speakerPin,510,100); delay(delay7);tone(speakerPin,380,100); delay(delay14);tone(speakerPin,320,100); delay(delay11);tone(speakerPin,440,100); delay(delay3);tone(speakerPin,480,80); delay(delay9);tone(speakerPin,450,100); delay(delay2);tone(speakerPin,430,100); delay(delay3);tone(speakerPin,380,100); delay(delay10);tone(speakerPin,660,80); delay(delay10);tone(speakerPin,760,50); delay(delay2);tone(speakerPin,860,100); delay(delay3);tone(speakerPin,700,80); delay(delay2);tone(speakerPin,760,50); delay(delay4);tone(speakerPin,660,80); delay(delay3);tone(speakerPin,520,80); delay(delay2);tone(speakerPin,580,80); delay(delay2);tone(speakerPin,480,80); delay(delay11);tone(speakerPin,500,100); delay(delay3);tone(speakerPin,760,100); delay(delay1);tone(speakerPin,720,100); delay(delay2);tone(speakerPin,680,100); delay(delay2);tone(speakerPin,620,150); delay(delay3);tone(speakerPin,650,150); delay(delay3);tone(speakerPin,380,100); delay(delay2);tone(speakerPin,430,100); delay(delay2);tone(speakerPin,500,100); delay(delay3);tone(speakerPin,430,100); delay(delay2);tone(speakerPin,500,100); delay(delay1);tone(speakerPin,570,100); delay(delay8);tone(speakerPin,500,100); delay(delay3);tone(speakerPin,760,100); delay(delay1);tone(speakerPin,720,100); delay(delay2);tone(speakerPin,680,100); delay(delay2);tone(speakerPin,620,150); delay(delay3);tone(speakerPin,650,200); delay(delay3);tone(speakerPin,1020,80); delay(delay3);tone(speakerPin,1020,80); delay(delay2);tone(speakerPin,1020,80); delay(delay3);tone(speakerPin,380,100); delay(delay3);tone(speakerPin,500,100); delay(delay3);tone(speakerPin,760,100); delay(delay1);tone(speakerPin,720,100); delay(delay2);tone(speakerPin,680,100); delay(delay2);tone(speakerPin,620,150); delay(delay3);tone(speakerPin,650,150); delay(delay3);tone(speakerPin,380,100); delay(delay2);tone(speakerPin,430,100); delay(delay2);tone(speakerPin,500,100); delay(delay3);tone(speakerPin,430,100); delay(delay2);tone(speakerPin,500,100); delay(delay1);tone(speakerPin,570,100); delay(delay8);tone(speakerPin,500,100); delay(delay3);tone(speakerPin,760,100); delay(delay1);tone(speakerPin,720,100); delay(delay2);tone(speakerPin,680,100); delay(delay2);tone(speakerPin,620,150); delay(delay3);tone(speakerPin,650,200); delay(delay3);tone(speakerPin,1020,80); delay(delay3);tone(speakerPin,1020,80); delay(delay2);tone(speakerPin,1020,80); delay(delay3);tone(speakerPin,380,100); delay(delay3);tone(speakerPin,500,100); delay(delay3);tone(speakerPin,760,100); delay(delay1);tone(speakerPin,720,100); delay(delay2);tone(speakerPin,680,100); delay(delay2);tone(speakerPin,620,150); delay(delay3);tone(speakerPin,650,150); delay(delay3);tone(speakerPin,380,100); delay(delay2);tone(speakerPin,430,100); delay(delay2);tone(speakerPin,500,100); delay(delay3);tone(speakerPin,430,100); delay(delay2);tone(speakerPin,500,100); delay(delay1);tone(speakerPin,570,100); delay(delay6);tone(speakerPin,585,100); delay(delay7);tone(speakerPin,550,100); delay(delay6);tone(speakerPin,500,100); delay(delay5);tone(speakerPin,380,100); delay(delay3);tone(speakerPin,500,100); delay(delay3);tone(speakerPin,500,100); delay(delay2);tone(speakerPin,500,100); delay(delay3);tone(speakerPin,500,60); delay(delay2);tone(speakerPin,500,80); delay(delay3);tone(speakerPin,500,60); delay(delay4);tone(speakerPin,500,80); delay(delay2);tone(speakerPin,580,80); delay(delay4);tone(speakerPin,660,80); delay(delay2);tone(speakerPin,500,80); delay(delay3);tone(speakerPin,430,80); delay(delay2);tone(speakerPin,380,80); delay(delay15);tone(speakerPin,500,60); delay(delay2);tone(speakerPin,500,80); delay(delay3);tone(speakerPin,500,60); delay(delay4);tone(speakerPin,500,80); delay(delay2);tone(speakerPin,580,80); delay(delay2);tone(speakerPin,660,80); delay(delay12);tone(speakerPin,870,80); delay(delay16);tone(speakerPin,760,80); delay(delay15);tone(speakerPin,500,60); delay(delay2);tone(speakerPin,500,80); delay(delay3);tone(speakerPin,500,60); delay(delay4);tone(speakerPin,500,80); delay(delay2);tone(speakerPin,580,80); delay(delay4);tone(speakerPin,660,80); delay(delay2);tone(speakerPin,500,80); delay(delay3);tone(speakerPin,430,80); delay(delay2);tone(speakerPin,380,80); delay(delay15);tone(speakerPin,660,100); delay(delay2);tone(speakerPin,660,100); delay(delay3);tone(speakerPin,660,100); delay(delay3);tone(speakerPin,510,100); delay(delay1);tone(speakerPin,660,100); delay(delay3);tone(speakerPin,770,100); delay(delay12);tone(speakerPin,380,100); } if (distance >= 30 and distance <50) { digitalWrite(rood,LOW); digitalWrite(geel,HIGH); digitalWrite(groen,LOW); analogWrite(speakerPin, 0); } if (distance >= 50) { digitalWrite(rood,LOW); digitalWrite(geel,LOW); digitalWrite(groen, HIGH); analogWrite(speakerPin, 0); }

}

int PublishValue(String pin) { int duration, afstand; digitalWrite(trigpin, LOW); delayMicroseconds(2); digitalWrite(trigpin, HIGH); delayMicroseconds(10); digitalWrite(trigpin, LOW); duration = pulseIn(echopin, HIGH); afstand = (duration/2) / 29.1;

return afstand; }

Step 4: Workings

The sensor is now to be mounted above the waterlevel at a fixed height. Because the parking sensor has a certain range in which is works, it has to be mounted at least 30 centimeter above the heighest water level, since it only works between ~30 - ~250 cm. The HC-SR04 sensor works between ~2 and ~100 centimeter and can thus be mounted lower than the parking sensor. After the code has been flashed to the Photon and the Photon, LED's and sensors are all wired up, you're good to go and can start measuring.

The sensor has 4 pins, 5V, trigger, echo and GND. The 5V should be wired to the 'VIN' pin, drafting 5V from the Photon. The GND should go to ground on the Photon. The triggerpin is used to 'tell' the sensor when to start measuring, by sending it a pulse so it knows it can start sending out a pulse itself. The echo pin then times how long it took for the pulse to reflect back into the sensor itself. The distance can then be calculated by dividing this time by 2, since it went back and forth and then dividing it by the amount of (micro)seconds it takes for sound to travel 1m in air, which is 1/343 = 0.029 sec.

As can be seen in the code, when the water height is still heigher than 60cm below the device, the green LED will be on and the yellow and red LED will stay on.

When the water height reaches below 60cm but still heigher than 30cm, the yellow LED will light up and the other two will turn off.

Finally, when the waterlevel reaches a height of less than 30 cm below the sensor, the red LED will start burning, indicating that the waterlevel has reached a critical height. This is also when a sound is played, in this case the themesong of Mario. Also an IFTTT trigger (IFTTT.com) will be triggered and an email will be send towards the email setup in the trigger, for example the supervisor of a stretch of river, a sluice or canal.

<p>it measure the deep inside water or the distance over the water?</p>
<p>This would be awesome in areas that flood easily :)</p>

About This Instructable

1,901views

15favorites

License:

More by dannnyyy:Measuring Water Height Using a Particle Photon, a Parking Sensor and IFTTT.com 
Add instructable to: