I am using a potentiometer-type position sensor. I have set up a voltage division circuit, and the voltage differential from the sensor to ground currently reads about 2V on a multimeter.
However, when I read it at pin 9 with the following code, it reports 1023, which should indicate 5V or more.
I am using a brand-new Ruggeduino, but had the same problem with an Uno.
Yes, I ideally need 7 or 8 analog inputs (pressure transducers, position sensor). I had read something about multiplexing, but it looks too complicated for now. I will get by with 6 at first, and then look into it. If you have any suggestions on a good chip/program package for newbies, I'd appreciate it.
Also, do you know if I can use Uno shields on the Mega, or would I have to start from scratch?
Not all the sensors have an analog output, for example DHT11 uses digital communication. Many other uses I2C, and something uses also SPI.
You can save some analog pins choosing different types of sensors
philraf:
Yes, I ideally need 7 or 8 analog inputs (pressure transducers, position sensor). I had read something about multiplexing, but it looks too complicated for now. I will get by with 6 at first, and then look into it. If you have any suggestions on a good chip/program package for newbies, I'd appreciate it.
Pro Mini's are also smaller and cheaper, but don't have a USB interface, you'd need
a USB->serial converter of some sort.
Only the surface mount versions of the ATmega328 bring out the A6 and A7 pins,
note, which is why they are not standard on most Arduinos.
Another option for lots of analog inputs is to use an analog multiplexor chip
to route your signals to one Arduino analog input - several digital outputs are
used to set the multiplexer source.
Since the ADC splits the input voltage range into 1024 equal-sized voltage ranges,
adding 0.5 gives an unbiased estimate of the actual voltage. But that's probably
more accurate than the hardware can actually achieve!
This is the problem of not reading a book on C. If you get a book, the first couple of chapters cover the data types and conversions. Any known programming language tries to preserve accuracy when converting different types of data into the same type, when they are involved in a calculation. Your thinking is just the opposite. But when all data are in the same type, say int for analogRead(), 5, and 1024, the programming language does NOT do any conversion, so integer math applies.
Example: 100*5=500, 500/1024=0
The above is expected behavior and much of computing depends on this behavior. You having an issue with this behavior only means you should use other data type, not the behavior is wrong.