rajbuddy007
Posts: 53
Joined: Fri Apr 05, 2019 3:03 pm

RPi for button presser

Tue May 07, 2019 3:08 pm

Hello Guys,

I am making a button presser for that i made a circuit and wrote some code. Its not working. Could you please help me out?
I am using 5V push pull Solenoid. I wrote some code but its not happening.

Code: Select all


# set GPIO pin numbering method to BCM

import time
from time import sleep
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)

PIN = 3
GPIO.setup(PIN, GPIO.OUT)


while(1):

    GPIO.setup(PIN, GPIO.HIGH)
    time.sleep
    GPIO.setup(PIN, GPIO.LOW)
    time.sleep

GPIO.cleanup()



pcmanbob
Posts: 6409
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: RPi for button presser

Tue May 07, 2019 3:19 pm

You have not said how you connected the 5V push pull Solenoid to your pi.

You can't connect it directly to the 3.3v gpio pins and expect it to work, for a start its 5V not 3.3V which is what the gpio outputs but more importantly the 5V push pull Solenoid will draw upwards or 1A were as the gpio can only supply 16mA maximum current.

So you will need a driver/interface circuit between the pi gpio and the 5V push pull Solenoid.

If you know how you can build your own using transistors or you could use a motor driver board it you want some thing ready made.

and finally looking at your code

Code: Select all


import time
from time import sleep

    GPIO.setup(PIN, GPIO.HIGH)
    time.sleep
    GPIO.setup(PIN, GPIO.LOW)
    time.sleep

as you have imported sleep from time then you lines should be sleep not time.sleep and also you need to specify the time to sleep for.

Code: Select all


import time
from time import sleep

    GPIO.setup(PIN, GPIO.HIGH)
    sleep(1)
    GPIO.setup(PIN, GPIO.LOW)
    sleep(1)

We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

rajbuddy007
Posts: 53
Joined: Fri Apr 05, 2019 3:03 pm

Re: RPi for button presser

Tue May 07, 2019 3:29 pm

Image

This is the circuit diagram I have made. I am using diode rectifier of 1A 50V and N channel MOSFET of 60V 30A.
What should I change??
Attachments
Capture.PNG
circuit diagram
Capture.PNG (95.11 KiB) Viewed 777 times

pcmanbob
Posts: 6409
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: RPi for button presser

Tue May 07, 2019 9:31 pm

So did you try making the changes to the code to see if that made your solenoid work ?

I have no idea what needs changing on your circuit as I don't know what transistor you are using.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

pfletch101
Posts: 480
Joined: Sat Feb 24, 2018 4:09 am
Location: Illinois, USA

Re: RPi for button presser

Tue May 07, 2019 10:22 pm

It looks as if your only source of power is the 5V supply from the Pi's GPIO. That is still (at the very least) not ideal for a solenoid. If the rest of your wiring is correct (difficult to tell from the picture), I am a bit surprised that the Pi is not rebooting as a result of the power drain when it is energized!

rajbuddy007
Posts: 53
Joined: Fri Apr 05, 2019 3:03 pm

Re: RPi for button presser

Wed May 08, 2019 7:10 am

pcmanbob wrote:
Tue May 07, 2019 9:31 pm
So did you try making the changes to the code to see if that made your solenoid work ?

I have no idea what needs changing on your circuit as I don't know what transistor you are using.
I am not using any transistor i just used N channel mosfet along with diode rectifier and drain current limit i used 100KR.
Coulld u please guide me in that??

pcmanbob
Posts: 6409
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: RPi for button presser

Wed May 08, 2019 9:08 am

rajbuddy007 wrote:
Wed May 08, 2019 7:10 am

I am not using any transistor i just used N channel mosfet
metal–oxide–semiconductor field-effect transistor (MOSFET, MOS-FET, or MOS FET)

https://en.wikipedia.org/wiki/MOSFET

and we still don't know which one you are using.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported


rajbuddy007
Posts: 53
Joined: Fri Apr 05, 2019 3:03 pm

Re: RPi for button presser

Wed May 08, 2019 11:59 am

This is the schematic of my RPi where i am using 5V as a Vcc from RPi.
Attachments
Capture1.PNG
Capture1.PNG (8.73 KiB) Viewed 658 times

PiGraham
Posts: 3567
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: RPi for button presser

Wed May 08, 2019 12:14 pm

rajbuddy007 wrote:
Tue May 07, 2019 3:08 pm
Hello Guys,

I am making a button presser for that i made a circuit and wrote some code. Its not working. Could you please help me out?
I am using 5V push pull Solenoid. I wrote some code but its not happening.

What's not happening?

What sort of buttons do you hope to push? A lot of solenoids on the market as 5V don't provide much force.

You could get a lot more push from a little 9g RC servo.


https://hackaday.com/2017/03/14/zero-in ... ht-switch/


The FET you have chosen is specified (datasheet linked on the page you linked) as having a gate threshold voltage of between 2 to 4 V. The GPIO output maximum is 3.3V so the FET is not guaranteed to turn on.


Does the solenoid move at all?


If you disconnect the gate pin wire from the GPIO output pin and connect it instead to a 3.3V pin what happens? Try the 5V pin. Does that work?

PiGraham
Posts: 3567
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: RPi for button presser

Wed May 08, 2019 12:18 pm

rajbuddy007 wrote:
Wed May 08, 2019 11:59 am
This is the schematic of my RPi where i am using 5V as a Vcc from RPi.

You have the diode the wrong way round. You put a diode across a coil reverse polarity to short out the back EMF that is generated when the coil turns off. The way you have shown it the diode will conduct if the FET turns on and no current will flow through the coil because it will go through the diode instead.

User avatar
davidcoton
Posts: 3940
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: RPi for button presser

Wed May 08, 2019 12:19 pm

The diode is shown the wrong way round in the circuit diagram -- it is there to remove the reverse voltage generated when the solenoid is turned off and the magnetic field collapses. The layout in an earlier post shows it the other way round, which is correct. If it is (or, at any time, was) actually connected wrongly when the GPIO was switched high, the MOSFET will possibly be dead. Possibly not, since the supply is unlikely to exceed 30A. Please check the diode polarity.

[Beaten to it, but left because there is extra info here.]
Last edited by davidcoton on Wed May 08, 2019 12:21 pm, edited 1 time in total.
Signature retired

PiGraham
Posts: 3567
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: RPi for button presser

Wed May 08, 2019 12:20 pm

You describe the solenoid as "push pull" but only show a single coil and a single sided drive so it can't puseh and pull, can it? Do you mean a spring return solenoid?

rajbuddy007
Posts: 53
Joined: Fri Apr 05, 2019 3:03 pm

Re: RPi for button presser

Wed May 08, 2019 1:54 pm


rajbuddy007
Posts: 53
Joined: Fri Apr 05, 2019 3:03 pm

Re: RPi for button presser

Wed May 08, 2019 2:04 pm

Sorry in the schematics the diode was wrongly placed but the circuit i made is still right and not working.

rajbuddy007
Posts: 53
Joined: Fri Apr 05, 2019 3:03 pm

Re: RPi for button presser

Wed May 08, 2019 2:05 pm

PiGraham wrote:
Wed May 08, 2019 12:14 pm
rajbuddy007 wrote:
Tue May 07, 2019 3:08 pm
Hello Guys,

I am making a button presser for that i made a circuit and wrote some code. Its not working. Could you please help me out?
I am using 5V push pull Solenoid. I wrote some code but its not happening.

What's not happening?

What sort of buttons do you hope to push? A lot of solenoids on the market as 5V don't provide much force.

You could get a lot more push from a little 9g RC servo.


