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. Development
  3. Powering a sensor with digital out

Powering a sensor with digital out

Scheduled Pinned Locked Moved Development
27 Posts 7 Posters 4.5k Views 7 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.
  • YveauxY Yveaux

    @hozze it's strange that you only measure 3.24V on the output pin if you're using a 5V pro mini. This is IMHO an indication that something is wrong, also when your pin does seem to toggle.

    TheoLT Offline
    TheoLT Offline
    TheoL
    Contest Winner
    wrote on last edited by
    #13

    @Yveaux @hozze Are you sure it's a ProMini 5V? Could you measure the voltage on the Raw pin.

    I've received some Pro Mini 3.3V while I actually did order 5V.

    It's just a guess.

    hozzeH 1 Reply Last reply
    0
    • TheoLT TheoL

      @Yveaux @hozze Are you sure it's a ProMini 5V? Could you measure the voltage on the Raw pin.

      I've received some Pro Mini 3.3V while I actually did order 5V.

      It's just a guess.

      hozzeH Offline
      hozzeH Offline
      hozze
      wrote on last edited by
      #14

      @TheoL I have two pro mini's. I measured the voltage across a output pin ( HIGH ) and GND and it gives me near 5V on one and near 3.3V on another .So it looks as if I do have 5V pro mini.

      I have tried few other sketches on both, seems they are working fine, I face the specific issue only when including the Mysensor.h library. I will give it a try on a nano that I have and see what happens.

      TheoLT 1 Reply Last reply
      0
      • hozzeH hozze

        @TheoL I have two pro mini's. I measured the voltage across a output pin ( HIGH ) and GND and it gives me near 5V on one and near 3.3V on another .So it looks as if I do have 5V pro mini.

        I have tried few other sketches on both, seems they are working fine, I face the specific issue only when including the Mysensor.h library. I will give it a try on a nano that I have and see what happens.

        TheoLT Offline
        TheoLT Offline
        TheoL
        Contest Winner
        wrote on last edited by
        #15

        @hozze It was just a guess. I once compiled a sketch for a 5V and uploaded it to a ProMini 3.3V. Took me a while before I noticed my mistake. I just didn;t understand why my Arduino couldn't control my relay boards ;-)

        hozzeH 1 Reply Last reply
        0
        • TheoLT TheoL

          @hozze It was just a guess. I once compiled a sketch for a 5V and uploaded it to a ProMini 3.3V. Took me a while before I noticed my mistake. I just didn;t understand why my Arduino couldn't control my relay boards ;-)

          hozzeH Offline
          hozzeH Offline
          hozze
          wrote on last edited by
          #16

          @TheoL :smiley: me too learning things the hard way.

          Thanks for all the pointers that you guys are giving . Looks as if I'm in the right place and with a great community,

          Let me tinker a bit more and see if I can get somewhere, if anyone can give any further info kindly do.

          Boots33B 1 Reply Last reply
          1
          • hozzeH hozze

            @TheoL :smiley: me too learning things the hard way.

            Thanks for all the pointers that you guys are giving . Looks as if I'm in the right place and with a great community,

            Let me tinker a bit more and see if I can get somewhere, if anyone can give any further info kindly do.

            Boots33B Offline
            Boots33B Offline
            Boots33
            Hero Member
            wrote on last edited by
            #17

            @hozze You should enable debugging at the top of your sketch with

            // Enable debug prints to serial monitor
            #define MY_DEBUG
            

            and check the serial monitor to see if the radio is initialising . Maybe the loop part of the program will not run if this does not happen. That could be why commenting out the #include <MySensors.h> allows it to work.

            You might also use wait instead of delay

            1 Reply Last reply
            1
            • hozzeH Offline
              hozzeH Offline
              hozze
              wrote on last edited by
              #18

              @Boots33 , I enabled MY_DEBUG. Sorry if I sound stupid. I have connected the pro mini to computer with USB serial CP2102 for programming/serial debug , at the same time can I power the pro mini + Radio with an external power supply 3.3V ?

              I did something similar with a ATTINY85 few days back and bricked it :cry: ( Connected it to USB and same time powered it )

              mfalkviddM Boots33B 2 Replies Last reply
              0
              • hozzeH hozze

                @Boots33 , I enabled MY_DEBUG. Sorry if I sound stupid. I have connected the pro mini to computer with USB serial CP2102 for programming/serial debug , at the same time can I power the pro mini + Radio with an external power supply 3.3V ?

                I did something similar with a ATTINY85 few days back and bricked it :cry: ( Connected it to USB and same time powered it )

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

                @hozze connect gnd from the serial adapter AND the external power supply to gnd on the Arduino. Connect + on the external adapter to the pin you normally use (vcc or raw). Do not connect + from the serial adapter. That's it.

                1 Reply Last reply
                1
                • hozzeH hozze

                  @Boots33 , I enabled MY_DEBUG. Sorry if I sound stupid. I have connected the pro mini to computer with USB serial CP2102 for programming/serial debug , at the same time can I power the pro mini + Radio with an external power supply 3.3V ?

                  I did something similar with a ATTINY85 few days back and bricked it :cry: ( Connected it to USB and same time powered it )

                  Boots33B Offline
                  Boots33B Offline
                  Boots33
                  Hero Member
                  wrote on last edited by
                  #20

                  @hozze The whole purpose of a good forum is for people to share ideas and knowledge. So never be worried about asking questions. :)

                  1 Reply Last reply
                  1
                  • hozzeH Offline
                    hozzeH Offline
                    hozze
                    wrote on last edited by
                    #21

                    Thanks guys, I will check this out.

                    1 Reply Last reply
                    0
                    • hozzeH Offline
                      hozzeH Offline
                      hozze
                      wrote on last edited by
                      #22

                      Was away from arduino for over a week with regular job. Tested the code with debug on a new arduino pro mini 3.3v 8Mhz and the below is the output ( please note that the values getting send are random values , i'm still not able to power the sensor with digital Pin )

                      TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=ok:0100
                      TSP:MSG:SEND 1-1-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=ok:2.0.0
                      TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=ok:0
                      TSP:MSG:READ 0-0-1 s=255,c=3,t=15,pt=6,l=2,sg=0:0100
                      TSP:MSG:SEND 1-1-0-0 s=1,c=0,t=35,pt=0,l=0,sg=0,ft=0,st=ok:
                      TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=11,pt=0,l=10,sg=0,ft=0,st=ok:SoilSensor
                      TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=ok:0.1
                      Request registration...
                      TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=ok:2
                      TSP:MSG:READ 0-0-1 s=255,c=3,t=27,pt=1,l=1,sg=0:1
                      Node registration=1
                      Init complete, id=1, parent=0, distance=1, registration=1
                      TSP:MSG:SEND 1-1-0-0 s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=ok:786
                      TSP:MSG:SEND 1-1-0-0 s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=ok:503
                      TSP:MSG:SEND 1-1-0-0 s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=ok:410
                      TSP:MSG:SEND 1-1-0-0 s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=ok:425
                      TSP:MSG:SEND 1-1-0-0 s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=ok:461
                      TSP:MSG:SEND 1-1-0-0 s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=ok:539
                      TSP:MSG:SEND 1-1-0-0 s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=ok:507
                      TSP:MSG:SEND 1-1-0-0 s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=ok:392
                      

                      Looks fine for me , still I can't turn a digital pin On :disappointed:

                      Boots33B 1 Reply Last reply
                      0
                      • hozzeH hozze

                        Was away from arduino for over a week with regular job. Tested the code with debug on a new arduino pro mini 3.3v 8Mhz and the below is the output ( please note that the values getting send are random values , i'm still not able to power the sensor with digital Pin )

                        TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=ok:0100
                        TSP:MSG:SEND 1-1-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=ok:2.0.0
                        TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=ok:0
                        TSP:MSG:READ 0-0-1 s=255,c=3,t=15,pt=6,l=2,sg=0:0100
                        TSP:MSG:SEND 1-1-0-0 s=1,c=0,t=35,pt=0,l=0,sg=0,ft=0,st=ok:
                        TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=11,pt=0,l=10,sg=0,ft=0,st=ok:SoilSensor
                        TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=ok:0.1
                        Request registration...
                        TSP:MSG:SEND 1-1-0-0 s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=ok:2
                        TSP:MSG:READ 0-0-1 s=255,c=3,t=27,pt=1,l=1,sg=0:1
                        Node registration=1
                        Init complete, id=1, parent=0, distance=1, registration=1
                        TSP:MSG:SEND 1-1-0-0 s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=ok:786
                        TSP:MSG:SEND 1-1-0-0 s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=ok:503
                        TSP:MSG:SEND 1-1-0-0 s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=ok:410
                        TSP:MSG:SEND 1-1-0-0 s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=ok:425
                        TSP:MSG:SEND 1-1-0-0 s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=ok:461
                        TSP:MSG:SEND 1-1-0-0 s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=ok:539
                        TSP:MSG:SEND 1-1-0-0 s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=ok:507
                        TSP:MSG:SEND 1-1-0-0 s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=ok:392
                        

                        Looks fine for me , still I can't turn a digital pin On :disappointed:

                        Boots33B Offline
                        Boots33B Offline
                        Boots33
                        Hero Member
                        wrote on last edited by
                        #23

                        @hozze It really should be working. I tried your original above and with a led connected to pin 5 it turns on when the code is run

                        try the code below with some serial prints to see what happens

                        // Enable debug prints to serial monitor
                        #define MY_DEBUG
                        #define MY_NODE_ID 150  // node id 
                        #define MY_RADIO_NRF24  // enabling support for NRF radio module
                        
                        #define NODE_ID 1  // sensor id
                        #define SENS_ON 5
                        #define VAL_PROBE A0
                        #include <MySensors.h>
                        #define POWER_ON 1  //  value to write to turn on sensor
                        #define POWER_OFF 0 //  value to write to turn off sensor
                        MyMessage msg(NODE_ID, V_LEVEL); // constructing the msg
                        
                        void setup()
                        {
                          pinMode(SENS_ON, OUTPUT);
                        }
                        
                        void presentation()
                        {
                          present(NODE_ID, S_MOISTURE);  // presenting the sensor
                          sendSketchInfo("SoilSensor", "0.1"); //meta data
                        }
                        
                        void loop()
                        {
                        
                        
                          digitalWrite(SENS_ON, POWER_ON);
                          Serial.print("Sensor Power on pin "); Serial.print(SENS_ON); Serial.print(" is..."); Serial.println((POWER_ON));
                          wait(1000); // To check the input voltage of pin 2
                          int moisture = analogRead(VAL_PROBE); //measuring the moisture
                          send(msg.set(moisture));  // sending the data
                          digitalWrite(SENS_ON, POWER_OFF); // turn it off
                          Serial.print("Sensor Power on pin "); Serial.print(SENS_ON); Serial.print(" is..."); Serial.println((POWER_OFF));
                        
                          wait(1000);
                        }
                        
                        

                        I get an output like this below and the led flashes on and off at 1 second intervals. Maybe try just a led with a 200 to 300 ohm resistor on pin 5 to see what is happening. could the moisture sensor be drawing more than the arduino can give?

                        TSP:MSG:SEND 150-150-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,ft=1,st=ok:0
                        TSP:MSG:READ 0-0-150 s=255,c=3,t=6,pt=0,l=1,sg=0:M
                        TSP:MSG:SEND 150-150-0-0 s=1,c=0,t=35,pt=0,l=0,sg=0,ft=0,st=ok:
                        TSP:MSG:SEND 150-150-0-0 s=255,c=3,t=11,pt=0,l=10,sg=0,ft=0,st=ok:SoilSensor
                        TSP:MSG:SEND 150-150-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=ok:0.1
                        Request registration...
                        TSP:MSG:SEND 150-150-0-0 s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=ok:2
                        TSP:MSG:READ 0-0-150 s=255,c=3,t=27,pt=1,l=1,sg=0:1
                        Node registration=1
                        Init complete, id=150, parent=0, distance=1, registration=1
                        Sensor Power on pin 5 is...1
                        TSP:MSG:SEND 150-150-0-0 s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=ok:511
                        Sensor Power on pin 5 is...0
                        Sensor Power on pin 5 is...1
                        TSP:MSG:SEND 150-150-0-0 s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=ok:313
                        Sensor Power on pin 5 is...0
                        Sensor Power on pin 5 is...1
                        TSP:MSG:SEND 150-150-0-0 s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=ok:254
                        Sensor Power on pin 5 is...0
                        Sensor Power on pin 5 is...1
                        TSP:MSG:SEND 150-150-0-0 s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=ok:326
                        Sensor Power on pin 5 is...0
                        Sensor Power on pin 5 is...1
                        TSP:MSG:SEND 150-150-0-0 s=1,c=1,t=37,pt=2,l=2,sg=0,ft=0,st=ok:235
                        Sensor Power on pin 5 is...0
                        Sensor Power on pin 5 is...1
                        
                        1 Reply Last reply
                        1
                        • hozzeH Offline
                          hozzeH Offline
                          hozze
                          wrote on last edited by
                          #24

                          I'm stupid ! @Boots33 the debug info saved me. With debug info I came to notice that the sketch goes into loop part only if the gateway is also connected and available. Stupid me was doing the pin checks just by connecting the sensor and keeping the gateway disconnected , when I had the gateway connected I didn't bother to check the pin out, I was going in the same loop and wasting my and all your valuable time.

                          Thanks for all your assistance people, you guys are awesome.

                          1 Reply Last reply
                          2
                          • Boots33B Offline
                            Boots33B Offline
                            Boots33
                            Hero Member
                            wrote on last edited by
                            #25

                            Great to hear you got it going, and don't worry I am sure everyone here ( including me) has there own moments they would rather forget when it comes to writing code. :)

                            1 Reply Last reply
                            1
                            • xydixX Offline
                              xydixX Offline
                              xydix
                              wrote on last edited by
                              #26

                              This sounds like a really good idea.
                              Can I use this to power like a DS18B20 tempsensor. Would this save power and give my battery powered sensors extended battery life?

                              bjacobseB 1 Reply Last reply
                              0
                              • xydixX xydix

                                This sounds like a really good idea.
                                Can I use this to power like a DS18B20 tempsensor. Would this save power and give my battery powered sensors extended battery life?

                                bjacobseB Offline
                                bjacobseB Offline
                                bjacobse
                                wrote on last edited by bjacobse
                                #27

                                @xydix
                                Arduino using Atmega can supply max 40mA per pin, and in total max 100mA.
                                DS18B20 seems to use max 1,5mA
                                so yes this will work
                                After searching on the net.
                                https://github.com/nathanchantrell/TinyTX/blob/master/TinyTX_DS18B20/TinyTX_DS18B20.ino

                                The part for the power on, read, power off is below (taken from the above link):

                                void loop() {

                                digitalWrite(ONE_WIRE_POWER, HIGH); // turn DS18B20 sensor on

                                //Sleepy::loseSomeTime(5); // Allow 5ms for the sensor to be ready
                                delay(5); // The above doesn't seem to work for everyone (why?)

                                sensors.begin(); //start up temp sensor
                                sensors.requestTemperatures(); // Get the temperature
                                tinytx.temp=(sensors.getTempCByIndex(0)*100); // Read first sensor and convert to integer, reversed at receiving end

                                digitalWrite(ONE_WIRE_POWER, LOW); // turn DS18B20 off

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


                                40

                                Online

                                11.7k

                                Users

                                11.2k

                                Topics

                                113.1k

                                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