514Views17Replies

Author Options:

Serial communication on Arduino? Answered

I tested a QRD1114 reflective sensor using a voltage meter, and was working great. I was getting good responses from the sensor (one of the sensors I was using had a bad LED which was not working, but the sensor worked fine with an external IR LED that I had laying around.) But as soon as I hooked it up to an analog input pin of my arduino board, and used the serial communications to display the reading from the sensor on the serial monitor, every reading would be 1023 (which should be the highest possible reading) even when there wasn't anything near the sensor. I changed the pin, so I know it isn't a defective pin. I repeated the test with a photo cell and got similar results. what could be the problem, and what can I do about it?

Discussions

0
None
steveastrouk

Best Answer 6 years ago

Show your circuit diagram, for a start.

Steve

0
None
Higgs Bosonsteveastrouk

Answer 6 years ago

would it be possible to use a small capacitor (maybe 0.01 uf) to connect it to the analog pin so that it is not directly connected? Would that fix the problem do you think?

0
None
steveastroukHiggs Boson

Answer 6 years ago

No, This is a DC signal - how would it flow through the capacitor.

Steve

0
None
Higgs Bosonsteveastrouk

Answer 6 years ago

Yeah I was thinking that maybe you would change the program so that the output would be based on how fast the capacitor charges and discharges, but I don't think that would work very well.

0
None
steveastrouk

6 years ago

Ah ! A completely wrong circuit......

Do this:

Connect a 4.7K resistor from the phototransistor emitter to ground. Connect the arduino pin to the emitter.


Steve

0
None
Higgs Bosonsteveastrouk

Answer 6 years ago

I tried the new circuit, and it didn't help. Do you think that it would be better just to connect the emitter from the phototransisitor to the base of a switching transistor and then just connect the transistor tho the power and a digital pin?

0
None
steveastroukHiggs Boson

Answer 6 years ago

No.

Your circuit now looks OK, but is the ground of this connected to the ground of the arduino ?

You may have to alter the resistor values to get decent results. Make the 68 Ohm bigger.

Steve

0
None
steveastroukHiggs Boson

Answer 6 years ago

Change the circuit, put the resistor from collector to the 5V line, connect the emitter to ground, connect the arduino to the collector. This configuration has a higher gain than the other circuit, but the output is never less than a volt or so.

Steve

0
None
Higgs Bosonsteveastrouk

Answer 6 years ago

Wow! works loads better now! thank you for all of your help.

0
None
frollard

6 years ago

Okay, are you talking to the sensor with SERIAL or are you reading the analog value from the sensor?

http://arduino.cc/en/Tutorial/AnalogInOutSerial

What happens when you use this code?

0
None
Higgs Bosonfrollard

Answer 6 years ago

the read out stays at 1023 still. works fine with pots though.

0
None
frollardHiggs Boson

Answer 6 years ago

that tells me the sensor isn't putting out a variable voltage between 0 and 5 volts. Does it have a dc bias? (like outputting between 3-8 volts for max to min readings)

0
None
Higgs Bosonfrollard

Answer 6 years ago

I don't know, but with my voltage meter it was saying that with 5v when a white object was right above it it was a little under 5 volts, and just over 0 when there was nothing due to ambient light. It seems that the sensor is working fine without the arduino, it is getting it to work with the arduino that is giving me trouble. the examples for serial monitor didn't seem to be working with the LDR, bur as soon as I connected a regular resistor it was consistant, and when it was hooked up to the wiper pin on a pot it worked great. could it be something with the code? I tried the example you gave me, and nothing changed. have you ever hooked up an IR sensor to arduino before? None of the tutorials are very helpful.

0
None
Higgs Boson

6 years ago

Its been working fine with resistors (other than photoresistors) and potentiometers. But with the LDRs and the photo transistor, it either stays at the largest value possible, or goes from a few values of 0 to a larger value then 1023 and back down in a predictable wave pattern. (I forgot to mention this in the question.