Pages: [1]   Go Down
Author Topic: analogRead  (Read 778 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

 In an arduino mega analog pins are consistently displaying value with no hardware connected.

 Test code is below, with serial monitor results.
  All pins have this behavior of reading values ~300 without input.

  I am expecting zero, any hints?
  Is something broken?

Thanks, cnash.

/*TESTCODE*/
const int Pin1 = 3;    
int ANALOG_PRESS_LEVEL = 0;

void setup() {
  Serial.begin(2400);  
  Serial.print("ALIVE_#");  
}

void loop(){
    ANALOG_PRESS_LEVEL = analogRead(Pin1);
    Serial.print(ANALOG_PRESS_LEVEL,DEC);
    Serial.print(", ");
    delay(1000);
}

/*OUTPUT*/
ALIVE_#390, 335, 329, 327, 325, 324, 324, 324, 323, 323, 323, 324,
« Last Edit: November 07, 2010, 04:27:44 pm by cnash44 » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12483
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


As the pins are not connected to 0V or 5V the are floating just in between. Connecting a resistor between pin and GND helps.

Please read this tutorial that explains all http://arduino.cc/en/Tutorial/DigitalPins
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you. My mistake. Corrected many months ago with the information referenced. Porting proof of concept to prototype introduced pull-down-resistor wiring error(trying to combine them). This indeed was the solution.

Best Regards,
Nash
Logged

Pages: [1]   Go Up
Jump to: