How to add a sensor to the serial gateway
-
@Bram81
I would try (not at home and cant try):int Analog_Input_Soil_Sensor= A0;
int Analog_Input_Soil_Sensor = 0;as you wrote before, and not #define interrupt analog_input_soil_sensor -2
Also you get only 0 and 1 because this is what you send to the gateway: gw.send(Msg.set(soilva... 0?1:0)
Either you have to define what 0 and 1 is (say dry = 0 moist = 1) or if you want to send it as % use another gw.send code. -
Here is an example of someone build a soil sensor using the light_sensor
http://forum.mysensors.org/topic/1492/soil-moisture-analog-input-question
If you remove the battery code this could be used if you connect to analog pin (Se code below)#include <SPI.h> #include <MySensor.h> #define CHILD_ID_LIGHT 0 #define LIGHT_SENSOR_ANALOG_PIN 1 MySensor gw; MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL); int lastLightLevel; void setup() { gw.begin(); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Soil_Moist_Sensor_grb", "1.15"); // Register all sensors to gateway (they will be created as child devices) gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); } void loop() { int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23; Serial.println(lightLevel); if (lightLevel != lastLightLevel) { gw.send(msg.set(lightLevel)); lastLightLevel = lightLevel; } }if you want lightlevel in % with a Min and a Max then:
#include <SPI.h> #include <MySensor.h> #define CHILD_ID_LIGHT 0 #define LIGHT_SENSOR_ANALOG_PIN 1 #define MIN 300 // Liquid #define MAX 1023 // Air MySensor gw; MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL); int lastLightLevel; void setup() { gw.begin(); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Soil_Moist_Sensor_grb", "1.15"); // Register all sensors to gateway (they will be created as child devices) gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); } void loop() { int lightLevel = static_cast<int>(((analogRead(LIGHT_SENSOR_ANALOG_PIN)-MIN)/(MAX-MIN))*100.); Serial.println(lightLevel); if (lightLevel != lastLightLevel) { gw.send(msg.set(lightLevel)); lastLightLevel = lightLevel; } }I have read some more...
About the digital pin and use (as you mentioned at first... )
It looks like there is a switch/nob on the hardware you can turn.
This will set the trigger point between dry and moist and send 1 or 0.
I think thats why the scetches was using S_Motion... either its dry (untriggered) or wet (triggered).
I dont know how to program or wire this though...Best of luck :) Hope i didnt just complicate things...
-
Here is an example of someone build a soil sensor using the light_sensor
http://forum.mysensors.org/topic/1492/soil-moisture-analog-input-question
If you remove the battery code this could be used if you connect to analog pin (Se code below)#include <SPI.h> #include <MySensor.h> #define CHILD_ID_LIGHT 0 #define LIGHT_SENSOR_ANALOG_PIN 1 MySensor gw; MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL); int lastLightLevel; void setup() { gw.begin(); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Soil_Moist_Sensor_grb", "1.15"); // Register all sensors to gateway (they will be created as child devices) gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); } void loop() { int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23; Serial.println(lightLevel); if (lightLevel != lastLightLevel) { gw.send(msg.set(lightLevel)); lastLightLevel = lightLevel; } }if you want lightlevel in % with a Min and a Max then:
#include <SPI.h> #include <MySensor.h> #define CHILD_ID_LIGHT 0 #define LIGHT_SENSOR_ANALOG_PIN 1 #define MIN 300 // Liquid #define MAX 1023 // Air MySensor gw; MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL); int lastLightLevel; void setup() { gw.begin(); // Send the sketch version information to the gateway and Controller gw.sendSketchInfo("Soil_Moist_Sensor_grb", "1.15"); // Register all sensors to gateway (they will be created as child devices) gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL); } void loop() { int lightLevel = static_cast<int>(((analogRead(LIGHT_SENSOR_ANALOG_PIN)-MIN)/(MAX-MIN))*100.); Serial.println(lightLevel); if (lightLevel != lastLightLevel) { gw.send(msg.set(lightLevel)); lastLightLevel = lightLevel; } }I have read some more...
About the digital pin and use (as you mentioned at first... )
It looks like there is a switch/nob on the hardware you can turn.
This will set the trigger point between dry and moist and send 1 or 0.
I think thats why the scetches was using S_Motion... either its dry (untriggered) or wet (triggered).
I dont know how to program or wire this though...Best of luck :) Hope i didnt just complicate things...
@sundberg84 Hey! Thank you verry much for your help and suggestions!!
I actually got it working combining your sketch witch my simple one resulting in this:#include <SPI.h>
#include <MySensor.h>#define CHILD_ID_LIGHT 0
#define LIGHT_SENSOR_ANALOG_PIN 1
#define MIN 300 // Liquid
#define MAX 1023 // Airint sensorPin = A0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensorMySensor gw;
MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
int lastLightLevel;void setup(){
Serial.begin(9600);
gw.begin();
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Soil_Moist_Sensor_grb", "1.15");// Register all sensors to gateway (they will be created as child devices)
gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
}void loop(){
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
delay(1000);
Serial.print("sensor = " );
Serial.println(sensorValue);
gw.send(msg.set(sensorValue));
}The sensor shows up in Domoticz as a light sensor meassuring in lux, but the numbers do match the output of the sensor.
Another thing is that after about 15 min the gateway started functioning. Seems like a problem that I had last week returned...
Loading the board with the pingpongtest shows that suddenly my radio chip is recognized as NRF24L01 instead of the + version, although the label on te chips shows NRF24L01+
Changing radios doesn't help, I'm completely in the dark... maybe just shitty radios..?
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login