Let's Make Robots!

Digital Detection Of Black And White With IR LED And Phototransistor

I have been using a simple Black/white detection circuit with my picaxe to make a line following robot.

i wired up a circuit like the one below and programmed the Picaxe with the code below.

basicly what it did was when the IR LED/Phototransistor pair detected black it sent the number 1 to my computer and when it saw white it sent the number 0. this worked fine with the circuit wired exactly like it is below, but when i changed the Picaxe input to a different pin it just kept constantly sending 0's to my computer.

any ideas why it isn't working on other pins?

Code:

 

top:

if pinc.0 is on then

goto l

else

goto h

endif

goto top

 

l:

sertxd ("1")

sertxd (13,10)

pause 10

goto top

 

h:

sertxd ("0")

sertxd (13,10)

pause 10

goto top

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Have you checked that the circuit has not been knocked / open circuit on white side.  Is this assembled on PCB or just breadboard? Have you tested the current state of the analog input - you stated was as opposed to is.  I realize this is semantics but can lead to misunderstanding.  I would have thought a simple meter reading to check 0 is less than say a volt and 1 is above 3v would also be in order.

when it was sensing white it read about 8 to 9 and when sensing black it was about 25 to 40.

is this enough?

Try connecting to an analog input to check how well your sensor is working. Perhaps your output is not going quite high enough to be detected by all pins.

Yeah i did that

sorry for not making it clear!

Since you changed the input pin on your picaxe I think you will have to change it from 0 to the new input pin in your code.

Hopefully that helps.