Pages: [1]   Go Down
Author Topic: analogRead() returning no 0  (Read 674 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
Jr. Member
**
Karma: 1
Posts: 56
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

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 221
Posts: 13848
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 -
(Please do not PM for private consultancy)

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

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 221
Posts: 13848
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 -
(Please do not PM for private consultancy)

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: 98
Posts: 4813
I learn a bit every time I visit the forum.
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

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34524
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
Jump to: