# Raspberry Pi Zero - PWM & Python Help

Disclaimer: I am very new to electrical engineering, but I'm determined to figure this project out.

I'm currently working on electronic solenoid lock. Here's a image of what I have so far.

I have a Raspberry Pi Zero and I'm attempting to use PWM to switch between 0V, 6V or 12V. The lock remains open at 6v, it pops open at 12v and stays locked with no power.

I've read up on Duty Cycle and Frequency and I know how to set that in Python, but I can't figure out what duty cycle % and frequency I need for each of the three states.

For example I'm setting the duty cycle at 100 and frequency at 50 to simulate 12V by doing this:

p = GPIO.PWM(12, 50)
p.start(100)


And then basically doing the same thing for when I want to simulate 6V:

p = GPIO.PWM(12, 50)
p.start(50)


Is this the correct way to do this? Also how would I simulate 0V? Any other advice is welcome, I have no idea what I'm doing :P Thanks!

• Welcome to EE.SE. Can you replace the Fritzing wiring diagram with the Fritzing circuit schematic? There should be an option to show one. The schematic shows us the "scheme" of things and from that we can see how it should work. Your wiring diagram doesn't and we have no idea what the pins on the transistor-looking device are doing. You're missing a protection diode across the solenoid. Your post doesn't say whether it works at all yet. Does it? Again, put all the info in the question rather than in the comments. Oct 16, 2018 at 20:30
• I can change the image to an actual picture of the project while I figure out how to do the schematic in Fritzing. Oct 16, 2018 at 20:58
• The real schematics symbols part numbers and wires. Oct 16, 2018 at 21:57

p.start(0);


or if it is already started:

p.ChangeDutyCycle(0)


Provide the real schematics not the pictures. If you control it on the low side you will need also the resistor from the gate to the Gnd to discharge the gate.

• Do we know it's a MOSFET? Oct 16, 2018 at 21:37
• I am guessing . Oct 16, 2018 at 21:55
• Correct it's a MOSFET Oct 17, 2018 at 2:10