Using a IR obstacle avoidance sensor to operate a common cathode red/green LED.

Hello, I would like to set up the above so that the green element of the LED stays lit unless the sensor reads an obstacle in its path then activates the green to go off and red to illuminate. As a newbie I thought it would not be that difficult but I seem to be stuck and would be grateful for ideas ( including code ) please.

Thanks,
Nick H.

It is customary to show what you've got so far, what it's doing wrong and what it should be doing. Schematics are helpful, too.

Hint:we don't know which sensor you have.

As a newbie I thought it would not be that difficult

It may amuse you that there is an official name for that common misconception: the Dunning-Kruger effect.

We recommend starting with the examples provided by the Arduino program development software. Learn to blink an LED without using delay(), read a voltage or a sensor, learn the special features of Arduino, etc. That way you avoid mountains of frustration.

PS: the U.S. is currently suffering from the Dunning-Kruger effect operating at the very highest levels.