Yesterday i build some more sensors
based on
4,85€ for Baseparts, i think thats okay
My Soil Moisture Sensors:
Sketch:
#include <MySensor.h>
#include <SPI.h>
#include <readVcc.h>
// ********** CONFIG **********************************
#define MY_RADIO_NRF24
#define NODE_ID 3 // ID of node
#define CHILD_ID 3 // ID of sensor
#define INPUT_PIN 3 // OUT-Pin of Moisture Sensor
#define VCC_PIN 4 // VCC-Pin of Moisture Sensor
#define MIN_V 2000 // empty voltage (0%)
#define MAX_V 3200 // full voltage (100%)
// ****************************************************
MyMessage msg(CHILD_ID, V_LEVEL);
MySensor node;
int oldBatteryPcnt;
int sentValue;
int forceSend = 0;
void setup()
{
node.begin(NULL, NODE_ID, false);
node.sendSketchInfo("Moisture Sensor", "1.0");
node.present(CHILD_ID, S_MOISTURE);
pinMode(INPUT_PIN, INPUT);
pinMode(VCC_PIN, OUTPUT);
}
void loop()
{
digitalWrite(VCC_PIN, HIGH); // Turn on Moisture sensor
// Get Percent
int value = analogRead(INPUT_PIN); // Get Moisture
int percent = map(value, 0, 700, 0, 100);
resend(msg.set(percent), 2); // Send PIR status to gateway
sentValue = percent;
// Send batterylevel
sendBattery();
digitalWrite(VCC_PIN, LOW); // Turn off Moisture sensor
// Sleep 1 hour
node.sleep(3600000); // Sending every hour to Gateway
}
// FUNCTIONS
void sendBattery() // Send battery percentage to GW
{
forceSend++;
int batteryPcnt = min(map(readVcc(), MIN_V, MAX_V, 0, 100), 100); // Get VCC and convert to percentage
if (batteryPcnt != oldBatteryPcnt || forceSend >= 20) { // If battery percentage has changed
node.sendBatteryLevel(batteryPcnt); // Send battery percentage to gateway
oldBatteryPcnt = batteryPcnt;
forceSend = 0;
}
}
void resend(MyMessage &msg, int repeats) // Resend messages if not received by GW
{
int repeat = 0;
int repeatDelay = 0;
boolean ack = false;
while ((ack == false) and (repeat < repeats)) {
if (node.send(msg)) {
ack = true;
} else {
ack = false;
repeatDelay += 100;
}
repeat++;
delay(repeatDelay);
}
}
Pimatic-device-config
{
"class": "MySensorsMulti",
"id": "Soil_Gummibaum",
"name": "Erdfeuchte Gummibaum",
"attributes": [
{
"name": "Erdfeuchte Gummibaum",
"nodeid": 3,
"sensorid": 3,
"type": "integer",
"unit": "%",
"sensortype": 37
},
{
"name": "Battery",
"nodeid": 3,
"type": "battery",
"unit": "%"
}
]
}
and how it looks like
My Door/Windos Contact Sensors
Sketch:
#include <MySensor.h>
#include <SPI.h>
#include <readVcc.h>
// ********** CONFIG **********************************
#define MY_RADIO_NRF24
#define NODE_ID 8 // ID of node
#define CHILD_ID 8 // ID of sensor
#define REED_PIN 3 // Pin connected to the Reed-contact, other to GND
#define MIN_V 2000 // empty voltage (0%)
#define MAX_V 3200 // full voltage (100%)
// ****************************************************
MyMessage msg(CHILD_ID, V_TRIPPED);
MySensor node;
int oldBatteryPcnt;
int sentValue;
int forceSend = 0;
void setup()
{
node.begin(NULL, NODE_ID, false);
node.sendSketchInfo("Contact Sensor", "1.2");
node.present(CHILD_ID, S_MOTION);
pinMode(REED_PIN, INPUT);
digitalWrite(REED_PIN, HIGH);
}
void loop()
{
// Get REED
int value = digitalRead(REED_PIN); // Get value of State
if (value != sentValue) { // If status of reedcontact has changed
resend(msg.set(value), 5); // Send reedcontact status to gateway
sentValue = value;
}
// Send batterylevel
sendBattery();
// Sleep until something happens with the sensor
node.sleep(REED_PIN-2, CHANGE);
}
// FUNCTIONS
void sendBattery() // Send battery percentage to GW
{
forceSend++;
int batteryPcnt = min(map(readVcc(), MIN_V, MAX_V, 0, 100), 100); // Get VCC and convert to percentage
if (batteryPcnt != oldBatteryPcnt || forceSend >= 20) { // If battery percentage has changed
node.sendBatteryLevel(batteryPcnt); // Send battery percentage to gateway
oldBatteryPcnt = batteryPcnt;
forceSend = 0;
}
}
void resend(MyMessage &msg, int repeats) // Resend messages if not received by GW
{
int repeat = 0;
int repeatDelay = 0;
boolean ack = false;
while ((ack == false) and (repeat < repeats)) {
if (node.send(msg)) {
ack = true;
} else {
ack = false;
repeatDelay += 100;
}
repeat++;
delay(repeatDelay);
}
}
Pimatic-device-config
{
"id": "MySensors_Contact_Sleeproom",
"name": "Fenster Kinderzimmer",
"class": "MySensorsButton",
"nodeid": 8,
"sensorid": 8,
"batterySensor": true
}
and how it looks like
My Water-gauge Sensor
Sketch
#include <MySensor.h>
#include <SPI.h>
#include <readVcc.h>
// ********** CONFIG **********************************
#define MY_RADIO_NRF24
#define NODE_ID 6 // ID of node
#define CHILD_ID 6 // ID of sensor
#define INPUT_PIN 1 // OUT-Pin of Sensor
#define VCC_PIN 4 // VCC-Pin of Sensor
#define MIN_V 2000 // empty voltage (0%)
#define MAX_V 3200 // full voltage (100%)
// ****************************************************
MyMessage msg(CHILD_ID, V_LEVEL);
MySensor node;
int oldBatteryPcnt;
int sentValue;
int forceSend = 0;
void setup()
{
node.begin(NULL, NODE_ID, false);
node.sendSketchInfo("Water Sensor", "1.0");
node.present(CHILD_ID, S_MOISTURE);
pinMode(INPUT_PIN, INPUT);
pinMode(VCC_PIN, OUTPUT);
}
void loop()
{
digitalWrite(VCC_PIN, HIGH); // Turn on Moisture sensor
// Get Percent
int value = analogRead(INPUT_PIN); // Get Moisture
int percent = map(value, 0, 1023, 0, 100);
resend(msg.set(percent), 2); // Send PIR status to gateway
sentValue = percent;
// Send batterylevel
sendBattery();
digitalWrite(VCC_PIN, LOW); // Turn on Moisture sensor
// Sleep 4 hours
node.sleep(14400000);
}
// FUNCTIONS
void sendBattery() // Send battery percentage to GW
{
forceSend++;
int batteryPcnt = min(map(readVcc(), MIN_V, MAX_V, 0, 100), 100); // Get VCC and convert to percentage
if (batteryPcnt != oldBatteryPcnt || forceSend >= 20) { // If battery percentage has changed
node.sendBatteryLevel(batteryPcnt); // Send battery percentage to gateway
oldBatteryPcnt = batteryPcnt;
forceSend = 0;
}
}
void resend(MyMessage &msg, int repeats) // Resend messages if not received by GW
{
int repeat = 0;
int repeatDelay = 0;
boolean ack = false;
while ((ack == false) and (repeat < repeats)) {
if (node.send(msg)) {
ack = true;
} else {
ack = false;
repeatDelay += 100;
}
repeat++;
delay(repeatDelay);
}
}
Pimatic device config
{
"class": "MySensorsMulti",
"id": "Soil_Palme",
"name": "Wasserstand Palme",
"attributes": [
{
"name": "Wasserstand Palme",
"nodeid": 6,
"sensorid": 6,
"type": "integer",
"unit": "%",
"sensortype": 37
},
{
"name": "Battery",
"nodeid": 6,
"type": "battery",
"unit": "%"
}
]
}
and how they looks like
@dynamite, nice PIR-Case!! looks very good i want 5 of them too… would you like to share your sketch ans schematics with us??
edit: added #define MY_RADIO_NRF24 for MySensors 2.0