"If" statement and LEDs not working correctly

Does the external component have a common GND with the Arduino ?