Karel Kalthoff
Published

Water Detection System

Send email alerts with LightBlue Bean using Node-RED on Raspberry Pi.

IntermediateFull instructions provided5,474
Water Detection System

Things used in this project

Hardware components

LightBlue Bean
Punch Through LightBlue Bean
×1
Raspberry Pi 2 Model B
Raspberry Pi 2 Model B
×1
Seeed Studio Grove Moisture Sensor
×1
Seeed Studio 2xAA Battery Holder
×1
Seeed Studio 4 Pin Male Jumper to Grove Conversion Cable
×1

Story

Read more

Schematics

Wiring Diagram

Code

Bean Code

Plain text
int sensorPin = A0;
int sensorValue = 0;

void setup() 
{
Serial.begin(9600);
}

void loop()
{
 sensorValue = analogRead(sensorPin);
 Serial.println(sensorValue);
 Bean.sleep(1000000000);
}

Node-RED Code

Plain text
[{"id":"912350e5.6edcb","type":"bean","name":"Water Sensor Bean","uuid":"","connectiontype":"timeout","connectiontimeout":"2"},{"id":"5ec0d702.a13f28","type":"bean serial","name":"Bean Serial","bean":"912350e5.6edcb","newline":"\\n","bin":"false","out":"char","addchar":true,"x":302.5,"y":83,"z":"ab0aaa47.54f558","wires":[["5bc0a855.a43f58"]]},{"id":"5bc0a855.a43f58","type":"function","name":"moisture threshold","func":"context.previousMoisture = context.previousMoisture || 0;\nvar moisture = msg.payload;\n\nvar upperThreshold = 400;\n\n// Check if the new moisture is different from the previous\nif (context.previousMoisture != moisture){\n  // Check if moisture outside threshold\n\tif ( moisture >= upperThreshold){\n    // Compose alert email\n\t\tmsg.payload = \"Water detected! Current moisture is \" + (String(moisture)-upperThreshold) + \" above threshold.\";\n    return msg;\n\t}\n}","outputs":1,"valid":true,"x":505.5,"y":83,"z":"ab0aaa47.54f558","wires":[["918c428b.6e73c"]]},{"id":"6915426.f96eabc","type":"inject","name":"1 min interval","topic":"","payload":"!","payloadType":"string","repeat":"60","crontab":"","once":false,"x":143.5,"y":83,"z":"ab0aaa47.54f558","wires":[["5ec0d702.a13f28"]]},{"id":"918c428b.6e73c","type":"e-mail","server":"smtp.gmail.com","port":"465","name":"","dname":"Email","x":679.5,"y":83,"z":"ab0aaa47.54f558","wires":[]}]

Credits

Karel Kalthoff

Karel Kalthoff

2 projects • 18 followers
happily building connected products at Punch Through Design

Comments