Nodes only seen once with using I/O pin as power



  • Hi there,

    I'm having a 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 was 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 and back to high 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..?



  • Why do you delay so much?

    I would try this:

    #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);
    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);
    
    }
    
    void loop(){
    // Turn sensor On
    digitalWrite(power, HIGH);
    // read the value from the sensor:
    delay (5000);
    sensorValue = analogRead(sensorPin);
    // Turn sensor Off
    digitalWrite(power, LOW);
    
    int lastsensorValue = sensorValue;
    
    Serial.println(sensorValue);
    int sendValue =  map(sensorValue, 0, 842, 0, 100); 
    gw.send( msg.set( sendValue ) );
    gw.sleep(60000);  
    }


  • Hi, thanks for your reply. I was using delay so much because it seemed that the radio and sensor both needed some time to start up after they were powered on by puting pin 4 high.

    Using your sketch wasn't working because both the radio and sensor are powered by the same pin. In the Void setup the pin was not set high so the node and radio were not started and it would not come to the loop part of thee sketch.

    Also I've put the digitalWrite low at the end before puting it to sleep, because otherwise it would not sent anything because being powered off.

    Making this small changes to your sketch still made it be presented to the gateway only once. Could there be a problem in puting pin 4 high both in the setup and the loop part? This is the code right now...

    #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);
    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);
    
    }
    
    void loop(){
    // Turn sensor On
    digitalWrite(power, HIGH);
    // read the value from the sensor:
    delay (5000);
    sensorValue = analogRead(sensorPin);
    
    
    int lastsensorValue = sensorValue;
    
    Serial.println(sensorValue);
    int sendValue =  map(sensorValue, 0, 842, 0, 100); 
    gw.send( msg.set( sendValue ) );
    // Turn sensor Off
    digitalWrite(power, LOW);
    gw.sleep(60000);  
    }
    


  • I expect that if you power down the radio module you have to reinitialize it before you can use it.

    Just try to only power down the sensor and check if this is working.



  • Cheers, when only powering down the sensor it is working now! Is there a way to reinitialize the radio after powering it down or do you know of other ways to reduce the power usage of the radio?



  • @Bram81 said:

    Hi, thanks for your reply. I was using delay so much because it seemed that the radio and sensor both needed some time to start up after they were powered on by puting pin 4 high.

    Aha, that you didn't mentioned in your request, but does make a huge difference.

    As gloob says, you have to reinitialize the radio again after waking up. I never done that but you can try calling gw.begin(); after setting your sensor/radio pin high.



  • @ericvdb
    Hi, yeah sorry for that. I only realised that when I took a closer look at your sketch because it gave me the check wires message..
    Thanks a lot, I've now put the radio on a seperate pin too powering it down and let the radio reinitialize by using gw.begin(); in the void loop section.

    This is the final code now and it is working well!

    #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;
    int radio =5; 
    MySensor gw;
    MyMessage msg(CHILD_ID_LIGHT, V_HUM);
    int lastLightLevel;
    
    void setup(){
    pinMode(power, OUTPUT);
    digitalWrite(power, HIGH);
    pinMode(radio, OUTPUT);
    digitalWrite(radio, HIGH);
    delay (5000);
    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);
    
    digitalWrite(power, LOW);
    }
    
    void loop(){
    // Turn sensor On
    digitalWrite(power, HIGH);
    // Turn Radio on 
    digitalWrite(radio, HIGH);
    // read the value from the sensor:
    delay (5000);
    gw.begin();
    sensorValue = analogRead(sensorPin);
    
    
    int lastsensorValue = sensorValue;
    
    Serial.println(sensorValue);
    int sendValue =  map(sensorValue, 0, 842, 0, 100); 
    gw.send( msg.set( sendValue ) );
    // Turn sensor Off
    digitalWrite(power, LOW);
    // Turn radio off
    digitalWrite(radio, LOW);
    gw.sleep(3600000);  
    }```

Log in to reply
 

Suggested Topics

  • 3
  • 3
  • 2
  • 2
  • 10
  • 1

1
Online

11.2k
Users

11.1k
Topics

112.5k
Posts