# Read the state from an LED in a MCP23017

Read state from LED in another circuit

Read the state of a 12v illuminated switch from an Arduino Uno

and I can read the state in a MCP23017 controlled by an NodeMCU V1

I have the following circuit:

simulate this circuit – Schematic created using CircuitLab

And I need to get a reading of a 1 or a 0 for each LED that its ON or OFF , This is my code:

#include <Wire.h>

int value = 0;
int total = 0;

void setup() {
mcp.begin(0,D2,D1);

for (int a = 0 ; a <= 15; a++) {
mcp.pinMode(a, INPUT);
mcp.pullUp(a, LOW);  // 100K pullup internally <- I tried commenting it out and changing it to HIGH
}

}

void loop() {
total = 0;
for (int a = 0 ; a <= 15; a++) {
Serial.print(value);
total += value;
}
Serial.println();
Serial.println(total);
delay(200);
}


All I get is either: LED on and off but the reading is 0 (or 1 if I use the pullup option) or I get the LED light but the reading is always 0.

Is there any difference on having an arduinio or nodeMCU directly or is there something I need to do to make it work?

• As I read your schematic, all the inputs to the MCP23017 are connected to Ground, so should read Zero/Low regardless of the state of the LEDs. – Peter Bennett Jul 20 '18 at 2:41