I just got an Arduino Uno and I'm trying to use it on a project where I can turn a pot and using a voltage divider be able to store the value as a variable. In other words, I'm using a potentiometer as a voltage divider, running it through a A/D converter then through a Parallel to Serial IC where it comes out as an 8 bit binary number and I want to store that number as a variable where I can compare numbers to it. Is this even possible? Is there an easier way?
If this makes no sense let me know because I am having trouble understanding what I'm doing.
Warning: I have only ever programed in Java so please dumb everything down.
AWOL
Thanks for the quick response. This is my first time ever using a microprocessor let alone an arduino, so that code makes no sense to me. From what I understand it reads in an analog signal on a selected pin, divides that by 4 and stores as a byte? If so then I don't think that's what I'm looking for.
poor choice of variable name ... :. (gets compile error) Slightly better is
bytevalue = analogRead(A0) / 4;
We're assuming here that the output of your voltage divider is connected to analog input pin 0 on the Arduino ("A0" is predefined to this pin in ver.22, it is another improvment I sneaked in :. )
Msquare, so if i plug the output of my voltage divider into pin0 that code would store a value between 0-255 in the variable "bytevalue". One quick question, what is the voltage that it would be comparing my output to? From what I understand a voltage divider would give me a voltage between 0-5v (since im putting 5v into the pot), and the A-D converter put it into a number between 0-255 relative to the voltage that the A-D converter is running at, so what voltage would the Arduino be comparing it to?
The default analogue reference is the supply voltage, so for most Arduinos, this is 5V.
The converter is a 10 bit (0...1023) device, so we divide by 4 to fit the value into a byte. http://arduino.cc/en/Reference/AnalogRead