0
\$\begingroup\$

I have a 12 V KCD3 unipolar switch with a LED inside. It is wired as per manufacturer specification, pin2 powers the load when switch is ON, pin 3 provides GND for LED.

I would like to read its state, ON or OFF. So the best thing I could think of is a voltage divider such that when it is ON it should output around 5 V to ATmega328P digital pin 6.

However, when it is off I read a voltage divider output voltage different from 0. I happened to read around 2.6 V, and similar voltages trigger the HIGH state of the digital pin even if the switch is OFF.
I can't explain why this happens. I assumed that when the switch is OFF I should read 0 V since the pull-down resistors are tied to GND.

Possible reasons I could think of:

  1. digital pin sinks/sources current
  2. defective switch
  3. short circuit somewhere in the engraved PCB (although there doesn't appear to be one)

What do you think?

Unipolar Switch with LED tied to voltage divider

EDIT:I add an image of the entire circuit. The switch controls a heater circuit. Independent switch-heater system

EDIT2: I add an image of the switch connections supplied by the sellerenter image description here

\$\endgroup\$
4
  • 1
    \$\begingroup\$ If you measure from the load side, can it leak from the load somehow? What is the load and does it have connections to other powered circuits? How do you initialize the IO pin for reading, do you use a pull-up? \$\endgroup\$
    – Justme
    Nov 27, 2022 at 11:54
  • \$\begingroup\$ @Justme I added another image of the circuit to the post and marked the relevant parts. The right part is a NPN transistor-MOSFET system controlled by digital pin 5, and controls the ON-OFF powering of a heater element. When the switch is "ON", ATmega328P signals software side to power the heater. As you see, switch circuit and load circuit are independent: I don't think there is the possibility of a leak from the load line. However GND is common to all the circuit and carried through a ground plane. 12V supply powers everything, including ATmega328P through an L7805. \$\endgroup\$
    – Gianf DS
    Nov 27, 2022 at 16:23
  • \$\begingroup\$ @Justme the pin is initialized as const int PinHeatSW=6; pinMode(PinHeatSW,INPUT); Therefore no pullup setting I guess \$\endgroup\$
    – Gianf DS
    Nov 27, 2022 at 16:23
  • \$\begingroup\$ @Justme I tested the circuit another time. There's something strange because with switch OFF I read 0,8 V between switch pin 2 and ground(the circuit performs correctly for some minutes although I would expect 0V). Then there is a build up of 2,6-2,9 V all of a sudden and without my intervention. Pretty strange. \$\endgroup\$
    – Gianf DS
    Nov 27, 2022 at 17:25

1 Answer 1

1
\$\begingroup\$

The current is too high to be an internal pullup.

I suspect you've got the switch wired incorrectly. Typically the center connection, typically pin 2 goes to +12, pin 1 to your switched output and pin 3 to GND for the illumination. Switch makers often don't show the internal schematics, so it's easy to mix it up.

From a C&K catalog.

enter image description here

\$\endgroup\$
8
  • \$\begingroup\$ I added an image of the entire circuit and of the switch. The switch seems wired correctly according to seller indication in the image. I am going to try inverting pin 1 and 2. Who knows. This circuit went through quite a bit of testing and errors so I don't know if the ATmega328 came out damaged from it. \$\endgroup\$
    – Gianf DS
    Nov 27, 2022 at 16:34
  • \$\begingroup\$ I tested the circuit another time. There's something strange because with switch OFF I read 0,8 V between switch pin 2 and ground(the circuit performs correctly for some minutes altough I would expect 0V). Then there is a build up of 2,6-2,9 V all of a sudden and without my intervention. Pretty strange. \$\endgroup\$
    – Gianf DS
    Nov 27, 2022 at 17:24
  • \$\begingroup\$ Did you solder the board yourself? \$\endgroup\$ Nov 27, 2022 at 18:20
  • 1
    \$\begingroup\$ @GianfDS I guess stray particles or shards of copper are a possibility then. Have to ask though, any chance the solder was not electronic grade? \$\endgroup\$ Nov 27, 2022 at 18:29
  • 1
    \$\begingroup\$ @GianfDS Solder is probably fine. \$\endgroup\$ Nov 27, 2022 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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