Measurement with pull up mode

I have question, maybe I should make new post for that.
To day I was playing with analog read and pull up function.
For this moment everything is fine until I use this pin to charge a small battery.
Idea was that battery is acting as big capacitor and sustain voltage for long time.
Good ideal flat voltage for measurements.

After setting pin as output and measure it, I get one value.
Now I change for pull up input and measure it.
In theory measured pin should get this same value as previous. But I get much higher value.
Why is like that?
Do internal measurements is connected earlier before internal resistor?

You should always set a pin as INPUT if using analogRead. Otherwise you'll not measure anything
useful.

Batteries are not capacitors, them are constant voltage sources.

If you connect a voltage source to an OUTPUT pin, you risk burning out the pin or the whole
chip.

MarkT:
You should always set a pin as INPUT if using analogRead. Otherwise you'll not measure anything
useful.

Batteries are not capacitors, them are constant voltage sources.

If you connect a voltage source to an OUTPUT pin, you risk burning out the pin or the whole
chip.

Yes, I am aware of that.
I am using mode as input, but interesting is that using only input I have one value, and switch to input pull up, I have different value much higher then previous.
And battery source is ideal to measure this same voltage with different modes.

PS if input pull up can be used with switch connected to ground, then battery 1.2v will not hurt my device.

And curious is for me, why I have different values using exactly this same voltage.

Basically you're injecting the voltage to your sensor internally... it's a no no.

wolframore:

Basically you're injecting the voltage to your sensor internally... it's a no no.

Yes, you are close of what I mean.
Now this swing change to battery. Replace switch to battery.
And now measure it using this same drawing as You show. One test with normal mode "INPUT" and second test with "INPUT_PULLUP" and read that input. What value will show then?

My tests show that with constant voltage, when I read value from the battery, with pull-up is higher.

It should not stay this same? Even when I am pulling up this 5v voltage is not affecting voltage of battery because of that internal resistor. ?
With this thinking I should have still this same value of 1.2v ‹-- 120 not 400 as arduino show me.

Post the full schematic.

What values the analogRead returns? Try to measure the voltage with DMM as well. Maybe you will get consistent results.

Ok, when I come to home, I will post screen shots and schematic. Also few measurements.

when I read value from the battery, with pull-up is higher.

Of course it is. The battery is being charged through the pullup resistor, and the voltage across the battery will be higher.

Verify this with your multimeter.

A 20 to 50k internal pullup won't affect a cell's voltage much at all, unless its a tiny little coin cell, but
that's beside the point, set an analog pin to INPUT mode if you want accurate measurements from it,
the internal pullup is non linear has a 2.5:1 range of values so all it can do is reduce accuracy and linearity
of your meusurements for no reason.

unless its a tiny little coin cell

You don't have a clue, do you?

I still want to see a schematic

50k ohms trickle charging a cell from a few volts headroom is probably not even compensating for the self-discharge current of many cells, and typical cell internal resistances are measured as a few ohms or fractions of an ohm. Small coin cells can have hundreds of ohms of internal resistance though, depending on the
chemistry.

schematic is in attachment.
Before You ask me why I use pin mode for all pins, answare is to eliminate all floating pins with noise what can affect my measurement for battery. Is one of that solutions what I found on internet. Someone said that to get more precise measurement, is good to eliminate all floating pins with pwm thing what can affect internal ADC.
I use rechargeable battery with 1.2 volt. schematic is only to show how I have connected arduino micro.
I tested it also on arduino uno and this problem is exactly this same. Difference in measurements with different mode.
code is that

void setup() {

  Serial.begin(9600);

  for (short i = 0; i < 18; i++) {
    pinMode(i, OUTPUT);
    digitalWrite(i, 1);
  }
  short pin[4] = {A0, A1, A2, A3};

  for (short i = 0; i < 4; i++) {
    pinMode(pin[i], OUTPUT);
    digitalWrite(pin[i], 1);
  }
}

void loop() {
  float input;
  float voltage;

  pinMode(A0, INPUT);
  delay(1);
  for (short i = 0; i < 1; i++) {
    input = analogRead(A0);
  }
  voltage = input * 0.004440559;
  Serial.print(input); Serial.print(" "); Serial.println(voltage, 3);
  if (voltage <= 1.30 )
  {
    pinMode(A0, OUTPUT);
    digitalWrite(A0, 1);
    delay(1);
    delay(2000);
  }
  else
  {
    pinMode(A0, INPUT);
    delay(1);
    while ( voltage > 1.25) {
      for (short i = 0; i < 5; i++) {
        input = analogRead(A0);
      }
      voltage = input * 0.004440559;
      Serial.println("Batery full" + String(" ") + String(voltage));
      delay(1000);
    }
  }

}

Now what I mean.

with

pinMode(A0, INPUT);

I have readings:

  • 286.00 1.270
  • 287.00 1.274
  • 287.00 1.274
  • 287.00 1.274
  • 288.00 1.279
  • 287.00 1.274
  • 287.00 1.274
  • 287.00 1.274
  • 287.00 1.274
  • 287.00 1.274

but when I change to

pinMode(A0, INPUT_PULLUP);

Iget that

  • 301.00 1.337
  • 302.00 1.341
  • 301.00 1.337
  • 302.00 1.341
  • 302.00 1.341
  • 302.00 1.341
  • 301.00 1.337
  • 302.00 1.341
  • 302.00 1.341

