-1

I want to know with the raspberry pi if the button is clicked.
I want ot use the button of the GPIOZERO python library.
The power plug is a 12v power plug.
Can this circuit work?
(I'm a beginner.)
Thanks

My Circuit

7
  • 2
    You need a voltage divider. – Ole Wolf Sep 30 '20 at 14:16
  • Can I use resistor instead ? I add it on the sheme. – PacCol Sep 30 '20 at 14:39
  • 5
    PacCol, not to be rude, but did you investigate what voltage divider means? It involves a resistor (or two, actually). – goldilocks Sep 30 '20 at 14:54
  • Yes I looked on Wikipedia but I don't see how to use it... I will do further research. – PacCol Sep 30 '20 at 15:07
  • 2
    Unless you have a common Gnd you DO NOT have a circuit so it will probably do nothing. If it did you would have destroyed the Pi. You have been warned. – Milliways Sep 30 '20 at 22:48
2

When the button is pressed the red side of the button will be at 0V. But when the button is released it will go to 12V and fry your RPi. Also 0V for the power plug can differ from 0V for the RPi. If they differ too much that fries the RPI as well.

So first thing you have to fix is to connect the GND of the power plug and RPi so they both agree what 0V is.

Next you need a voltage divider (just 2 large resistors in series) going from the red side of the button to GND. Picking the right resistors you would get a 3.3V signal in between the two resistors and you can connect that to a GPIO pin. But that would also create a leak across the button. A small current would flow even with the button off. So not really the best solution.

A better solution would be to add an octocoupler in series with the button. Adjust the resistor and/or diode in the circuit to offset the voltage loss through the octocoupler. The other side of the octocoupler is then connected to GND and a GPIO pin and the GPIO pin is set to input with pullup.

5
  • Like this ? Circuit --> inventions.ovh/circuit.jpg – PacCol Sep 30 '20 at 16:01
  • 1
    Except for all the resistors being the same that looks right. But I really recommend using an occtocoupler. – Goswin von Brederlow Sep 30 '20 at 16:08
  • How can I choose the resistors ? – PacCol Sep 30 '20 at 16:14
  • 1
    The ratio between the two resistors determines the voltage in the middle. And to reduce the current flow you want large resistors. To get 3V you need a 1:3 ratio, e.g. 100kOhm + 300kOhm. Doesn't have to be exact. 100kOhm + 260kOhm for example will give you 3.3V. The formula is 12 / (X1 + X2) * X1 and anything between 3V and 3.3V would be perfect. MEASURE the voltage before you connect the Raspberry Pi. If you swap the two resistors you will get 9V. If you picked the wrong ones you might get anything between 0V and 12V. – Goswin von Brederlow Sep 30 '20 at 16:25
  • Thanks for your help ! – PacCol Sep 30 '20 at 16:28

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.