Go Down

Topic: analog input alters voltage... doesn't read properly (Read 6284 times) previous topic - next topic

pcguru000

Apr 28, 2013, 02:28 am Last Edit: May 04, 2013, 04:18 am by pcguru000 Reason: 1
So hopefully this schematic will explain what i'm doing well enough.

The problem i am having is that my A0 (and all other input pins) are somehow breaking my reading- w/o the arduino hooked up I read specific ranges for each gear (check the schematic) - but as soon as I connect the A0 pin to the wire it should *read* voltage from- it locks up on 3.98 volts- and doesn't budge.

Why would this happen?

Schematic:




All of my so-so code:

Code: [Select]

 const int bottomLeft = 3;
 const int bottom = 6;
 const int bottomRight = 2;
 
 const int topRight = 7;  
 const int top = 1;  
 const int topLeft = 4;

 const int middle = 5;


void setup() {
 
 pinMode(bottomLeft, OUTPUT);
 pinMode(bottom, OUTPUT);
 pinMode(bottomRight, OUTPUT);
 
 pinMode(topRight, OUTPUT);
 pinMode(top, OUTPUT);  
 pinMode(topLeft, OUTPUT);

 pinMode(middle, OUTPUT);

 pinMode(A0, INPUT);
 
 //debug
 //Serial.begin(9600);
}


int incomingByte = 0;
int prevByte = 2;
int currentByte = 0;
int testing = 0;

void loop() {
 if (testing == 1){
   test();
   //digitalWrite(6,HIGH); // test individual segments    
 }else{
 int raw = 0;
 float val = 0;
 float avgVal = 0;
 
 for (int i=0; i <= 99; i++){
     raw = analogRead(A0); //  read 0-5 volts from the GPS
     val = fmap(raw, 0, 1023, 0.0, 5.0); // volts are 10 bit (0-1023) so map it back to a proper volt number
     avgVal = avgVal+val;
 }

 //Serial.println(avgVal/100); //voltage
 
 //1st: 1.36V
 //2nd: 1.77V
 //3rd: 2.49V
 //4th: 3.23V
 //5th: 4.1V
 //6th: 4.55V
 //N: 5V
 
if (avgVal <= 4.24){
 reset();
 first();
}

if (avgVal >= 4.25 && avgVal <= 4.31){
 second();
}

if (avgVal >= 4.32 && avgVal <= 4.40){
 third();
}

if (avgVal >= 4.41 && avgVal <= 4.56){
 fourth();
}

if (avgVal >= 4.57 && avgVal <= 4.72){
 fifth();
}

if (avgVal >= 4.73 && avgVal <= 4.89){
 sixth();
}

if (avgVal >= 4.90){
 neutral();
}
   
   

 
 delay(1);
   }
}

void reset(){  
 digitalWrite(bottomRight,HIGH);  
 digitalWrite(bottom,HIGH);
 digitalWrite(bottomLeft,HIGH);
 
 digitalWrite(topRight,HIGH);
 digitalWrite(top,HIGH);  
 digitalWrite(topLeft,HIGH);

 digitalWrite(middle,HIGH);
}


void first(){
 reset();
 digitalWrite(topRight,LOW);
 digitalWrite(bottomRight,LOW);
}

void second(){
 reset();
 digitalWrite(top,LOW);
 digitalWrite(topRight,LOW);
 digitalWrite(middle,LOW);
 digitalWrite(bottomLeft,LOW);
 digitalWrite(bottom,LOW);
}
void third(){
 reset();
 digitalWrite(top,LOW);
 digitalWrite(topRight,LOW);
 digitalWrite(middle,LOW);
 digitalWrite(bottomRight,LOW);
 digitalWrite(bottom,LOW);
}
void fourth(){
 reset();
 digitalWrite(topLeft,LOW);
 digitalWrite(middle,LOW);
 digitalWrite(topRight ,LOW);
 digitalWrite(bottomRight,LOW);
}
void fifth(){
 reset();
 digitalWrite(top,LOW);
 digitalWrite(topLeft,LOW);  
 digitalWrite(middle,LOW);
 digitalWrite(bottomRight,LOW);
 digitalWrite(bottom,LOW);
}
void sixth(){
 reset();
 digitalWrite(top,LOW);
 digitalWrite(topLeft,LOW);
 digitalWrite(bottomLeft,LOW);
 digitalWrite(bottom,LOW);
 digitalWrite(bottomRight,LOW);
 digitalWrite(middle,LOW);
}
//animated neutral "spins"
void neutral(){  
 digitalWrite(bottomLeft,LOW);
 delay(100);
 reset();
 digitalWrite(bottom,LOW);
 delay(100);
 reset();
 digitalWrite(bottomRight,LOW);
 delay(100);
 reset();
 digitalWrite(topRight,LOW);
 delay(100);
 reset();
 digitalWrite(top,LOW);
 delay(100);
 reset();
 digitalWrite(topLeft,LOW);
 delay(100);
 reset();  
}

void test(){
 
 
 first();
 delay(1000);
 
 second();
 delay(1000);
 
 third();
 delay(1000);
 
 fourth();
 delay(1000);
 
 fifth();
 delay(1000);
 
 sixth();
 delay(1000);
}

