Excluding statement in if function

hideki:
Hello everybody! About voltages, I checked again and it seems to be OK. I am using the collector output of phototransistor to get HI and LO data, directly using a 10K Ohm resistor. Anyway, I will try your tips and I will give you a feedback soon. Thank you, guys!

I would set up some serial prints to see what the arduino is seeing rather than using a volt meter. I built a control pad that used 4 optical switchs (tcrt5000L) my connection diagram is different than the one you posted.

Im sending 5v to the led anode then from the led cathode im using a 200 ohm resistor to ground.

on the sensor side im sending 5v to the collector then from the emitter I am going to the arduino pin and I have a 10k resistor from the emitter to ground.

If you use a digital camera or the camera on your phone you should be able to see if the led is on as it will show up as light blue.

I have the switchs behind a piece of clear plastic (so you touch the plastic to activate) and they have proven to be reliable but sometimes annoying as you can swipe and accidently hit the next one over. I also programmed them to look for statechange rather than using them as direct inputs.

Hi,
Did you read this?

the phototransistor is also sensitive to normal light, so you will have noise on the collector signal.

Try putting a 0.1uF capacitor from the digital input to gnd on each of your opto-outputs.

The idea of Serial.prints is excellent.

Tom.. :slight_smile:

IMHO you can Try like this

st=digitaread (input1)+2*digitalread (input2);
if (st!=status)
{
\\ changed

Status=st;

Switch (status){
Case (0):
Action...
Break;
case (1):

Etc  etc...

}
}

Writen on smartphone, check spelling

First acquire input in numerical mode

Then check if changed
Then ma ke action Only if changed