Loading...
Pages: [1]   Go Down
Author Topic: analogRead() returning no 0  (Read 391 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello! I'm playing with IR receiver.. it is photo transistor. The problem is if I disconnect all (except usb) and look into Serial Monitor analogRead(A0) returning strange values (about ~200-300) but not 0. Why? smiley

Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 48
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the input is floating (definition of nothing connected) therefore does not have a defined voltage applied to it.
Logged

Netherlands
Offline Offline
Tesla Member
***
Karma: 87
Posts: 9360
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you post your code and a schematic you use?
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

no schema at all .. just arduino connected to usb ... code..

Code:
void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);
}

void loop() {
  sensorValue = analogRead(A0);            
  Serial.print("sensor = " );
Serial.print(sensorValue);  
}
Logged

Netherlands
Offline Offline
Tesla Member
***
Karma: 87
Posts: 9360
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


If it only prints 0's it could be that the A0 line is grounded somehow. Can you check the other analog ports?
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

how sensor is connected?

if sensor make ground connection when it got ir try with these two lines....

Code:
void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);
pinMode(A0, INPUT)
digitalWrite(A0, HIGH)
}

« Last Edit: January 31, 2012, 05:17:48 pm by uk350 » Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 29
Posts: 2882
I only know some basic electricity....
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The analog pin is not connected to anything and the pin mode is not set. The reading should float and be about good for a poor random number generator.
Logged

Examples can be found at Learning in the Main Site and at the Playground

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 269
Posts: 25416
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
pinMode(A0, INPUT)
digitalWrite(A0, HIGH)
Is no good because it makes the analogue input into a digital input and enables the internal pull up resistor.

See:-
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html
About floating inputs.
Logged

Pages: [1]   Go Up
Print
 
Jump to: