#define SERIESRESISTOR 560
#define SENSORPIN A0
String waterState = "uninitialized";
String previousState = "uninitialized";
void setup(void) {
Serial.begin(9600);
Particle.publish("spotify_trigger");
}
void loop(void) {
float reading;
reading = analogRead(SENSORPIN);
Serial.print("Analog reading ");
Serial.println(reading);
// convert the value to resistance
reading = (4095 / reading) - 1;
reading = SERIESRESISTOR / reading;
Serial.print("Sensor resistance ");
Serial.println(reading);
if (reading >= 1550) {
waterState = "water_height_empty";
}
else if ((reading < 1550) && (reading >= 1100)) {
waterState = "water_height_filling";
}
else if ((reading < 1100) && (reading >= 1050)) {
waterState = "water_height_near";
}
else if ((reading < 1050) && (reading >= 900)) {
waterState = "water_height_full";
}
else if (reading < 900) {
waterState = "water_height_max";
}
else {
waterState = "error";
}
if (waterState != previousState) {
Particle.publish(waterState);
delay(750);
}
previousState = waterState;
delay(1000);
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .