Go Down

Topic: UNO with a Motor shield and 200ohm potentiometer (Read 702 times) previous topic - next topic

fofro

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)/1023*5

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)

This is the script I have been trying to run:

Function motor

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);                   
end
end

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

retrolefty

Well this seems to be a cross posting of one you already made? That tends to piss off the moderators here. Anyway I responded to your first post about a possible programming error, but as I don't know metlab I can't say the for sure. Anyway:

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

Code: [Select]
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

MarkT

Please post code in
Code: [Select]
// code tags, its much much easier to read and doesn't mangle it

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

Is missing a ';'

You have a linear taper pot?  Sounds like a log-taper if you read 0.5V in mid-range.  Have you checked using an Arduino-side sketch to print the values?
[ I won't respond to messages, use the forum please ]

Grumpy_Mike

I used to have kids like this. If you don't like the answer you get first time ask again incase the laws of physics have changed.
You still have the same problem we told you about in the other thread, if you read 2.5B wit a meter and do not get arround 512 as a reading it is your software that is screwed.

Go Up