Go Down

Topic: analogRead() returning no 0 (Read 722 times) previous topic - next topic

expream

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? :)


JasonK

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

robtillaart

Can you post your code and a schematic you use?
Rob Tillaart

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

expream

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

Code: [Select]

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

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

robtillaart


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

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

uk350

#5
Jan 31, 2012, 11:05 pm Last Edit: Jan 31, 2012, 11:17 pm by uk350 Reason: 1
how sensor is connected?

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

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



GoForSmoke

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.
Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts

Grumpy_Mike

Code: [Select]
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.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy