You’re reading the pin before you configure it as analog in.
You’re assuming that off is exactly zero. This is very unlikely.
You’re actually not reading the pin, you’re reading the voltage the imp is running at
You probably want this:
`imp.configure(“voltage reader”, [], []);
hardware.pin5.configure(ANALOG_IN);
function checkpin5() {
local v = (hardware.pin5.read() / 65535) * hardware.voltage();
server.log(format(“pin5 is at %.2f volts”, v));
if (v > 1.0) server.show(“on”); else server.show(“off”);
imp.wakeup(0.5, checkpin5);
}
checkpin5();
`
…note also that LEDs can be turned on and off two ways. One is to turn the power pin (anode) on and off, the other is to connect or disconnect the ground pin (cathode: this is more common). You need to determine, likely with a voltmeter, which method is in use.
If the system is grounding the anode to turn the LED on, then the voltage you read will be near zero… but this also depends on where the current limiting resistor is in the circuit…