webserver analog input

Hi, I am new, I just bought arduino. I tried runing the tutoriol code http://arduino.cc/en/Tutorial/WebServer, my web show this result;-

analog input 0 is 464 analog input 1 is 423 analog input 2 is 880 analog input 3 is 769 analog input 4 is 693 analog input 5 is 673

but only input 2 is connected to a sensor. Why other input show value as well?

Thanks

Because they're not connected to anything, they are said to be "floating" and are picking up all sorts of interference. If you want them to read zero, short the unused pins to ground. Or just don't print their values.

I have connected my board to an ultrasonic. with the reading between ~1-1000. i track the reading every few second. But my reading change between 820 to 850 every few second. While the ultrasonic measure the river level that is always the same, and LCD panel show the same level, my board keep giving me differences value every second(820 to 840). Why? ,thanks.

It is called noise.

First: What is your circuit? It's hard to tell much without knowing that.

Second, here are some debugging techniques that will probably help isolate what the problem is:

If you hook up an oscilloscope (or multimeter) to the output of the sensor, does it change the same as the Arduino?

If you hook up a potentiometer instead of the sensor to the Arduino, and change the value of the potentiometer, does the Arduino program give you the output you expect?

I have an ultrasonic sensor(4-20mA) connected to a 200ohm resistor and then to arduino analog pin, and from arduino grd pin to ground. Power using normal 5v power adapter.

I tested it with multimeter and the voltage from the sensor is stable(doesn't change), the lcd panel on the sensor is also stable.

I test the board using rotating sensor in the office(not at site yet) also stable.

I read on some post on mechanical switch that use pull-down resistor, should I do this?

A pull-up or pull-down resistor can often be helpful in eliminating floating/noisy signals. Try wiring a 10 kOhm resistor from the Arduino analog in pin to +5V (or to ground) and see if it helps.

Note that the amount of variance you're talking about (820 -> 840) is only about 2% of the output signal, so a multimeter might not actually show that variation. Similarly, a LED display that smooths or clips out small changes may also not show this change.

Thus, it's not certain that a pull-up/down will fix your problem, because the problem may be "works as designed." It's hard to know without knowing more about the specific parts you're using.

I guess you might be right but 2% from 5 meter is 100cm and for a river level it make lot of different. So i tried using average, and it seem to work(static value). So in order to measure the river level i took two point. The point I took is 3.72 meter and 4.76 meter. And build a formula using y=mx+c. But if the the real river level went 4.20 my calculation is less 2% that is 4.1. Is there other way? Thanks

Is there other way?

I'd try putting a capacitor on the input pin between it and ground to smooth the voltage fluxuations.

kmkn: I guess you might be right but 2% from 5 meter is 100cm and for a river level it make lot of different. So i tried using average, and it seem to work(static value). So in order to measure the river level i took two point. The point I took is 3.72 meter and 4.76 meter. And build a formula using y=mx+c. But if the the real river level went 4.20 my calculation is less 2% that is 4.1. Is there other way? Thanks

I think 2% of 5 meters is 10 centimeters. Is the water flowing? Is the sensor ultrasonic? Is it sensitive to movement in what is being monitored?

You might be better off with a filter on the input channel. This filter can be analog (someone suggested a simple capacitor and using the resistance of the circuit itself for an RC filter). Or it can be digital.

If you only need measurements every so often (say, every 10 seconds), then you can measure more often than that (say, every 1 second, or 10 times a second) and average the measurements. This will serve as one kind of filter that doesn't need analog components, but is implemented entirely digitally (as "DSP.")

Other kinds of filters go from the "leaky integrator" (technically a single-pole filter) through the "bi-quad" (technically a two-pole/two-zero filter) through more advanced cascades of filters, where the problem starts becoming precision loss in the digital math, or convolution filters, where the problem starts becoming the number of math operations needed per sample. Technically, taking 10 or 100 readings and then reporting the average of them is a simple form of convolution and down-sampling in a single operation. Not so good for fast signals (like sound, say), but probably very good for your particular use case :-)