Why is the relay connected to analog pin 12? Analog pins are input only. You can't perform a digitalRead on an analog pin.