Hi there,
I'm having another sketch problem.. In order to try and save battery power on my moisture sensors I'm trying to use a IO pin as power by setting it high for some time, let the sensor take a measurement, send the results to the gateway, setting the IO pin low again, let the node go to sleep for some time .
This works only one time, the node presents itself to the gateway, sends data but after that it's not seen again after the expected sleep time.
My guess is that somehow after puting the IO pin low it doesn't come back up in a high state. The strange thing is that when I measure the current on the pins of my moisture sensor with a multimeter the current goes from 0 to aprox 4.27V in the given time, so actually that indicates the pin is going from high to low as needed, but somehow the radio doesn't come back up... This is my code:
#include <SPI.h>
#include <MySensor.h>
#define CHILD_ID_LIGHT 0
#define LIGHT_SENSOR_ANALOG_PIN 1
#define MIN 300 // Liquid
#define MAX 700 // Air
int sensorPin = A0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
int power =4;
MySensor gw;
MyMessage msg(CHILD_ID_LIGHT, V_HUM);
int lastLightLevel;
void setup(){
pinMode(power, OUTPUT);
digitalWrite(power, HIGH);
delay(3000);
Serial.begin(9600);
gw.begin();
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Mobile Sensor 1", "Kruiden");
// Register all sensors to gateway (they will be created as child devices)
gw.present(CHILD_ID_LIGHT, S_HUM);
delay (2000);
}
void loop(){
// read the value from the sensor:
digitalWrite(power, HIGH);
delay (5000);
sensorValue = analogRead(sensorPin);
delay(1000);
int lastsensorValue = sensorValue;
Serial.println(sensorValue);
int sendValue = map(sensorValue, 0, 842, 0, 100);
gw.send( msg.set( sendValue ) );
delay(10000);
digitalWrite(power, LOW);
delay (2000);
gw.sleep(60000);
}
Does anyone have any clue..?