509Views17Replies

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?

17 Replies

user
steveastroukBest Answer (author)2011-12-20

Show your circuit diagram, for a start.

Steve

Select as Best AnswerUndo Best Answer

user
Higgs Boson (author)steveastrouk2011-12-20

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?

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)Higgs Boson2011-12-20

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

Steve

Select as Best AnswerUndo Best Answer

user
Higgs Boson (author)steveastrouk2011-12-20

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.

Select as Best AnswerUndo Best Answer

user
Higgs Boson (author)steveastrouk2011-12-20

Here is the diagram. sorry for my messy handwriting.

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)2011-12-20

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

Select as Best AnswerUndo Best Answer

user
Higgs Boson (author)steveastrouk2011-12-20

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?

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)Higgs Boson2011-12-20

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

Select as Best AnswerUndo Best Answer

user
Higgs Boson (author)steveastrouk2011-12-20

The ground is connected to the ground on the arduino.

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)Higgs Boson2011-12-20

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

Select as Best AnswerUndo Best Answer

user
Higgs Boson (author)steveastrouk2011-12-20

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

Select as Best AnswerUndo Best Answer

user
Higgs Boson (author)steveastrouk2011-12-20

sop the circuit would be this right?

Select as Best AnswerUndo Best Answer

user
frollard (author)2011-12-20

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?

Select as Best AnswerUndo Best Answer

user
Higgs Boson (author)frollard2011-12-20

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

Select as Best AnswerUndo Best Answer

user
frollard (author)Higgs Boson2011-12-20

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)

Select as Best AnswerUndo Best Answer

user
Higgs Boson (author)frollard2011-12-20

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.

Select as Best AnswerUndo Best Answer

user
Higgs Boson (author)2011-12-19

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.

Select as Best AnswerUndo Best Answer