Very Basic Newbie question ANALOG READ

Hi
I am owning a Arduino Uno.

I am reading analog value from 2 pots and would like more stable reading (or less accurate)
then displaying on LCD.

Is there a easy way to divide the result to have less step ? (I understand on the uno I can't change the ADC resolution.)

of course now it give me 1023 step which is way too much in my case (100 steps would be great )

how can I integrate this extra lines in the code below ?

what I the best way to achieve that ?
thanks you so much !

P ;D

9000_TEST.ino (727 Bytes)

If you divide the value returned by analogRead() by 4 or shift it right 2 places, which amounts to the same thing, then the reading will be from 0 to 255.

Is that the sort of thing you had in mind ?

Incidentally, you will get more help if you post your code in the forum like this

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);


int potPin1 = A1;
int potPin2 = A2;

void setup()
{
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  lcd.clear();
  pinMode(potPin1, INPUT);
  pinMode(potPin2, INPUT);
}

void loop()
{
  lcd.setCursor(0, 0); // Sets the cursor to col 0 and row 0
  lcd.print("Line Input 9K: "); // Prints Sensor Val: to LCD
  lcd.print(analogRead(potPin1)); // Prints value on Potpin1 to LCD
  lcd.setCursor(0, 1); // Sets the cursor to col 1 and row 0
  lcd.print("Mic  Input 9k: "); // Prints Sensor Val: to LCD
  lcd.print(analogRead(potPin2)); // Prints value on Potpin1 to LCD
}

See Read this before posting a programming question

thanks you so much for the advice
will be careful next time I post

could you show me where and how to write it into the code ? (sorry very basic question)

thanks a lot !!
P

  lcd.print(analogRead(potPin1) / 4); // Prints value on Potpin1 to LCD

For completeness you should also update the comments to reflect the pin being read and the change of range

exactly what I needed !
working perfectly !
thank you so much

P

It may also be a good idea to scrap the first reading from each pin in case the ADC still has some residual voltage from the other pin - like this

void loop()
{
  lcd.setCursor(0, 0); // Sets the cursor to col 0 and row 0
  lcd.print("Line Input 9K: "); // Prints Sensor Val: to LCD
  int scrap = analogRead(potPin1); // this reading is not used
  lcd.print(analogRead(potPin1)); // Prints value on Potpin1 to LCD
  lcd.setCursor(0, 1); // Sets the cursor to col 1 and row 0
  lcd.print("Mic  Input 9k: "); // Prints Sensor Val: to LCD
  scrap = analogRead(potPin2);
  lcd.print(analogRead(potPin2)); // Prints value on Potpin1 to LCD
}

...R

The map() function works too:

rawADC = analogRead(potPin1);
newADC = map(rawADC,1023,0,100,0);

There you can choose almost any range, even swap values like 1023 maps to 0 and 0 maps to 100 map(rawADC,1023,0,0,100)

edpsycho:
The map() function works too:

rawADC = analogRead(potPin1);

newADC = map(rawADC,1023,0,100,0);




There you can choose almost any range, even swap values like 1023 maps to 0 and 0 maps to 100 *map(rawADC,1023,0,0,100)*

how would you integrate this to my code ?
tx
p

:astonished:
Ok, first you have to initialize the new vars:

int rawADC = 0;
int newADC = 0;

Then before you print the values on the LCD:

.
.
.
rawADC = analogRead(potPin1);
newADC = map(rawADC,1023,0,100,0);
lcd.print(newADC); // Prints value on Potpin1 to LCD
.
.
.

thanks edpsycho !
will try :-))

I have one last question :

what would be the easiest way to display the exact same value as the lcd the serial monitor ?

can't get it to work properly

thanks guy !

P

Just print the same variable to both