LCD shield -Analog input A0 changes value continuously

We have tried to recieve analog values from the A0 port in this LCD shield http://www.robotshop.com/en/dfrobot-lcd-keypad-shield-arduino.html

The value changes when we connect new components to the arduino and therefore we have to update our program coding (if statement). Is there any way to configure the input values from the buttons as digital values instead of analog values, alt, use the other analog ports (A1, A2, A3, A4, A5)

Thank you for reading, and i hope you can help us.

while(beslut==1)//så länge select knappen inte är intryckt

  • { *
    _ if(counter=!0)_

  • {*

  • delay(3000);*

  • counter–;*

  • }*

  • x=analogRead(0);*

  • lcd.setCursor(10,0); // Set cursor to*

  • lcd.print(x); // Print text on LCD*

  • if(x>6300)//SELCET KNAPPEN HAR TRYCKTS IN*

  • {*

  • if(svar_fran_spelare>=0){*

  • beslut=0;}*

  • }*

  • if(x<1010 && x>990)//upp knappen*

  • {*

  • svar_fran_spelare++;*

  • lcd.setCursor(12,1);*

  • lcd.print(svar_fran_spelare);*

  • }*

  • if(x<2700 && x>2400)//ner knappen*

  • {*
    /*if(svar_fran_spelare==0)

  • {*

  • continue;*
    _ }*/_

  • svar_fran_spelare–;*

  • lcd.setCursor(12,1);*

  • lcd.print(svar_fran_spelare);*

  • }*
    }

The value changes when we connect new components to the arduino

Sounds like you are using the "default" Vcc (+5Volt) reference... Increasing load may be dropping your supply voltage and giving incorrect/fluctuating A/D readings. If you have a DVM, measure the +5 after the voltage regulator for variations.... Better, use a DC o'scope if available.

Ray

A0 is used to read the analog value from the keypad to determine which key is pressed.

Did you use their libraries?

Why are your test values so high?

Follows is some code from their site and notice the values for the 5 keys.

// include this library's description file

#include <LiquidCrystal.h>
#include "LCDKeypad.h"

LCDKeypad::LCDKeypad() : LiquidCrystal(8, 9, 4, 5, 6, 7)
{
}

int LCDKeypad::button()
{
  static int NUM_KEYS=5;
  static int adc_key_val[5] ={  
    30, 150, 360, 535, 760     };
  int k, input;
  input=analogRead(0);
  for (k = 0; k < NUM_KEYS; k++)
  {
    if (input < adc_key_val[k])
    {
      return k;
    }
  }
  if (k >= NUM_KEYS)
    k = -1;     // No valid key pressed
  return k;
}

Well, clearly if A0 is used for the pushbuttons, you will not be connecting it to any other components, will you?

As the analog read routine returns values only up to 1023, your comparisons in the code cited are not going to be useful at all.

Speaking of code, please go back and select "modify" on your first post, highlight the code section and mark it as such with the "code" ([ # ]) icon above the submission window and re-save it.

As the pushbutton inputs are ratiometric, fluctuations in the supply voltage do not matter.

Also do check that you have a version 1.0 board rather than a 0.01, which earlier board has a really nasty problem with the backlight control explained in the "sticky" up the top of this forum.