https://hackaday.com/2017/03/14/zero-in ... ht-switch/


The FET you have chosen is specified (datasheet linked on the page you linked) as having a gate threshold voltage of between 2 to 4 V. The GPIO output maximum is 3.3V so the FET is not guaranteed to turn on.


Does the solenoid move at all?


If you disconnect the gate pin wire from the GPIO output pin and connect it instead to a 3.3V pin what happens? Try the 5V pin. Does that work?
It is a very small button on a pcb thats why i have gone for a small voltage solenoid.

rajbuddy007
Posts: 53
Joined: Fri Apr 05, 2019 3:03 pm

Re: RPi for button presser

Thu May 16, 2019 8:40 am

hello guys,

New update in this. O have changed my mosfet with logic level mosfet. The circuit got worked. But the solenoid heated up so badly. What should i do to my circuit if want to give 12V external supply?

MarkTF
Posts: 295
Joined: Tue Mar 03, 2015 4:59 pm

Re: RPi for button presser

Thu May 16, 2019 12:43 pm

rajbuddy007 wrote:
Tue May 07, 2019 3:08 pm
. . . I am using 5V push pull Solenoid. . . .
rajbuddy007 wrote:
Thu May 16, 2019 8:40 am
New update in this. O have changed my mosfet with logic level mosfet. The circuit got worked. But the solenoid heated up so badly. What should i do to my circuit if want to give 12V external supply?
The obvious solution would be to use a solenoid rated for 12 Volts in a 12 Volt circuit.

PiGraham
Posts: 3567
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: RPi for button presser

Sun May 19, 2019 11:13 am

rajbuddy007 wrote:
Thu May 16, 2019 8:40 am
hello guys,

New update in this. O have changed my mosfet with logic level mosfet. The circuit got worked. But the solenoid heated up so badly. What should i do to my circuit if want to give 12V external supply?
The obvious answer is to use appropriately rated components, so use a 12V solenoid, if you are still using the 5V type.
But even then coils can get hot if powered on continuously.
There are latching solenoids that hold in one of two positions without power. You only apply power to change the position.

The current required to move a solenoid is less that the current required to hold it in position so you could try controlling the MOSFET with a PWM signal. To activate use 100% and to hold change the duty cycle to some lesser value, say 40%. You would have to experiment.

Another option could be to use two switching devices (e.g. "high side switch" FETs) one switching 12V and another switching 5V. Activate the high voltage to pull in the olenoid then activate the lower voltage and release the higher to hold the position.
Be very careful here with the circuit. You must not connect two different supply voltages together.

mopa6700
Posts: 1
Joined: Sun May 19, 2019 8:24 pm

Re: RPi for button presser

Sun May 19, 2019 8:26 pm

PiGraham wrote:
Sun May 19, 2019 11:13 am
rajbuddy007 wrote:
Thu May 16, 2019 8:40 am
hello guys,

New update in this. O have changed my mosfet with logic level mosfet. The circuit got worked. But the solenoid heated up so badly. What should i do to my circuit if want to give 12V external supply?
The obvious answer is to use appropriately rated components, so use a 12V solenoid, if you are still using the 5V type.
But even then coils can get hot if powered on continuously.
There are latching solenoids that hold in one of two positions without power. You only apply power to change the position.

The current required to move a solenoid is less that the current required to hold it in position so you could try controlling the MOSFET with a PWM signal. To activate use 100% and to hold change the duty cycle to some lesser value, say 40%. You would have to experiment.

Another option could be to use two switching devices (e.g. "high side switch" FETs) one switching 12V and another switching 5V. Activate the high voltage to pull in the olenoid then activate the lower voltage and release the higher to hold the position.
Be very careful here with the circuit. You must not connect two different supply voltages together.
This is the circuit diagram I have made. I am using diode rectifier of 1A 50V and N channel MOSFET of 60V 30A.
What should I change??

Return to “General discussion”