Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Hardware
  3. Temp/Humidity/Light Sensor on battery

Temp/Humidity/Light Sensor on battery

Scheduled Pinned Locked Moved Hardware
3 Posts 2 Posters 7.2k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dheeraj
    Plugin Developer
    wrote on last edited by Dheeraj
    #1

    After a long time tried making a node with temperature, relative humidity and light sensors. 2015-04-03 13.00.18.jpg
    Running sensor node on 9v battery..actually i have bought ample of 9v batteries. sensor node is running for last 15 days.. ignore the dip in the battery levels due to non-battery mode .
    upload-cd163fd8-f48d-4e84-95f6-8d340f725709
    LDR and DHT11 sensors connected on PCB..
    2015-04-03 13.00.40.jpg
    final product2015-04-03 13.05.34.jpg
    upload-99d006c0-7a49-49f8-953d-964c221803be

    D 1 Reply Last reply
    1
    • D Dheeraj

      After a long time tried making a node with temperature, relative humidity and light sensors. 2015-04-03 13.00.18.jpg
      Running sensor node on 9v battery..actually i have bought ample of 9v batteries. sensor node is running for last 15 days.. ignore the dip in the battery levels due to non-battery mode .
      upload-cd163fd8-f48d-4e84-95f6-8d340f725709
      LDR and DHT11 sensors connected on PCB..
      2015-04-03 13.00.40.jpg
      final product2015-04-03 13.05.34.jpg
      upload-99d006c0-7a49-49f8-953d-964c221803be

      D Offline
      D Offline
      Dwalt
      wrote on last edited by
      #2

      @Dheeraj Very nice. Do you mind sharing your sketch?

      Veralite UI5 :: IBoard Ethernet GW :: MyS 1.5

      D 1 Reply Last reply
      0
      • D Dwalt

        @Dheeraj Very nice. Do you mind sharing your sketch?

        D Offline
        D Offline
        Dheeraj
        Plugin Developer
        wrote on last edited by
        #3

        @Dwalt

        actually the sketch is simple.

        #include <SPI.h> 
        #include <MySensor.h>  
        #include <DHT.h>  
        
        #define CHILD_ID_HUM 0
        #define CHILD_ID_TEMP 1
        #define CHILD_ID_LIGHT 2
        #define HUMIDITY_SENSOR_DIGITAL_PIN 4
        #define BATTERY_SENSE_PIN  A0  // select the input pin for the battery sense point
        #define LIGHT_SENSOR_ANALOG_PIN A1
        
        unsigned long SLEEP_TIME = 60000; // Sleep time between reads (in milliseconds)
        
        MySensor gw;
        DHT dht;
        float lastTemp;
        float lastHum;
        boolean metric = true; 
        MyMessage msgHum(CHILD_ID_HUM, V_HUM);
        MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
        MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
        int oldBatteryPcnt = 0;
        int battLoop =0;
        int lightLevel =0;
        int lastLightLevel =0;
        
        void setup()  
        { 
          gw.begin(NULL,15);
          dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
        
          // Send the Sketch Version Information to the Gateway
          gw.sendSketchInfo("Temp Humidity Light", "1.0");
        
          // Register all sensors to gw (they will be created as child devices)
          gw.present(CHILD_ID_HUM, S_HUM);
          gw.present(CHILD_ID_TEMP, S_TEMP);
          gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
          
          metric = gw.getConfig().isMetric;
          check_batt();
        }
        
        void loop()      
        {  
          delay(dht.getMinimumSamplingPeriod());
        
          float temperature = dht.getTemperature();
          if (isnan(temperature)) {
              Serial.println("Failed reading temperature from DHT");
          } else if (temperature != lastTemp) {
            lastTemp = temperature;
            if (!metric) {
              temperature = dht.toFahrenheit(temperature);
            }
            gw.send(msgTemp.set(temperature, 1));
            Serial.print("T: ");
            Serial.println(temperature);
          }
          
          float humidity = dht.getHumidity();
          if (isnan(humidity)) {
              Serial.println("Failed reading humidity from DHT");
          } else if (humidity != lastHum) {
              
              lastHum = humidity;
              gw.send(msgHum.set(humidity, 1));
              Serial.print("H: ");
              Serial.println(humidity);
          }
          
          lightLevel = (analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23; 
          if (lightLevel != lastLightLevel) {
              Serial.println(lightLevel);
              gw.send(msg.set(lightLevel));
              lastLightLevel = lightLevel;
          }
          battLoop++;
          if (battLoop > 10)
          {
              check_batt();
              battLoop=0;
          }
          gw.sleep(SLEEP_TIME); //sleep a bit
          
          
        }
        
        void check_batt()
        {
          // get the battery Voltage
          int sensorValue = analogRead(BATTERY_SENSE_PIN);
          Serial.println(sensorValue);
          
          // 1M, 470K divider across battery and using internal ADC ref of 1.1V
          // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
          // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
          // 3.44/1023 = Volts per bit = 0.003363075
          // vout = (sensorvalue x 3.3) / 1023
          //vin = vout /  (R2/(R1+R2)); 
         
          float batteryV  = ( sensorValue * 0.003225806 ) / 0.3; // divide R2/(R1+R2)
          int batteryPcnt = sensorValue / 10 ;
          if ( batteryPcnt > 100 )
          batteryPcnt = 100;
          
          Serial.print("Battery Voltage: ");
          Serial.print(batteryV);
          Serial.println(" V");
          Serial.print("Battery percent: ");
          Serial.print(batteryPcnt);
          Serial.println(" %");
        
          if (oldBatteryPcnt != batteryPcnt)
          {
            // Power up radio after sleep
            gw.sendBatteryLevel(batteryPcnt);
            oldBatteryPcnt = batteryPcnt;
          }
        
        }
        //```
        1 Reply Last reply
        0

        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
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        15

        Online

        12.0k

        Users

        11.2k

        Topics

        113.4k

        Posts


        Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • MySensors
        • OpenHardware.io
        • Categories
        • Recent
        • Tags
        • Popular