I read already this 2 questions:

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>
#include "Adafruit_MCP23017.h"

Adafruit_MCP23017 mcp;

int value = 0;
int total = 0;

void setup() { 

  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++) {
    value =  mcp.digitalRead(a);
    total += value;

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?

  • 3
    \$\begingroup\$ 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. \$\endgroup\$ – Peter Bennett Jul 20 '18 at 2:41

As mentioned by Peter, you measuring inputs are all connected to ground. You could do something like this


simulate this circuit – Schematic created using CircuitLab

This way you measure 660mV when the active LED is draining 20mA. By the way, 33R seems to be quite small, you may wanna doublecheck the effective forward voltage of your LEDs.

  • \$\begingroup\$ Thank you @Humpawumpa for the answer. and you're correct. that's what I wanted. Also I punch in the numbers in led.linear1.org/led.wiz .... I got adafruit.com/product/754 3.0V forward current and 20mA, makes more sense to have all 150Ohms. So I'll do that. Thanks \$\endgroup\$ – nicocesar Jul 20 '18 at 21:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.