Powering a sensor with digital out
-
Hi,
I'm trying to power a sensor with one of the digital pins of Arduino. Issue I'm facing is I'm unable to turn on digital pin, I have tried quite few options. I feel I'm missing something simple but its wrecking my brain. Can any one of you look at the code and see what I'm doing wrong, please.
Arduino : pro mini Atmega168 3.3v
#define MY_NODE_ID 1 // node id #define MY_RADIO_NRF24 // enabling support for NRF radio module #define NODE_ID 1 // sensor id #define SENS_ON 2 #include <MySensors.h> #include <SPI.h> MyMessage msg(NODE_ID, V_LEVEL); // constructing the msg const int VAL_PROBE = 0; // initializing the moisture variable 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, HIGH); delay(10000); // To check the input voltage on pin 2 int moisture = analogRead(VAL_PROBE); //measuring the moisture send(msg.set(moisture)); // sending the data sleep(1000); // sleeping for 10 sec } -
Hi,
I'm trying to power a sensor with one of the digital pins of Arduino. Issue I'm facing is I'm unable to turn on digital pin, I have tried quite few options. I feel I'm missing something simple but its wrecking my brain. Can any one of you look at the code and see what I'm doing wrong, please.
Arduino : pro mini Atmega168 3.3v
#define MY_NODE_ID 1 // node id #define MY_RADIO_NRF24 // enabling support for NRF radio module #define NODE_ID 1 // sensor id #define SENS_ON 2 #include <MySensors.h> #include <SPI.h> MyMessage msg(NODE_ID, V_LEVEL); // constructing the msg const int VAL_PROBE = 0; // initializing the moisture variable 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, HIGH); delay(10000); // To check the input voltage on pin 2 int moisture = analogRead(VAL_PROBE); //measuring the moisture send(msg.set(moisture)); // sending the data sleep(1000); // sleeping for 10 sec }try this
void loop() { digitalWrite(SENS_ON, HIGH); delay(10000); // To check the input voltage on pin 2 // byTheo 10 seconds seems to be a bit much?? int moisture = analogRead(VAL_PROBE); //measuring the moisture digitalWrite(SENS_ON, LOW); // turn it off //byTheo you didn't turn the pin off send(msg.set(moisture)); // sending the data sleep(10000); // sleeping for 10 sec // byTheo 1000 s isn't 10 secs } -
Hi,
I'm trying to power a sensor with one of the digital pins of Arduino. Issue I'm facing is I'm unable to turn on digital pin, I have tried quite few options. I feel I'm missing something simple but its wrecking my brain. Can any one of you look at the code and see what I'm doing wrong, please.
Arduino : pro mini Atmega168 3.3v
#define MY_NODE_ID 1 // node id #define MY_RADIO_NRF24 // enabling support for NRF radio module #define NODE_ID 1 // sensor id #define SENS_ON 2 #include <MySensors.h> #include <SPI.h> MyMessage msg(NODE_ID, V_LEVEL); // constructing the msg const int VAL_PROBE = 0; // initializing the moisture variable 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, HIGH); delay(10000); // To check the input voltage on pin 2 int moisture = analogRead(VAL_PROBE); //measuring the moisture send(msg.set(moisture)); // sending the data sleep(1000); // sleeping for 10 sec } -
@TheoL , Thanks for the suggestion . Tried that, same result.
@mfalkvidd , Thanks for the code suggestion, I made the change. Regarding the issue, I did check with a multi-meter and it shows 0V . To make sure I also used the example blink sketch with pin 2 as output and it is showing 3.24V I will attach the wiring diagram(I haven't drawn one). Things I noticed.
- On commenting the Mysensor.h library and related code from above sketch I'm able to turn on the Pin
- I tried using different digital pins and same result.
- To make sure I measured the output pin voltage powering it with USB ( without connecting the board to radio and soil sensor ) , same result voltage is 0V
-
@TheoL , Thanks for the suggestion . Tried that, same result.
@mfalkvidd , Thanks for the code suggestion, I made the change. Regarding the issue, I did check with a multi-meter and it shows 0V . To make sure I also used the example blink sketch with pin 2 as output and it is showing 3.24V I will attach the wiring diagram(I haven't drawn one). Things I noticed.
- On commenting the Mysensor.h library and related code from above sketch I'm able to turn on the Pin
- I tried using different digital pins and same result.
- To make sure I measured the output pin voltage powering it with USB ( without connecting the board to radio and soil sensor ) , same result voltage is 0V
@hozze looks like good troubleshooting, great work.
Very interesting that it works when uncommenting the MySensors stuff. I think there are some leds blinking features in 2.0 (have not yet moved to 2.0 myself so I don't know more than what I've read in the forum), but I think that is only enabled for gateways.
Does it help if you remove include <SPI.h>? It looks like SPI is not used so it shouldn't make a difference but you might as well remove it if you aren't using it.
-
@hozze looks like good troubleshooting, great work.
Very interesting that it works when uncommenting the MySensors stuff. I think there are some leds blinking features in 2.0 (have not yet moved to 2.0 myself so I don't know more than what I've read in the forum), but I think that is only enabled for gateways.
Does it help if you remove include <SPI.h>? It looks like SPI is not used so it shouldn't make a difference but you might as well remove it if you aren't using it.
@mfalkvidd said:
there are some leds blinking features in 2.0
This feature is also present in previous versions and not limited to gateways.
Pin 2 however is never used for leds as it is the default irq pin for nRF.
Try with another pin, e.g. 4/5/6 and see if that makes a difference. -
@mfalkvidd : Removed SPI.h , it didn't help though. Thanks for pointers on cleaning up the code :smiley:
@Yveaux :
Tried with pin 5 , same result.
Tried using a different pro mini ( Atmega328 16Mhz 5 v ) got same result , no output on pin :expressionless: -
@mfalkvidd : Removed SPI.h , it didn't help though. Thanks for pointers on cleaning up the code :smiley:
@Yveaux :
Tried with pin 5 , same result.
Tried using a different pro mini ( Atmega328 16Mhz 5 v ) got same result , no output on pin :expressionless: -
@Yveaux I don't have those defined. Below is my current code.
#define MY_NODE_ID 1 // 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> 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, HIGH); delay(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, LOW); // turn it off // sleep(1000); // sleeping for 10 sec }An as soon as I comment it out like below the pin out on 5 works
#define MY_NODE_ID 1 // 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> 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, HIGH); delay(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, LOW); // turn it off // sleep(1000); // sleeping for 10 sec } -
@Yveaux I don't have those defined. Below is my current code.
#define MY_NODE_ID 1 // 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> 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, HIGH); delay(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, LOW); // turn it off // sleep(1000); // sleeping for 10 sec }An as soon as I comment it out like below the pin out on 5 works
#define MY_NODE_ID 1 // 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> 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, HIGH); delay(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, LOW); // turn it off // sleep(1000); // sleeping for 10 sec } -
@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.
-
@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.
-
@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.
-
@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 ;-)
@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.
-
@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.
@hozze You should enable debugging at the top of your sketch with
// Enable debug prints to serial monitor #define MY_DEBUGand 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
-
@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 )
-
@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 )
-
@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 )
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