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. Troubleshooting
  3. ds18b20 on 2xAAA battery

ds18b20 on 2xAAA battery

Scheduled Pinned Locked Moved Troubleshooting
34 Posts 10 Posters 3.1k Views 8 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.
  • pihomeP Offline
    pihomeP Offline
    pihome
    wrote on last edited by
    #1

    Hi All,
    i have nodes running on 18650 battery on Arduino mini pro 8mhz (3.3v) without much modification or any low power bootloader but now i want to switch to AAA battery to keep everything tidy and need but one issue ds18b20 requires 3.3v whereas 2xAAA can supply 3v, now million dollar question is what you guys doing to supply 3.3v to ds18b20? boost converter consume power as well and all on ebay/aliexpress ones are seems very power hungry (Quiescent current 13uA).
    https://www.aliexpress.com/item/32800430445.html?spm=2114.search0104.3.219.5b3d1a25h7pRRv&ws_ab_test=searchweb0_0%2Csearchweb201602_2_10065_10068_319_10059_10884_317_10887_10696_321_322_10084_453_10083_454_10103_10618_10304_10307_10820_10821_537_10302_536%2Csearchweb201603_51%2CppcSwitch_0&algo_expid=e6ec65d0-b780-4c66-b06a-52134fa6c454-31&algo_pvid=e6ec65d0-b780-4c66-b06a-52134fa6c454&transAbTest=ae803_3
    i m thinking to find alternate to ds18b20 that can run reliably on 2v,
    any thoughts or suggestions?

    PiHome - Smart Heating Control

    mfalkviddM zboblamontZ K T 4 Replies Last reply
    0
    • pihomeP pihome

      Hi All,
      i have nodes running on 18650 battery on Arduino mini pro 8mhz (3.3v) without much modification or any low power bootloader but now i want to switch to AAA battery to keep everything tidy and need but one issue ds18b20 requires 3.3v whereas 2xAAA can supply 3v, now million dollar question is what you guys doing to supply 3.3v to ds18b20? boost converter consume power as well and all on ebay/aliexpress ones are seems very power hungry (Quiescent current 13uA).
      https://www.aliexpress.com/item/32800430445.html?spm=2114.search0104.3.219.5b3d1a25h7pRRv&ws_ab_test=searchweb0_0%2Csearchweb201602_2_10065_10068_319_10059_10884_317_10887_10696_321_322_10084_453_10083_454_10103_10618_10304_10307_10820_10821_537_10302_536%2Csearchweb201603_51%2CppcSwitch_0&algo_expid=e6ec65d0-b780-4c66-b06a-52134fa6c454-31&algo_pvid=e6ec65d0-b780-4c66-b06a-52134fa6c454&transAbTest=ae803_3
      i m thinking to find alternate to ds18b20 that can run reliably on 2v,
      any thoughts or suggestions?

      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      @pihome https://forum.mysensors.org/topic/3801/witch-temp-hum-sensor-is-best-to-use-for-battery-powered-sensors/ and the linked study is a good source.

      1 Reply Last reply
      0
      • pihomeP pihome

        Hi All,
        i have nodes running on 18650 battery on Arduino mini pro 8mhz (3.3v) without much modification or any low power bootloader but now i want to switch to AAA battery to keep everything tidy and need but one issue ds18b20 requires 3.3v whereas 2xAAA can supply 3v, now million dollar question is what you guys doing to supply 3.3v to ds18b20? boost converter consume power as well and all on ebay/aliexpress ones are seems very power hungry (Quiescent current 13uA).
        https://www.aliexpress.com/item/32800430445.html?spm=2114.search0104.3.219.5b3d1a25h7pRRv&ws_ab_test=searchweb0_0%2Csearchweb201602_2_10065_10068_319_10059_10884_317_10887_10696_321_322_10084_453_10083_454_10103_10618_10304_10307_10820_10821_537_10302_536%2Csearchweb201603_51%2CppcSwitch_0&algo_expid=e6ec65d0-b780-4c66-b06a-52134fa6c454-31&algo_pvid=e6ec65d0-b780-4c66-b06a-52134fa6c454&transAbTest=ae803_3
        i m thinking to find alternate to ds18b20 that can run reliably on 2v,
        any thoughts or suggestions?

        zboblamontZ Offline
        zboblamontZ Offline
        zboblamont
        wrote on last edited by
        #3

        @pihome
        The advantage of the ds18b20 is the one-wire topology, 12 of them here on cat5e to a single node (PSU with 2AA backup), short of installing 12 nodes I found no better option, but your install is undoubtedly different.

        Would it not be worth re-examining the power options or other methods of extending battery life or is reduced volume such a big issue?
        AAA v AA is not a massive difference in size, but a BIG difference in mAh...
        Your Pro-mini will need modified for lower voltage unless it and a booster is powered on/off externally (timer?) but this adds to bulk.
        If the Pro-mini is running purely on battery power, why not switch on/off the booster the dsb20 and a level converter? The power draw should be minimal for such short duration.

        1 Reply Last reply
        0
        • pihomeP pihome

          Hi All,
          i have nodes running on 18650 battery on Arduino mini pro 8mhz (3.3v) without much modification or any low power bootloader but now i want to switch to AAA battery to keep everything tidy and need but one issue ds18b20 requires 3.3v whereas 2xAAA can supply 3v, now million dollar question is what you guys doing to supply 3.3v to ds18b20? boost converter consume power as well and all on ebay/aliexpress ones are seems very power hungry (Quiescent current 13uA).
          https://www.aliexpress.com/item/32800430445.html?spm=2114.search0104.3.219.5b3d1a25h7pRRv&ws_ab_test=searchweb0_0%2Csearchweb201602_2_10065_10068_319_10059_10884_317_10887_10696_321_322_10084_453_10083_454_10103_10618_10304_10307_10820_10821_537_10302_536%2Csearchweb201603_51%2CppcSwitch_0&algo_expid=e6ec65d0-b780-4c66-b06a-52134fa6c454-31&algo_pvid=e6ec65d0-b780-4c66-b06a-52134fa6c454&transAbTest=ae803_3
          i m thinking to find alternate to ds18b20 that can run reliably on 2v,
          any thoughts or suggestions?

          K Offline
          K Offline
          kimot
          wrote on last edited by
          #4

          @pihome
          very power hungry (Quiescent current 13uA) ?
          And do you know, that with AAA (1000 mAh) it is 8 years in standby?
          Maybe self discharge is greater.
          Alternetively use 3xAAA with low quiescent current 3.3V LDO.

          1 Reply Last reply
          2
          • pihomeP Offline
            pihomeP Offline
            pihome
            wrote on last edited by
            #5

            i have done some testing for power consumption, these enamourments are taken using cheap chines multimeter.

            Power consumption when powered by 18650 battery with onboard regulator and power and pin 13 led removed without any further modification:
            18.11 mA startup
            66.9 uA during sleeping
            3.01 mA during Transmission

            Pro mini with 1mhz bootloader and on board regulator/LED removed:
            14.42 mA startup
            7.50 uA during sleeping
            1.40 mA during Transmission

            @zboblamont, i was thinking the same to power on/off boost converter to save some battery. but need to test this and may be integrate boost converter into my pcb.

            @kimot, sorry haven't checked self discharge of any battery also i m trying to fit this temperature sensors in
            small box

            i would prefer to use ds18b20 sensors but also if battery works for 1 to 1.5 years i m happy with that. any suggestion on boost converter?

            PiHome - Smart Heating Control

            zboblamontZ 1 Reply Last reply
            0
            • pihomeP pihome

              i have done some testing for power consumption, these enamourments are taken using cheap chines multimeter.

              Power consumption when powered by 18650 battery with onboard regulator and power and pin 13 led removed without any further modification:
              18.11 mA startup
              66.9 uA during sleeping
              3.01 mA during Transmission

              Pro mini with 1mhz bootloader and on board regulator/LED removed:
              14.42 mA startup
              7.50 uA during sleeping
              1.40 mA during Transmission

              @zboblamont, i was thinking the same to power on/off boost converter to save some battery. but need to test this and may be integrate boost converter into my pcb.

              @kimot, sorry haven't checked self discharge of any battery also i m trying to fit this temperature sensors in
              small box

              i would prefer to use ds18b20 sensors but also if battery works for 1 to 1.5 years i m happy with that. any suggestion on boost converter?

              zboblamontZ Offline
              zboblamontZ Offline
              zboblamont
              wrote on last edited by zboblamont
              #6

              @pihome I have such an arrangement using a small 3v latching dpdt relay to battery feed a 5v booster/ultrasonic/level-converter arrangement, but in my case the pro-mini's onboard booster provides a solid 3.3v and the external crystal runs it at 16MHz, not sure how in your case you could reliably fire a 3v relay with a declining voltage. The trade-offs of detuning a pro-mini to run on low voltage are not necessarily applicable now compared to when Arduino projects were in their infancy. Yes, it works, but it is no longer the only way.
              I selected this product as it preserved full 16MHz 3.3v capabilities in preference to DIY detuning and modifying a cheap pro-mini, no regrets or magic smoke with hobby skills from the valve-era, and thumbs like mallets :stuck_out_tongue_winking_eye: . Aged eyesight is not a problem with 4xc250b's.
              At 6 months in the 2xAA alkalines are on 2.93v, and should nosedive around the 1.7v mark, so well over a year is probable.
              There is nothing exotic about the board's booster circuit component-wise to my limited knowledge, so it is likely available somewhere, just not necessarily cheap from China.
              By way of contrast - the node monitoring the gas meter (no external power demand - reed activated) is running over a year now with the 2xAA batteries still reading 2.95v. I will be interested but not surprised to see it run another year.. - PS They all have onboard RFM69s...
              My point is that there must be equally efficient boosters out there to buy in or DIY, you don't have to change the car because the ash-tray's full.. ;

              1 Reply Last reply
              0
              • pihomeP Offline
                pihomeP Offline
                pihome
                wrote on last edited by
                #7

                @zboblamont, i love your analogy about ash-try in car.
                i just feed arduino with 1mhz bootloader through raw pin with 2xAAA batteries (i know it was very long shot) and it didnt work onboard regulator can not supply enough voltage to ds18b20, but sure i need to look into boost converter.
                before i dive into boost convert i wanted to ask what others are doing and how they are managing voltage for voltage hungry sensors. i have found few examples on openhardware.io all of them are by @NeverDie

                PiHome - Smart Heating Control

                mfalkviddM K 2 Replies Last reply
                1
                • pihomeP pihome

                  @zboblamont, i love your analogy about ash-try in car.
                  i just feed arduino with 1mhz bootloader through raw pin with 2xAAA batteries (i know it was very long shot) and it didnt work onboard regulator can not supply enough voltage to ds18b20, but sure i need to look into boost converter.
                  before i dive into boost convert i wanted to ask what others are doing and how they are managing voltage for voltage hungry sensors. i have found few examples on openhardware.io all of them are by @NeverDie

                  mfalkviddM Offline
                  mfalkviddM Offline
                  mfalkvidd
                  Mod
                  wrote on last edited by mfalkvidd
                  #8

                  @pihome a "low-tech" solution is to use 2xAA to power the mcu and another AA to power the temperature sensor as described by yveaux here. Maybe even use 2xAA and another AAA.

                  1 Reply Last reply
                  1
                  • pihomeP Offline
                    pihomeP Offline
                    pihome
                    wrote on last edited by
                    #9

                    @mfalkvidd having multiple batteries in confined space isn't option.
                    i m leaning towards this Boost Converter

                    PiHome - Smart Heating Control

                    1 Reply Last reply
                    0
                    • nagelcN Offline
                      nagelcN Offline
                      nagelc
                      wrote on last edited by
                      #10

                      Do you even need to boost? I have several ds18b20 nodes running on 2 AA batteries with a ProMini 8Mhz and basic low power mods. Wired like here: https://www.mysensors.org/build/temp

                      I get nearly 2 years on a set of batteries. The ds18b20 seem to work fine at the lower voltages, but I have not tested them rigorously. The output just seems about right.

                      1 Reply Last reply
                      0
                      • pihomeP Offline
                        pihomeP Offline
                        pihome
                        wrote on last edited by
                        #11

                        @nagelc,
                        you AA batteries must be 1.6 or above voltage, as mine had same voltage, in other words when new batteries were supplying 1.6v/AAA it was working fine as soon as voltage dropped to 3.0 temperature sensors stoped, node is sending battery voltage which mean node and radio working fine but ds18b20 stopped.

                        PiHome - Smart Heating Control

                        1 Reply Last reply
                        0
                        • pihomeP pihome

                          @zboblamont, i love your analogy about ash-try in car.
                          i just feed arduino with 1mhz bootloader through raw pin with 2xAAA batteries (i know it was very long shot) and it didnt work onboard regulator can not supply enough voltage to ds18b20, but sure i need to look into boost converter.
                          before i dive into boost convert i wanted to ask what others are doing and how they are managing voltage for voltage hungry sensors. i have found few examples on openhardware.io all of them are by @NeverDie

                          K Offline
                          K Offline
                          kimot
                          wrote on last edited by
                          #12

                          @pihome
                          said in ds18b20 on 2xAAA battery:

                          i wanted to ask what others are doing and how they are managing voltage for voltage hungry sensors

                          One useful "switch" you have got on your PRO MINI.
                          My from ebay has got LDO marked LG33, which is MIC5219 LDO with shutdown pin capability.
                          So remove one from arduino hacked for ultra low consumption and use it for switch power hungry sensors.

                          Or only unsolder and bend up from pcb output and shutdown pin of LDO.
                          Then you can use 3AAA to power directly VCC ( 4.5V ). Connect this to RAW pin ( input LDO ) too.
                          Your sensors connect to unsoldered LDO output pin and shutdown pin connect with some output IO to drive your sensors ON/OFF.
                          Problem can be, that sensors run on 3.3V and your Arduino runs on 4.5V.
                          So you can put some diodes in series between battery and Vcc pin. Each diode ( not LED ) drops about 0.6V ( try different diodes ).
                          Another interesting idea with this LDO can be seen here:

                          https://forum.arduino.cc/index.php?topic=360996.15

                          1 Reply Last reply
                          0
                          • pihomeP Offline
                            pihomeP Offline
                            pihome
                            wrote on last edited by
                            #13

                            so far i have temperature sensors running on 18650 battery by feeding to raw pin on arduino and it works fine now i'm switching to 2xAAA battery and at this stage i think i have no option but to go for boost converter to power sensor on the node, i wish i had space in sensor box i m using for 3xAAA batteries.
                            MIC5219-3.3BM5 is good option but it has minimum Input Voltage 2.5v, with good Quiescent 8µA but i think i m leaning toward TPS613221A boost convert chip i know it does not have shutdown option but very low quiescent current of 6.5uA, here is unfinished prototype pcb design.

                            0_1559298983315_b8d261d9-3233-4a65-90df-82b4af89f8c9-image.png

                            PiHome - Smart Heating Control

                            zboblamontZ 1 Reply Last reply
                            0
                            • pihomeP pihome

                              so far i have temperature sensors running on 18650 battery by feeding to raw pin on arduino and it works fine now i'm switching to 2xAAA battery and at this stage i think i have no option but to go for boost converter to power sensor on the node, i wish i had space in sensor box i m using for 3xAAA batteries.
                              MIC5219-3.3BM5 is good option but it has minimum Input Voltage 2.5v, with good Quiescent 8µA but i think i m leaning toward TPS613221A boost convert chip i know it does not have shutdown option but very low quiescent current of 6.5uA, here is unfinished prototype pcb design.

                              0_1559298983315_b8d261d9-3233-4a65-90df-82b4af89f8c9-image.png

                              zboblamontZ Offline
                              zboblamontZ Offline
                              zboblamont
                              wrote on last edited by
                              #14

                              @pihome Surely VR shutdown is irrelevant for a live device, or am I completely misunderstanding this function?
                              Presumably you will deploy one of these for each zone instead instead of running a cable.
                              Passing thought - Have you considered a plastic type battery holder on back of the circuitry, halving the current board area but making it slightly thicker?

                              1 Reply Last reply
                              0
                              • pihomeP Offline
                                pihomeP Offline
                                pihome
                                wrote on last edited by
                                #15

                                @zboblamont
                                you are right one battery powered sensor for each zone and reading once every minute and no cables to sensors. but during sleep time VR will consume power, i had thought about 3x AAA battery on the back of pcb but i n using tht nrf or perhaps i have to rethink the whole design.

                                PiHome - Smart Heating Control

                                zboblamontZ 1 Reply Last reply
                                0
                                • pihomeP pihome

                                  @zboblamont
                                  you are right one battery powered sensor for each zone and reading once every minute and no cables to sensors. but during sleep time VR will consume power, i had thought about 3x AAA battery on the back of pcb but i n using tht nrf or perhaps i have to rethink the whole design.

                                  zboblamontZ Offline
                                  zboblamontZ Offline
                                  zboblamont
                                  wrote on last edited by
                                  #16

                                  @pihome Perhaps re-evaluate what you are trying to achieve and how?
                                  The array in my place reads every 5 minutes over a cable array, even for outside temperatures half-hourly samples would probably be fine, this is my screen-shot.
                                  0_1559412067482_d341a047-155e-4672-bd5e-dcf7c909fda7-image.png
                                  Frankly your goal of 1 minute granularity makes no sense with real world temperature variations, even in interior spaces. If the objective is heating control, room effects are slow.
                                  If necessay you could up the sample rate when heat is circulating, thence minimise wasted yet finite energy?
                                  Even the choice of radio may be inappropriate to your energy efficiency goals, I explained previously how this end works, @nagelc has outlined he is getting super performance with 2+ years battery life, this perhaps merits review...

                                  1 Reply Last reply
                                  1
                                  • pihomeP Offline
                                    pihomeP Offline
                                    pihome
                                    wrote on last edited by
                                    #17

                                    @kimot said in ds18b20 on 2xAAA battery:

                                    MIC5219

                                    you are right i think i have to go back to drawing board and re-evaluate my design. thanks for reply.

                                    PiHome - Smart Heating Control

                                    1 Reply Last reply
                                    0
                                    • pihomeP pihome

                                      Hi All,
                                      i have nodes running on 18650 battery on Arduino mini pro 8mhz (3.3v) without much modification or any low power bootloader but now i want to switch to AAA battery to keep everything tidy and need but one issue ds18b20 requires 3.3v whereas 2xAAA can supply 3v, now million dollar question is what you guys doing to supply 3.3v to ds18b20? boost converter consume power as well and all on ebay/aliexpress ones are seems very power hungry (Quiescent current 13uA).
                                      https://www.aliexpress.com/item/32800430445.html?spm=2114.search0104.3.219.5b3d1a25h7pRRv&ws_ab_test=searchweb0_0%2Csearchweb201602_2_10065_10068_319_10059_10884_317_10887_10696_321_322_10084_453_10083_454_10103_10618_10304_10307_10820_10821_537_10302_536%2Csearchweb201603_51%2CppcSwitch_0&algo_expid=e6ec65d0-b780-4c66-b06a-52134fa6c454-31&algo_pvid=e6ec65d0-b780-4c66-b06a-52134fa6c454&transAbTest=ae803_3
                                      i m thinking to find alternate to ds18b20 that can run reliably on 2v,
                                      any thoughts or suggestions?

                                      T Offline
                                      T Offline
                                      tommies
                                      wrote on last edited by
                                      #18

                                      @pihome i use ds18b20 on 2xAA with an atmega328p without any problem ans without any regulator

                                      1 Reply Last reply
                                      0
                                      • B Offline
                                        B Offline
                                        buxtronix
                                        wrote on last edited by
                                        #19

                                        Confirming also, I have about a dozen nodes around the place, all running off 2xAA batteries and all of the DS18B20 devices have no problems with this supply voltage, even when they are down to 2.8V they're still reporting reliably.

                                        1 Reply Last reply
                                        0
                                        • pihomeP Offline
                                          pihomeP Offline
                                          pihome
                                          wrote on last edited by
                                          #20

                                          i must admit you are lucky or your sensors dont care about voltage but at this stage after reading your comments i have tried 3 different sensors and all the same result

                                          may be something is in my sketch ?

                                          //  _____    _   _    _                             
                                          // |  __ \  (_) | |  | |                           
                                          // | |__) |  _  | |__| |   ___    _ __ ___     ___ 
                                          // |  ___/  | | |  __  |  / _ \  | |_  \_ \   / _ \ 
                                          // | |      | | | |  | | | (_) | | | | | | | |  __/
                                          // |_|      |_| |_|  |_|  \___/  |_| |_| |_|  \___|
                                          //
                                          //    S M A R T   H E A T I N G   C O N T R O L 
                                          // *****************************************************************
                                          // *       Battery Powered OneWire DS18B20 Temperature Sensor      *
                                          // *           Version 0.31 Build Date 06/11/2017                  *
                                          // *            Last Modification Date 09/05/2019                  *
                                          // *                                          Have Fun - PiHome.eu *
                                          // *****************************************************************
                                          
                                          // Enable debug prints to serial monitor
                                          //#define MY_DEBUG
                                          
                                          // Enable and select radio type attached
                                          #define MY_RADIO_RF24
                                          //#define MY_RADIO_NRF5_ESB
                                          //#define MY_RADIO_RFM69
                                          //#define MY_RADIO_RFM95
                                          
                                          // Set LOW transmit power level as default, if you have an amplified NRF-module and
                                          // power your radio separately with a good regulator you can turn up PA level.
                                          // #define MY_RF24_PA_LEVEL RF24_PA_LOW
                                          // RF24_PA_MIN RF24_PA_LOW RF24_PA_HIGH RF24_PA_MAX RF24_PA_ERROR
                                          
                                          #define MY_RF24_PA_LEVEL RF24_PA_MIN
                                          //#define MY_DEBUG_VERBOSE_RF24
                                          
                                          // RF channel for the sensor net, 0-127 Default is 76
                                          #define MY_RF24_CHANNEL	76
                                          
                                          //PiHome - Make Sure you change Node ID, for each temperature sensor. 21 for Ground Floor, 20 for First Floor, 30 for Domastic Hot Water.
                                          #define MY_NODE_ID 33
                                          
                                          //RF24_250KBPS for 250kbs, RF24_1MBPS for 1Mbps, or RF24_2MBPS for 2Mbps
                                          #define RF24_DATARATE 	   RF24_250KBPS
                                          
                                          // Set baud rate to same as optibot
                                          //#define MY_BAUD_RATE 9600
                                          
                                          //set how long to wait for transport ready in milliseconds
                                          //#define MY_TRANSPORT_WAIT_READY_MS 3000
                                          
                                          
                                          //#include <SPI.h>
                                          #include <MySensors.h>  
                                          #include <DallasTemperature.h>
                                          #include <OneWire.h>
                                          
                                          #define ledpin 4 // LED for one Blink Power On, Solid LED for No sensors, 5 Blinks for no Radio (this settings is in MySensors.cpp) and three blinks for low battery 
                                          
                                          // Define sensor node childs
                                          #define CHILD_ID_BATT 1
                                          #define CHILD_ID_TEMP 0
                                          
                                          #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
                                          #define COMPARE_BVOLT 1 // Send battery voltage only if changed? 1 = Yes 0 = No
                                          #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
                                          
                                          #define MAX_ATTACHED_DS18B20 2
                                          unsigned long SLEEP_TIME = 56000; // Sleep time between reads (in milliseconds)
                                          
                                          // Battery related init
                                          int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
                                          float oldBatteryV = 0;
                                          MyMessage msgBatt(CHILD_ID_BATT, V_VOLTAGE);
                                          
                                          // Dallas Temperature related init
                                          OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
                                          DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. 
                                          float lastTemperature[MAX_ATTACHED_DS18B20];
                                          int numSensors=0;
                                          bool receivedConfig = false;
                                          bool metric = true;
                                          // Initialize temperature message
                                          MyMessage msg(CHILD_ID_TEMP, V_TEMP);
                                          
                                          void before(){
                                            // Startup up the OneWire library
                                            sensors.begin();
                                          }
                                          
                                          void setup(){
                                          
                                          	//This is LED pin set to output and turn it on for short while 
                                          	pinMode(ledpin, OUTPUT);
                                          	digitalWrite(ledpin, HIGH);
                                          	delay(60);
                                          	digitalWrite(ledpin, LOW);
                                          
                                          	// requestTemperatures() will not block current thread
                                            sensors.setWaitForConversion(false);
                                            // needed for battery soc
                                            // use the 1.1 V internal reference
                                            #if defined(__AVR_ATmega2560__)
                                                analogReference(INTERNAL1V1);
                                            #else
                                                analogReference(INTERNAL);
                                            #endif
                                          
                                              // disable ADC
                                            //ADCSRA = 0; 
                                            //power_usart0_disable();// Serial (USART)
                                            //power_adc_disable(); // ADC converter
                                            //power_twi_enable(); // TWI (I2C)
                                          }
                                          
                                          void presentation() {
                                          	// Send the sketch version information to the gateway and Controller
                                          	sendSketchInfo("Temperature Sensor", "0.31");
                                          	// Fetch the number of attached temperature sensors  
                                          	numSensors = sensors.getDeviceCount();
                                          	//Blink LED as number of sensors attached
                                          	blink_led(numSensors, ledpin);
                                          	
                                          	//check if attached sensors number is grater then 0 if no then put led on solid
                                          	#if numSensors > 0
                                          		digitalWrite(ledpin, HIGH);
                                          	#else 
                                          		digitalWrite(ledpin, LOW);
                                          	#endif
                                          	
                                          	
                                            // Present all sensors to controller
                                            for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
                                               present(i, S_TEMP);
                                            }
                                          }
                                          
                                          void loop(){
                                          	// get the battery Voltage
                                          	//ref http://www.ohmslawcalculator.com/voltage-divider-calculator
                                          	// Sense point is bypassed with 0.1 uF cap to reduce noise at that point
                                          	
                                          	// 1M, 100K divider across battery and using internal ADC ref of 1.1V
                                          	// ((1e6+100e3)/100e3)*1.1 = Vmax = 12.1 Volts
                                          	// 12.1/1023 = Volts per bit = 0.011828 
                                          	
                                          	//R1 820k, R2 220k
                                          	//((820e3+220e3)/220e3)*1.1 = Vmax = 5.2 Volts
                                          	//5.2/1023 = Volts per bit = 0.005083089
                                          	
                                          	int battSensorValue = analogRead(BATTERY_SENSE_PIN);
                                          	//float batteryV  = battSensorValue * 0.005083089; //R1 820k, R2 220k divider across battery and using internal ADC ref of 1.1v
                                          	float batteryV  = battSensorValue * 0.011828;    //R1 1M, R2 100K divider across battery and using internal ADC ref of 1.1v
                                          	
                                          	//int batteryPcnt = ( ( batteryV - 2.9 ) / ( ( 4.2 - 2.9 ) / 100 ) ); // for 18650 Battery Powred 
                                          	int batteryPcnt = ( ( batteryV - 2.1 ) / ( ( 3.0 - 2.1 ) / 100 ) ); // for AAA Battery Powered
                                          	
                                          	
                                          	#ifdef MY_DEBUG
                                          		Serial.print("Pin Reading: ");
                                          		Serial.println(battSensorValue);
                                          		Serial.print("Battery Voltage: ");
                                          		Serial.print(batteryV);
                                          		Serial.println(" v");
                                          		//Print Battery Percentage
                                          		Serial.print("Battery percent: ");
                                          		Serial.print(batteryPcnt);
                                          		Serial.println(" %");
                                          	#endif
                                          	
                                          	#if COMPARE_BVOLT == 1
                                          		if (oldBatteryV != batteryV) {
                                          			send(msgBatt.set(batteryV, 2));
                                          			sendBatteryLevel(batteryPcnt);
                                          			oldBatteryV = batteryV;
                                          		}
                                          	#else
                                          		send(msgBatt.set(batteryV, 2));
                                          		sendBatteryLevel(batteryPcnt);
                                          		oldBatteryV = batteryV; 
                                          	#endif
                                          
                                          	// Fetch temperatures from Dallas sensors
                                          	sensors.requestTemperatures();
                                          	// query conversion time and sleep until conversion completed
                                          	int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
                                          	//sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
                                          	sleep(conversionTime);
                                            // Read temperatures and send them to controller 
                                          	for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
                                          		// Fetch and round temperature to one decimal
                                          		float temperature = static_cast<float>(static_cast<int>((getControllerConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
                                          		// Only send data if temperature has changed and no error
                                          		#if COMPARE_TEMP == 1
                                          			if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
                                          		#else
                                          			if (temperature != -127.00 && temperature != 85.00) {
                                          		#endif
                                          			// Send in the new temperature
                                          			send(msg.setSensor(i).set(temperature,1));
                                          			// Save new temperatures for next compare
                                          			lastTemperature[i]=temperature;
                                          			}
                                          		}
                                          		//Condition to check battery levell is lower then minimum then blink led 3 times
                                          		//if (batteryV < 2.9) { //for 18650 Battery Powered Sensor 
                                          		if (batteryV < 2.0) { //for AAA Battery Powered Sensor 
                                          			blink_led(3, ledpin);
                                          			//Serial.print("Low Voltage");
                                          		}
                                          	//go to sleep for while
                                          	//smartSleep(SLEEP_TIME);
                                          	sleep(SLEEP_TIME);
                                          	}
                                          
                                          //Blink LED function, pass ping number and number of blinks usage: blink_led(variable or number of time blink, ledpin);
                                          void blink_led(int count, int pin){
                                          	for(int i=0;i<count;i++){
                                          		digitalWrite(pin, HIGH);
                                          		delay(700);
                                          		digitalWrite(pin, LOW);
                                          		delay(700);
                                          	}
                                          }
                                          

                                          PiHome - Smart Heating Control

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


                                          16

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