View Full Version : [Question(s)] I'm having trouble getting an arduino analog input to work

09-01-2009, 12:28 AM
Here's the setup. I have a resistor ladder that creates the same effect as a pot, just with 11 specific voltages. I'm feeding this signal into an op amp wired for negative feedback. The resistor ladder, the arduino, and the opamp are all powered from the same source (12 volt battery). with it all set up and wired and ready to go, I put my multimeter straight on the AI pin, already hooked up to the opamp output, I read a max of 4 volts, and it drops to 0 depending on theresistor in the ladder that is activated.

In short, it all appears to be working exactly like it should.

So to debug, I initialize the serial port, hook it up to my computer, and command a serial print of the read value of the analog port. Again, at "idle" the pin reads FOUR VOLTS, and when I pull up hyperterminal, I read straight 0's. Doesnt respond at all to the inputs.

I'm not even sure what to think. I'm left with no clues why the read comes back all zero, not sure where to start troubleshooting. Anyone have suggestions where to start?

09-01-2009, 12:58 AM
Welcome to the forum!

Sounds like you have your hardware in line. Posting your code would be the next step!

09-01-2009, 01:17 AM
int SWI1 = 1
int SWI2 = 2

void setup()

void loop()


Seems like it should work.... (swi2 doesnt work either)

So I have to admit there is other code in there too, but I didn't include it. Can other code muck up what is here? Like using DIO pin 2? I'm not currently using DIO 0 and 1 (thought might be in the future)

Oh, and thank you for the welcome :)

09-01-2009, 02:07 AM
Try this:

int analogInput = 0; // Just a place to hold the input value

void setup()
// open the serial port at 9600 baud

void loop()
// read the analog input on pin 0 (are you SURE you're using analog input 1 and not analog input 0?)
analogInput = analogRead(0);

// print it out to the serial port as an ASCII-encoded Decimal value

// give it some time to get there

If that works, than you should probably set out to debug the code that you didn't bother to post...

09-01-2009, 02:41 AM
I'll give it a shot. I'm sure I'm using 1 and 2 and not 0 because I'm using 0 for something else. And the code works for AI 0 which just has a simple pot attached.

However, when I was testing THAT, I was doing what I think you did above. read the input and write it to a global variable before printing it.

Is there a reason to write the analogRead command to a variable then Serial.Print the variable? Rather than serial.printing the analogRead command itself?