//Mapping function, used to convert 0-1023 to 0-5 volts
float fmap(float x, float in_min, float in_max, float out_min, float out_max)
{
 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

Robin2

Your diagram is much too big to read easily.

It looks like you have no ground connection between the Arduino and the gear indicators.

...R

pcguru000

#2
Apr 28, 2013, 05:37 pm Last Edit: Apr 28, 2013, 05:42 pm by pcguru000 Reason: 1
Ha- fits well on a 27" 1440p monitor... sorry my bad. -- updated OP image.

So perhaps I need to use the ground line from the GPS... I thought it would be the same thing as the ground on the rest of the bike, I mean it IS running to the common ground on the rest of the bike AFAIK.

pcguru000

Altered it a bit this morning- grounding directly to the GPS sensor now- its like  .1 volt difference vs grounding to the frame or the neg. battery terminal.

Regardless- all my readings w/o the Arduino A0 pin attached- look right-... as soon as i plug the arduino in though the numbers go all over the place... doesn't make ssense.

Robin2

You haven't said how you are generating the gear change voltages.

How are you measuring the voltages without the Arduino? Perhaps you are using a digital multimeter which has a very high impedance - several megaOhms. The Arduino's ADC input pins have an impedance of about 10k ohms. This may affect things.

...R

PeterH


The Arduino's ADC input pins have an impedance of about 10k ohms.


Are you sure about that?
I only provide help via the forum - please do not contact me for private consultancy.

pcguru000

#6
Apr 28, 2013, 08:26 pm Last Edit: Apr 28, 2013, 08:28 pm by pcguru000 Reason: 1

You haven't said how you are generating the gear change voltages.

How are you measuring the voltages without the Arduino? Perhaps you are using a digital multimeter which has a very high impedance - several megaOhms. The Arduino's ADC input pins have an impedance of about 10k ohms. This may affect things.

...R



You sir deserve a gold star :)

I think this is what is going wrong... i was just triple checking my voltage readings- with my multimeter when it occurred to me- maybe the readings on the meter are different from what the arudino sees.

This said- what should i do about it? Perhaps I need to add a resistor or 3 ? Or am I misunderstanding this again...

I might try and set this up on my laptop- all next to the bike, then I could get the readings FROM the arduino- via serial... and know for sure what it is getting.



Robin2

"The ADC is optimized for analog signals with an output impedance of approximately 10 k? or less"

Extract from Section 23.6.1 of Atmel doc8161.pdf

...R





The Arduino's ADC input pins have an impedance of about 10k ohms.


Are you sure about that?

pcguru000

So what is the verdict? What is the solution for this?

DVDdoug

Quote
So what is the verdict? What is the solution for this?
I can't think of any reason this is happening.   That's why I didn't answer before...   Maybe figure-out a different way of detecting gear selection?


I don't know why the gear indicator output would be high impedance, yet this is the "obvious" cause of what you are seeing.  (Unless it's not really an "output".)   

Because of it's very-high impedance, the Arduino's input shouldn't affect anything it's connected to, unless the voltage is greater than 5V, or negative.  (Internal protection dioes start conducting when the input goes nevative, or above the power supply voltage.)

Are you sure you have 5V powering the Arduino?   Are you sure the gear-output voltages are not negative?

An op-amp buffer circuit is the usual solution (to increase the input-impedance, or decrease the output impedance).  But, the Arduino already has very-high input impedance.

Quote
"The ADC is optimized for analog signals with an output impedance of approximately 10 k? or less"

Extract from Section 23.6.1 of Atmel doc8161.pdf

...R
That means that the output (source) impedance of whatever is driving the ADC input should be less than 10K.  The Arduino's input impedance is much greater...  The spec sheet (page 377) says 100 Megohms minimum.





Runaway Pancake

http://arduino.cc/forum/index.php?topic=65134.0

http://electronics.stackexchange.com/questions/36394/arduino-analog-input-example-clarification

http://forums.hackaday.com/viewtopic.php?f=4&t=564

http://tronixstuff.wordpress.com/2010/12/07/tutorial-arduino-and-the-aref-pin/

https://sites.google.com/site/measuringstuff/the-arduino
"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

pcguru000

Great info on a few of those-

"Attach a 1k-100k resistor to ground on the floating pin and repeat the test. "

This is what I was *guessing* i'd need to do- but just so I understand this correctly- This implys that I cross my signal and ground wires, with a resistor?

Please excuse my noob understanding of electronics- I thought I'd just be hooking a couple wires up to get X voltage- the impedance stuff has me baffled.

pcguru000


Quote
So what is the verdict? What is the solution for this?
I can't think of any reason this is happening.   That's why I didn't answer before...   Maybe figure-out a different way of detecting gear selection?


I don't know why the gear indicator output would be high impedance, yet this is the "obvious" cause of what you are seeing.  (Unless it's not really an "output".)   

Because of it's very-high impedance, the Arduino's input shouldn't affect anything it's connected to, unless the voltage is greater than 5V, or negative.  (Internal protection dioes start conducting when the input goes nevative, or above the power supply voltage.)

Are you sure you have 5V powering the Arduino?   Are you sure the gear-output voltages are not negative?

An op-amp buffer circuit is the usual solution (to increase the input-impedance, or decrease the output impedance).  But, the Arduino already has very-high input impedance.

Quote
"The ADC is optimized for analog signals with an output impedance of approximately 10 k? or less"

Extract from Section 23.6.1 of Atmel doc8161.pdf

...R
That means that the output (source) impedance of whatever is driving the ADC input should be less than 10K.  The Arduino's input impedance is much greater...  The spec sheet (page 377) says 100 Megohms minimum.



And yes- i am sure i've got a 5v power for the Arduino- tested that a few times, its a V regulator from radioshack... solid as a rock at 5 volts.

Thanks also for the op-amp suggestion, i had read that elsewhere... something new i don't know about haha :)

Runaway Pancake

Someone asked before, but, what's the shakedown on this "gear position sensor"?
Any links, PDFs, etc?
"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Runaway Pancake

"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Go Up