Skip to content
  • 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. My Project
  3. My 2AA battery sensor
  • Getting Started
  • Controller
  • Build
  • Hardware
  • Download/API
  • Forum
  • Store

My 2AA battery sensor

Scheduled Pinned Locked Moved My Project
90 Posts 27 Posters 106.6k Views 36 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.
  • N Nicklas Starkel

    @EasyIoT , how are your sensors doing, its been 2 years :)
    And also, @m26872 , the node 105. Is it alive?

    m26872M Offline
    m26872M Offline
    m26872
    Hardware Contributor
    wrote on last edited by
    #80

    @Nicklas-Starkel I've been busy for few months moving to a new house and have had my sensor network offline until now because of this. Node 105 was kept on and handled with care, but I was pretty sure it would be dead when I started my gateway yesterday. BUT, it was ALIVE ?! at 14% battery level. Amazing! 24 months with such poor and simple hardware and software. :exclamation: :two_hearts: :star: :musical_note: :dancers: :clap: :muscle: Same batteries and only one restart (due to my controller change last year).
    One little remark though, it doesn't seem to send temperature och pressure, only humidity and battery level. Maybe an issue of voltage recovery time between transmissions.

    1 Reply Last reply
    6
    • S Offline
      S Offline
      sineverba
      Hardware Contributor
      wrote on last edited by
      #81
      This post is deleted!
      1 Reply Last reply
      0
      • S Offline
        S Offline
        sineverba
        Hardware Contributor
        wrote on last edited by
        #82

        Sorry for the noob question...
        I would re-create your setup. At which point of it you insert the multimeter to measure the current?

        Is it ok to "interrupt" the ground (proximity to the step up) and measure the current there?

        Thank you

        m26872M 1 Reply Last reply
        0
        • S sineverba

          Sorry for the noob question...
          I would re-create your setup. At which point of it you insert the multimeter to measure the current?

          Is it ok to "interrupt" the ground (proximity to the step up) and measure the current there?

          Thank you

          m26872M Offline
          m26872M Offline
          m26872
          Hardware Contributor
          wrote on last edited by
          #83

          @sineverba Just cut one of the battery wires of the finished assembly. Solder together again when your done measuring.

          1 Reply Last reply
          1
          • P Offline
            P Offline
            palmerfarmer
            wrote on last edited by
            #84

            Has anyone got a V2 version working for this?

            F 1 Reply Last reply
            0
            • P palmerfarmer

              Has anyone got a V2 version working for this?

              F Offline
              F Offline
              flopp
              wrote on last edited by
              #85

              @palmerfarmer said in My 2AA battery sensor:

              Has anyone got a V2 version working for this?

              Do you mean running with MySensors 2.3?

              1 Reply Last reply
              0
              • P Offline
                P Offline
                palmerfarmer
                wrote on last edited by
                #86

                Any Ver 2.xx,
                So I have cobbled together/hacked this and it seem to work, battery has stayed at 97% for 2 weeks now. Feel free to Hack about and improve i have this mounted on an easyPCB board, x2AA batteries, NRF radio, BME280 with a 3.3v convertor .

                /*   
                * use mysensors library 2.2.0
                * ALL WORKING AND TESTED ON EASY PCB BOARD WITH BATTERY SAVING CODE 29/11/18
                *
                * Time SET to 15 mins
                * also added BME280.writeMode (smSleep); to reduce quisecent to current to 40uA
                * BME280 sensor connections: 3.3v, 0V, SCL to A5, SDA to A4, BAT to A0
                **/
                
                //Enable debug prints to serial monitor
                #define MY_DEBUG 
                
                // Enable and select radio type attached
                #define MY_RADIO_NRF24
                #define MY_RF24_PA_LEVEL RF24_PA_MIN //settings are MIN, LOW, HIGH, MAX
                #define MY_NODE_ID 18
                //#define MY_RADIO_RFM69
                
                #include <SPI.h>
                #include <MySensors.h>  
                #include <Wire.h>
                #include <BME280_MOD-1022.h>
                
                // BME280 libraries and variables
                // Bosch BME280 Embedded Adventures MOD-1022 weather multi-sensor Arduino code
                // Written originally by Embedded Adventures
                // https://github.com/embeddedadventures/BME280
                
                
                #define BARO_CHILD 0
                #define TEMP_CHILD 1
                #define HUM_CHILD 2
                
                
                int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
                
                unsigned long SLEEP_TIME = 15*60000;  // sleep time between reads (seconds x*1000 milliseconds)
                //unsigned long SLEEP_TIME = 20000;  // Debug test time 20 seconds
                int oldBatteryPcnt = 0;
                
                    
                long interval = 1000;                // 1 min interval at which to send (milliseconds)
                long previousMillis = interval;        // will store last time data was sent
                
                const float ALTITUDE = 0; // <-- adapt this value to your location's altitude (in m). Use your smartphone GPS to get an accurate value!
                
                const char *weather[] = { "stable", "sunny", "cloudy", "unstable", "thunderstorm", "unknown" };
                enum FORECAST
                {
                  STABLE = 0,     // "Stable Weather Pattern"
                  SUNNY = 1,      // "Slowly rising Good Weather", "Clear/Sunny "
                  CLOUDY = 2,     // "Slowly falling L-Pressure ", "Cloudy/Rain "
                  UNSTABLE = 3,   // "Quickly rising H-Press",     "Not Stable"
                  THUNDERSTORM = 4, // "Quickly falling L-Press",    "Thunderstorm"
                  UNKNOWN = 5     // "Unknown (More Time needed)
                };
                
                
                const int LAST_SAMPLES_COUNT = 5;
                float lastPressureSamples[LAST_SAMPLES_COUNT];
                
                
                // this CONVERSION_FACTOR is used to convert from Pa to kPa in the forecast algorithm
                // get kPa/h by dividing hPa by 10 
                #define CONVERSION_FACTOR (1.0/10.0)
                
                int minuteCount = 0;
                bool firstRound = true;
                // average value is used in forecast algorithm.
                float pressureAvg;
                // average after 2 hours is used as reference value for the next iteration.
                float pressureAvg2;
                
                float dP_dt;
                boolean metric;
                MyMessage tempMsg(TEMP_CHILD, V_TEMP);
                MyMessage humMsg(HUM_CHILD, V_HUM);
                MyMessage pressureMsg(BARO_CHILD, V_PRESSURE);
                
                float getLastPressureSamplesAverage()
                {
                  float lastPressureSamplesAverage = 0;
                  for (int i = 0; i < LAST_SAMPLES_COUNT; i++)
                  {
                    lastPressureSamplesAverage += lastPressureSamples[i];
                  }
                  lastPressureSamplesAverage /= LAST_SAMPLES_COUNT;
                
                  return lastPressureSamplesAverage;
                }
                
                
                // Algorithm found here
                // http://www.freescale.com/files/sensors/doc/app_note/AN3914.pdf
                // Pressure in hPa -->  forecast done by calculating kPa/h
                int sample(float pressure)
                {
                  // Calculate the average of the last n minutes.
                  int index = minuteCount % LAST_SAMPLES_COUNT;
                  lastPressureSamples[index] = pressure;
                
                  minuteCount++;
                  if (minuteCount > 185)
                  {
                    minuteCount = 6;
                  }
                
                  if (minuteCount == 5)
                  {
                    pressureAvg = getLastPressureSamplesAverage();
                  }
                  else if (minuteCount == 35)
                  {
                    float lastPressureAvg = getLastPressureSamplesAverage();
                    float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
                    if (firstRound) // first time initial 3 hour
                    {
                      dP_dt = change * 2; // note this is for t = 0.5hour
                    }
                    else
                    {
                      dP_dt = change / 1.5; // divide by 1.5 as this is the difference in time from 0 value.
                    }
                  }
                  else if (minuteCount == 65)
                  {
                    float lastPressureAvg = getLastPressureSamplesAverage();
                    float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
                    if (firstRound) //first time initial 3 hour
                    {
                      dP_dt = change; //note this is for t = 1 hour
                    }
                    else
                    {
                      dP_dt = change / 2; //divide by 2 as this is the difference in time from 0 value
                    }
                  }
                  else if (minuteCount == 95)
                  {
                    float lastPressureAvg = getLastPressureSamplesAverage();
                    float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
                    if (firstRound) // first time initial 3 hour
                    {
                      dP_dt = change / 1.5; // note this is for t = 1.5 hour
                    }
                    else
                    {
                      dP_dt = change / 2.5; // divide by 2.5 as this is the difference in time from 0 value
                    }
                  }
                  else if (minuteCount == 125)
                  {
                    float lastPressureAvg = getLastPressureSamplesAverage();
                    pressureAvg2 = lastPressureAvg; // store for later use.
                    float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
                    if (firstRound) // first time initial 3 hour
                    {
                      dP_dt = change / 2; // note this is for t = 2 hour
                    }
                    else
                    {
                      dP_dt = change / 3; // divide by 3 as this is the difference in time from 0 value
                    }
                  }
                  else if (minuteCount == 155)
                  {
                    float lastPressureAvg = getLastPressureSamplesAverage();
                    float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
                    if (firstRound) // first time initial 3 hour
                    {
                      dP_dt = change / 2.5; // note this is for t = 2.5 hour
                    }
                    else
                    {
                      dP_dt = change / 3.5; // divide by 3.5 as this is the difference in time from 0 value
                    }
                  }
                  else if (minuteCount == 185)
                  {
                    float lastPressureAvg = getLastPressureSamplesAverage();
                    float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
                    if (firstRound) // first time initial 3 hour
                    {
                      dP_dt = change / 3; // note this is for t = 3 hour
                    }
                    else
                    {
                      dP_dt = change / 4; // divide by 4 as this is the difference in time from 0 value
                    }
                    pressureAvg = pressureAvg2; // Equating the pressure at 0 to the pressure at 2 hour after 3 hours have past.
                    firstRound = false; // flag to let you know that this is on the past 3 hour mark. Initialized to 0 outside main loop.
                  }
                
                  int forecast = UNKNOWN;
                  if (minuteCount < 35 && firstRound) //if time is less than 35 min on the first 3 hour interval.
                  {
                    forecast = UNKNOWN;
                  }
                  else if (dP_dt < (-0.25))
                  {
                    forecast = THUNDERSTORM;
                  }
                  else if (dP_dt > 0.25)
                  {
                    forecast = UNSTABLE;
                  }
                  else if ((dP_dt > (-0.25)) && (dP_dt < (-0.05)))
                  {
                    forecast = CLOUDY;
                  }
                  else if ((dP_dt > 0.05) && (dP_dt < 0.25))
                  {
                    forecast = SUNNY;
                  }
                  else if ((dP_dt >(-0.05)) && (dP_dt < 0.05))
                  {
                    forecast = STABLE;
                  }
                  else
                  {
                    forecast = UNKNOWN;
                  }
                
                  return forecast;
                }
                
                
                
                void setup() 
                
                {
                   // use the 1.1 V internal reference
                #if defined(__AVR_ATmega2560__)
                   analogReference(INTERNAL1V1);
                #else
                   analogReference(INTERNAL);
                #endif
                
                  metric = getControllerConfig().isMetric;  // was getConfig().isMetric; before MySensors v2.1.1
                  Wire.begin(); // Wire.begin(sda, scl)
                  // use the 1.1 V internal reference
                  #if defined(__AVR_ATmega2560__)
                  analogReference(INTERNAL1V1);
                  #else
                  analogReference(INTERNAL);
                  #endif
                }
                
                void presentation()  {
                  // Send the sketch version information to the gateway and Controller
                  sendSketchInfo("BME280_BAT_V2", "V2e.");
                
                  // Register sensors to gw (they will be created as child devices)
                  present(BARO_CHILD, S_BARO);
                  present(TEMP_CHILD, S_TEMP);
                  present(HUM_CHILD, S_HUM);
                
                }
                
                // Loop
                void loop() {
                
                {
                   // get the battery Voltage
                   int sensorValue = analogRead(BATTERY_SENSE_PIN);
                   #ifdef MY_DEBUG
                   Serial.println(sensorValue);
                   #endif
                
                   // 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
                
                   int batteryPcnt = sensorValue / 10;
                
                   #ifdef MY_DEBUG
                   float batteryV  = sensorValue * 0.003363075;
                   Serial.print("Battery Voltage: ");
                   Serial.print(batteryV);
                   Serial.println(" V");
                
                   Serial.print("Battery percent: ");
                   Serial.print(batteryPcnt);
                   Serial.println(" %");
                   #endif
                
                   if (oldBatteryPcnt != batteryPcnt) {
                     // Power up radio after sleep
                     sendBatteryLevel(batteryPcnt);
                     oldBatteryPcnt = batteryPcnt;
                   }
                 //  sleep(SLEEP_TIME);
                }
                
                
                unsigned long currentMillis = millis();  
                
                if(currentMillis - previousMillis > interval) {
                    // save the last time sent the data
                    previousMillis = currentMillis;
                
                  analogReference(INTERNAL);
                  wait(500);
                  
                  // need to read the NVM compensation parameters
                  BME280.readCompensationParams();
                
                  // Normal mode for regular automatic samples
                  BME280.writeStandbyTime(tsb_0p5ms);         // tsb = 0.5ms
                  BME280.writeFilterCoefficient(fc_16);       // IIR Filter coefficient 16
                  BME280.writeOversamplingPressure(os16x);    // pressure x16
                  BME280.writeOversamplingTemperature(os8x);  // temperature x8
                  BME280.writeOversamplingHumidity(os8x);     // humidity x8
                  
                  BME280.writeMode(smNormal);
                
                    // Just to be sure, wait until sensor is done mesuring  
                    while (BME280.isMeasuring()) {
                  }
                
                  // Read out the data - must do this before calling the getxxxxx routines
                  BME280.readMeasurements();
                
                  float temperature = BME280.getTemperatureMostAccurate();                    // must get temp first
                  float humidity = BME280.getHumidityMostAccurate();
                  float pressure_local = BME280.getPressureMostAccurate();                    // Get pressure at current location
                  float pressure = pressure_local/pow((1.0 - ( ALTITUDE / 44330.0 )), 5.255); // Adjust to sea level pressure using user altitude
                  int forecast = sample(pressure);
                
                  if (!metric) 
                  {
                    // Convert to fahrenheit
                    temperature = temperature * 9.0 / 5.0 + 32.0;
                  }
                //**/
                  Serial.println();
                  Serial.print("Temperature = ");
                  Serial.print(temperature);
                  Serial.println(metric ? " °C" : " °F");
                  Serial.print("Humidity = ");
                  Serial.print(humidity);
                  Serial.println(" %");
                  Serial.print("Pressure = ");
                  Serial.print(pressure);
                  Serial.println(" hPa");
                  Serial.print("Forecast = ");
                  Serial.println(weather[forecast]);
                  Serial.println();
                //*/
                
                    send(tempMsg.set(temperature, 1));
                wait(50);
                    send(humMsg.set(humidity, 1));
                wait(50);
                    send(pressureMsg.set(pressure, 2));
                wait(50);
                
                BME280.writeMode (smSleep);
                sleep(SLEEP_TIME);
                
                }
                
                }
                
                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  palmerfarmer
                  wrote on last edited by palmerfarmer
                  #87

                  11months on battery at 87%... still working!0_1574260268012_BME280 battery.JPG

                  TRS-80T 1 Reply Last reply
                  5
                  • P Offline
                    P Offline
                    palmerfarmer
                    wrote on last edited by
                    #88
                    This post is deleted!
                    1 Reply Last reply
                    0
                    • P palmerfarmer

                      11months on battery at 87%... still working!0_1574260268012_BME280 battery.JPG

                      TRS-80T Offline
                      TRS-80T Offline
                      TRS-80
                      wrote on last edited by
                      #89

                      @palmerfarmer,

                      That project box is perfect! Where did you find it (it doesn't look printed)?

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        palmerfarmer
                        wrote on last edited by
                        #90

                        I got it from CPC in the UK which are owned by Farnell
                        https://cpc.farnell.com/hammond/1593qgy/case-with-bat-compart-110x66x28mm/dp/EN82140
                        You may have to make a slight mod to the board or enclosure to make it fit.
                        good luck

                        1 Reply Last reply
                        1
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        18

                        Online

                        11.7k

                        Users

                        11.2k

                        Topics

                        113.0k

                        Posts


                        Copyright 2019 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
                        • OpenHardware.io
                        • Categories
                        • Recent
                        • Tags
                        • Popular