electronics is really not my field so I am asking for help.
I want to turn on and off my pc via an esp8266 and a few octocouplers. This I got working following some examples on the internet. No problem here so far.
But I also want to check if my PC is on or off via the power led.
I found that there was made a video from the hookup guy with this schematic:
Would that ESPHome code be right for the binary sensor?
Because for me this does not work in my current breadboard setup (might have missed something though).
The way the circuit is drawn, when the power LED is on the opto will deliverer 3.3V to D0. When the power LED is off there will be no connection to D0. So when the LED is off the input will be ‘floating’. This is not good, floating inputs can be subject to noise and switch on / off randomly.
If you use mode: INPUT_PULLUP the input will be pulled ‘up’ to 3.3v by an internal resistor, so now you have 3.3v whether the LED is on or off. So it will always register as on.
You need a way to pull the GPIO down to ground when the LED is off, ie. use mode: INPUT_PULLDOWN not mode: INPUT_PULLUP.
This way the when the power LED is on the opto will deliverer 3.3V to D0. When the power LED is off the input will be pulled to ground.
Also the circuit is drawn with D5 controlling the power switch, yet you have used D7 in your switch code. Either wire the power switch opto to D7 or change your code to use D5.
Also you are using D8 for the reset switch (not shown in the drawing). This is not the best pin to use for outputs. See the table lower down on this page for the best pins to use:
The sensor is off when no connection is happening. When I connect the cables of 3.3V and D0 the sensor turns on. When I release it turns off. Also pretty fast.
So I guess that part works.
Now when I connect
3.3V to the Collector and
D0 to the emitter
The binary sensor is off like (LED circuit not connected yet.)
But somehow I can not get it to work with the led circuit.
My brain is not able to figure out how to connect the anode and cathode to the existing led circuit.