Now problem is why I get higher value on PULLUP mode if still battery is connected tho that pin without any resistor.
Looks like arduino have some internal resistance, and when pull up mode is active, then measured voltage is higher then originally battery have. I measure battery voltage, and is not changed even by 1 mili volt. is exactly 1.27V
But arduino with PULLUP show me higher value.

On left site is raw measurement, on the right site is calculated value of voltage. With PULLUP mode this is not accurate, and if I want make it accurate with that mode, I need one more time calculate raw value by actual voltage on battery from voltage meter.

maxim2511:
schematic is in attachment.

Well let's see it then!
batery_charger.png

maxim2511:
Before You ask me why I use pin mode for all pins, answer is to eliminate all floating pins with noise what can affect my measurement for battery. Is one of that solutions what I found on internet.

Sounds as if you found the wrong one.

To stabilise unused input pins, you do not set them to OUTPUT. You set them to INPUT_PULLUP. This makes it safe should they accidentally be connected to something.

And whether or not it actually does anything, you should not attempt to change the mode of or write to pins 0 or 1.

maxim2511:

  for (short i = 0; i < 18; i++) {
pinMode(i, OUTPUT);
digitalWrite(i, 1);

}
short pin[4] = {A0, A1, A2, A3};

for (short i = 0; i < 4; i++) {
pinMode(pin[i], OUTPUT);
digitalWrite(pin[i], 1);
}

Somewhat odd approach - you set all pins HIGH except A4 and A5, then do it again for the analog pins using different names! A0 to A3 are of course, pins 14 to 17 on the 328.

maxim2511:

  pinMode(A0, INPUT);

delay(1);
for (short i = 0; i < 1; i++) {
input = analogRead(A0);
}

That is indeed, a short loop! Only runs once. :astonished:

maxim2511:

  {
pinMode(A0, OUTPUT);
digitalWrite(A0, 1);
delay(1);
delay(2000);

}

So A0 is connected to a battery, and you are going to write it HIGH as an output? Is that a good idea?

May be a few bugs in the code. :grinning:

Paul__B:
Well let's see it then!
batery_charger.png
Sounds as if you found the wrong one.

To stabilise unused input pins, you do not set them to OUTPUT. You set them to INPUT_PULLUP. This makes it safe should they accidentally be connected to something.

And whether or not it actually does anything, you should not attempt to change the mode of or write to pins 0 or 1.
Somewhat odd approach - you set all pins HIGH except A4 and A5, then do it again for the analog pins using different names! A0 to A3 are of course, pins 14 to 17 on the 328.

That is indeed, a short loop! Only runs once. :astonished:
So A0 is connected to a battery, and you are going to write it HIGH as an output? Is that a good idea?

May be a few bugs in the code. :grinning:

Yes, A0 is connected to battery and yes, I make it to high. Because battery have internal resistance and it will not take more then 100mA. I did measure outgoing amperage. Other wise I will use resistor for the battery if internal resistance would be to low.

Yes short loop I need, because first measurement is inaccurate, and second one show me proper value. That's why I need second measurement. I think is because of switching mode of that pin, that's why first value is very low.

No, I use arduino micro, and there are 3 analog pins on board.

Question was about INPUT and INPUT_PULL-UP. When I switch to this second I have value about 100 steps higher, and this post was about.

And thank You for tip about setting all pins to INPUT_PULL-UP. you have right. I will do it.

maxim2511:
Yes, A0 is connected to battery and yes, I make it to high. Because battery have internal resistance and it will not take more then 100mA. I did measure outgoing amperage. Other wise I will use resistor for the battery if internal resistance would be to low.

The problem is that the Arduino output pin is not rated for more than about a third of that!

maxim2511:
Yes short loop I need, because first measurement is inaccurate, and second one show me proper value. That’s why I need second measurement. I think is because of switching mode of that pin, that’s why first value is very low.

Well, unless I am getting rather vague, the code “for (short i = 0; i < 1; i++)” would run once. Perhaps someone might explain it to me differently.

.
[/quote]

Paul__B:
The problem is that the Arduino output pin is not rated for more than about a third of that!
Well, unless I am getting rather vague, the code “for (short i = 0; i < 1; i++)” would run once. Perhaps someone might explain it to me differently.

You are sure that output of arduino don’t have rate 100mA? You said is 30mA?
Och, I download pin names for arduino pro micro, and there rate per pin is 10mA. =-O

Somehow pro micro is still working… Hm… Interesting
And I have much more analog pins… :-I
In this moment I feel stupid.

But I am able to charge battery 1.2v nimh to maximal voltage 1.33v. Without any problems. Pro micro is not even warm.
Board is set to 3.3V.
Maybe because of that pro micro voltage drop on pins is so low that charging battery don’t make harm to my board.

OK, my mistake about wrong amperage rating on pins.
But what about measurements?
Why pin mode INPUT_PULL-UP measure 100 steps higher then normal mode INPUT.?

Put a 150 Ohm resistor in series with the Arduino pin - guarantees current limiting. May slow down charging but that is not the point.

Whether the chip is warm or not is not particularly relevant - the concern is excess current concentrated on one tiny output FET.

OK thanks, but for output pin 10mA and resistor will really by a little bit of charging.
I started to thinking about external transistor used to charging my battery.

OK. Now what about measurements in this two modes? Anyone know what analnogRead is higher with pin mode INPUT_PULL-UP?