Pages: [1]   Go Down
Author Topic: 200ohms potenciometer as analog input, Arduino UNO  (Read 1193 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi!

I'm having trouble to read the voltage value of the potenciometer's wiper "leg".

I connected it to the 5V-GND of the Arduino, and connect the wiper into A0 analog pin. At 100ohms, I should have read 2.5V, but instead, I got 0,49V! I'm using Matlab instead of IDE.
I set the A0 pin in two different ways to see if it was a syntax error :

pinMode(A0,'input') and pinMode(14, 'input');
potencmt=a.analogRead(0);

but none worked as supposed.Therefore, I connected the Arduino's 5V to A0 to see if I would get 5V, no problem. But with the potentiometer it's inconsistent.

Do I really have to set A0 as input(I believe I dont) in order to "tell" Arduino to increase its impedance?
Do I need to use any special potenciometer functions to read the values?(I believe I dont either)

Regards


Logged

Valencia, Spain
Online Online
Faraday Member
**
Karma: 142
Posts: 5296
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

potencmt=a.analogRead(0);

What's the value returned by analogRead(0)?

0.49 is after you've done some math on it. What's the raw, unmodified value?
Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17259
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

potencmt=a.analogRead(0);

What's the value returned by analogRead(0)?

0.49 is after you've done some math on it. What's the raw, unmodified value?


Which is another way of saying "post your sketch" please.

As a better electrical test, just use your multimeter to measure the wiper terminal voltage while it's wired up to the arduino and check the readings at the two ends of travel and while centered, and confirm that the meter reads 0, +5vdc, and +2.5vdc respectively.

Lefty
« Last Edit: November 19, 2012, 03:02:37 pm by retrolefty » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

potencmt=a.analogRead(0);

What's the value returned by analogRead(0)?

0.49 is after you've done some math on it. What's the raw, unmodified value?


Which is another way of saying "post your sketch" please.

As a better electrical test, just use your multimeter to measure the wiper terminal voltage while it's wired up to the arduino and check the readings at the two ends of travel and while centered, and confirm that the meter reads 0, +5vdc, and +2.5vdc respectively.

Lefty


The returned value is about 100bytes(I don't recall the precise value) and to transform it into voltage, I just have to multiple it
 for 5 and divide it for 1023 due to the pin's resolution of 10bits. The expected value would be 512bytes, which is not happening...

I measured the two ends and the wiper terminal and I got the expected values of 0, 5 and 2.5V respectively.

This is the script I have been using to drive a DC motor with an Arduino Motor shield:

function shield

a=arduino('COM3');

    a.pinMode(12,'output');        %DIR A
    a.pinMode(13,'output');        %DIR B
    a.pinMode(9,'output');         %BRAKE A
    a.pinMode(8,'output');         %BRAKE B
    a.pinMode(3,'output');         %PWM A
    a.pinMode(11,'output');        %PWM B
    a.pinMode(14,'input');         % ??

b=0;

    while(b==0)
       
        a.digitalWrite(12,1); %
        a.digitalWrite(9,0);
        a.analogWrite(3, 255); 
 
        pause(5);

        potmcmt=a.analogRead(0)/1024*5

        a.digitalWrite(9,1);
        pause(5);
         
        a.digitalWrite(12,0);       
        a.digitalWrite(9,0);
        a.analogWrite(3, 255);       
   
        pause(5);                   
        a.digitalWrite(9,1);
 

    end
   
end

But the values returned by a.analogRead(0) don't correspond to the ones read by the multimeter...                                           
Logged

Valencia, Spain
Online Online
Faraday Member
**
Karma: 142
Posts: 5296
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

But the values returned by a.analogRead(0) don't correspond to the ones read by the multimeter...                                           

Does the number vary as you turn the pot? What does it read at min/max?

Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I believe that the A0 pin's impedance is too small, giving a different voltage value on the wiper terminal. It needs to be a very high value in order to read voltage like a voltmeter does...

Anyone knows the A0-A5 pin's impedance? And if it's tunable?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 597
Posts: 33301
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I believe that the A0 pin's impedance is too small, giving a different voltage value on the wiper terminal. It needs to be a very high value in order to read voltage like a voltmeter does...

Anyone knows the A0-A5 pin's impedance? And if it's tunable?
It is nothing to do with the impedance. It is very high and connecting a low impedance to it will not affect the reading.
Why do you use the a.analogueRead and not just analogueRead?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I believe that the A0 pin's impedance is too small, giving a different voltage value on the wiper terminal. It needs to be a very high value in order to read voltage like a voltmeter does...

Anyone knows the A0-A5 pin's impedance? And if it's tunable?
It is nothing to do with the impedance. It is very high and connecting a low impedance to it will not affect the reading.
Why do you use the a.analogueRead and not just analogueRead?

Maybe it hasnt but I think it does. I use a.analogRead bc im using matlab instead of Ide environment...
Logged

Valencia, Spain
Online Online
Faraday Member
**
Karma: 142
Posts: 5296
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe it hasnt but I think it does.

Now you've done it...

Put on your flameproof underwear before Grumpy Mike reads that!

Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17259
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Not familiar with matlab programming 'language' but this from your listing looks wrong:

Code:
potmcmt=a.analogRead(0)/1024*5

No trailing ;
And not sure if integer math will work as truncation/rounding, will kill that calc, no?
Or is matlab converting the components to floating variables. I can't even see where
the potmcmt variable is declared?

Lefty
« Last Edit: November 19, 2012, 08:43:56 pm by retrolefty » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 597
Posts: 33301
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Maybe it hasnt but I think it does.
You can think what you want, but you can't alter the laws of physics by thinking. So while you think that is the problem I am telling you that it is not.
Logged

0
Offline Offline
Full Member
***
Karma: 4
Posts: 218
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Maybe it hasnt but I think it does.
You can think what you want, but you can't alter the laws of physics by thinking. So while you think that is the problem I am telling you that it is not.
More important I think that thinking helps us determine what the laws of physics are and we certainly do not have them all right yet!
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 597
Posts: 33301
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

True but we have this one right and have had so for over one hundred years.
This is not quantum mechanics you know!
Logged

Pages: [1]   Go Up
Jump to: