A simple sensor to detect what is essentially changes in resistance of a circuit. As more water hits the sensing pad, the resistance of the circuit goes down, allowing the Photon to detect this change in voltage through a voltage divider circuit in the sensor.
The sensor itself is NOT entirely waterproof, so seal off the connectors from water using perhaps a silicone potting compound or something similar.
Remember: sensors are designed for one application in mind, but it can always be used in creative ways!
For more technical details on the sensor click here.
BEWARE: there are 2 versions of this board floating around – check the pin labels and swap the wires accordingly. The above diagram assumes a V2 board.
// how long between each log update? feel free to change this value,
// but this must not be anything less than 1000 milliseconds!
#define INTERVAL_BETWEEN_LOGS 5000// initialise the timer
Timer dataTimer(INTERVAL_BETWEEN_LOGS, doDataUpdate);
// code in this setup function runs just once, when Photon is powered up or reset
voidsetup() {
Serial.begin(9600); // Open a connection via the Serial port / USB cable – useful for debugging
delay(5000); // Common practice to allow board to 'settle' after connecting online
dataTimer.start();
// note: analogue pins do not need to be initialised as they are INPUTs by default
}
// code in this loop function runs forever, until you cut power!
// for the A/D blackbox, there is nothing to do in here because data updates are handled by our timer
voidloop() {
}
// doDataUpdate runs every interval set in INTERVAL_BETWEEN_LOGS
voiddoDataUpdate() {
// IMPORTANT: to prevent server overload, the Particle cloud can only accept
// update rates of once per second, with the option to 'burst' 4 updates in a
// second (but then you'll get blocked for the next 4 seconds). 'Ration' your
// INTERVAL_BETWEEN_LOGS and the number of readings you are publishing; in our
// default example, we are frugally using just 1 publish, by concatenating
// all the data we want into a single publish statement
// first we save what we want to read into temporary variables first.
// feel free to add/remove these lines as you see fit in your application:
int A0State = analogRead(A0); // read an analogue range (0-4095) from A0
// now we form the concatenated string to put them all together. This String
// must NOT exceed 255 characters!
String output ="A0:"+ String(A0State);
// prints this out the Serial port (coolterm) for us humans to verify and
// debug; comment the next line if you don't want to see it in Coolterm
Serial.println(output);
// send it out (and have your IFTTT recipe ready to use it):
Particle.publish("sensorData", output);
}