comet424
Posts: 51
Joined: Fri Jan 03, 2020 11:42 pm

whats best way to control relays by button

Sat Jan 11, 2020 11:18 pm

hi I working on buiding a timer

I using CronTab to run a On and then and Off script

but I wanna add a either a Toggle Switch... 3 positions for the 1 Relay... ON/AUTO/OFF so when on it turns relay on.. Set to AUTO It goes back to Crontab scripts and OFF turns off the relay even when Crontab says to run.

or I wanted a Single Button... so when pi boots up goes to last postion you set the Button.. but Button be ON OFF AUTO and then 3 LEDS corresponding ON OFF AUTO... so when you press Button once It would be ON and say RED led.. press button again OFF and Yellow LED lights then and press it one more time goes to AUTO and Blue LED comes on..

I have looked at different codes and one with the GPIO Zero PI library

but with what I trying to do what would be my best route.. is there any sample codes links you guys could point me to..

as right now works fine doing cron tab running and then off... but just looking to add a button

emma1997
Posts: 774
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: whats best way to control relays by button

Sun Jan 12, 2020 12:42 am

comet424 wrote:
Sat Jan 11, 2020 11:18 pm
I wanna add a either a Toggle Switch... 3 positions for the 1 Relay... ON/AUTO/OFF so when on it turns relay on.. Set to AUTO It goes back to Crontab scripts and OFF turns off the relay even when Crontab says to run.
No code for that. Just on-off-on toggle switch. Five minute job. Obviously the 'best' way.

The other complicated scheme does need software and probably take days or weeks to implement even if familiar with Pi programming.

LTolledo
Posts: 3321
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: whats best way to control relays by button

Sun Jan 12, 2020 1:21 am

yep definitely a on-off-on toggle switch is up for the job (preferably a 2-gang type toggle switch)

another is a two-gang 3-position rotary switch (the other side wired for the LED indicators)

the only software required..... creative thinking... :mrgreen:

if you really want/insist a "software assisted solution with indications"
then you'll need a few more GPIOs for that:
1 GPIO for push button input ( you'll have to be creative with the toggling and state memory coding)
1 GPIO for relay to control the other original GPIO controlled by crontab
3 GPIOs for the indicator lights
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

comet424
Posts: 51
Joined: Fri Jan 03, 2020 11:42 pm

Re: whats best way to control relays by button

Sun Jan 12, 2020 4:07 am

ah ok ill probably got the simple route then a 3 way switch

oh and is there a simulator to try and draw up the wiring to a switch so I know how I want it wired before I wire it

for Arduino I played with the tinkercad and Arduino sketch but is there one for raspberry pi I tried googling never found anything except one sample for Microsoft azures thing … but not like the tinkercad..

if there is anything if not ill work on it hands on I just wanted to see if I could draw it online

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

Re: whats best way to control relays by button

Sun Jan 12, 2020 1:15 pm

So the first thing is which version of a DPDT on-on-on toggle switch are you using .

there are 6 pin and 8 pin versions and there are at least 2 type of the 6 pin version that connects different pins.

it would be much easier if you had it on - off - auto as the common 3 way switch has the on - off - on output.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

comet424
Posts: 51
Joined: Fri Jan 03, 2020 11:42 pm

Re: whats best way to control relays by button

Sun Jan 12, 2020 4:37 pm

hi
ya that's what I have a On Off ON.. I have 2 types 3 and 6 pin toggle switches... didn't know there is a 8 pin


and as for simulator software I guess there is no real raspberry pi simulator where you can slide your devices over put the software in and run it

not like arudino tinkercad I played with was nice

you just have to know your electronics (:

its pretty cool this Arduino/ raspberry pi projects wish they were around when was a kid in 80s 90s
could built some really cool stuff lol

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

Re: whats best way to control relays by button

Sun Jan 12, 2020 6:05 pm

No that hard to wire using your single pole on - off - no switch ( 3 pin one )

Image

so in mid position every thing is disconnected so off

in one on position you connect the gpio to the relay = auto

in the other on position you connect the 3.3v pin to the relay = manual on

this is assuming you are active high for relay activation, if you relay board is active low then you just need to add a transistor / resistor interface to make it active high, as most 5v relay boards that are active low don't work well with the 3.3v gpio.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

comet424
Posts: 51
Joined: Fri Jan 03, 2020 11:42 pm

Re: whats best way to control relays by button

Sun Jan 12, 2020 8:47 pm

ah ok ya that's how I was thinking to make it 3 pos

and how do you know which relay you have.. the one I ordered is
https://www.amazon.ca/gp/product/B07JYD ... UTF8&psc=1

so since I new to raspberry/Arduino stuff haven't done much electronics in 20 yrs

I had couple extra questions the reason for the transistor what does it do for the raspberry pie?
and I got told in another post I was doing they said read the beginners guide for relays transistors

now im a visual learner so reading doesn't always help me.. I have to see something done.. im a hands on builder... what does the transistor acutally do for the circuit? is it acting like a capictor and bumping the voltage from 3.3 to 5 volts? whats happening in the circuit...
and I I read you want to add a LED to the circuit you need a resistor but different articles say different resisotrs isn't there just one size you need.. as they stated in the one article... the LED wants to draw as much current as it can and burns out your raspberry pi. but I seen for ardunio no resister needed.. I guess the built a bit different?

sorry if I sound stupid I learning as I go and its first time I even dabbled with raspberry pi bought the first one ever raspberry pi 4 2gb 2 weeks ago. so very new as I wanted to make that retropie but doesn't work for pi4... so I been playing with other projects

its very cool though (:

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

Re: whats best way to control relays by button

Sun Jan 12, 2020 9:51 pm

Well it's clearly designed for the Arduino and 5V operation, but I have not seen that particular one,
So I don't know if it's active low or active high.

You will probably ha e to test it yourself once it arrives.

The idea of the transistor is to switch the ground for the 5V operating circuit on the relay board so keeping the 5V away from the gpio which is not 5V tolerant.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

comet424
Posts: 51
Joined: Fri Jan 03, 2020 11:42 pm

Re: whats best way to control relays by button

Sun Jan 12, 2020 11:16 pm

ah ok I contacted the company that makes that relay as there page says for raspberry pi but tech support English so bad I couldn't understand all I got out of it was yes works for raspberry


as for the transistor so does that mean instead of 5 volts going to the Input wire on the relay it would send GND connection instead and the GPIO just activates the transistor.. and are each GPIO 3.3 volts?

if I understood what you ment

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

Re: whats best way to control relays by button

Mon Jan 13, 2020 11:42 am

Having a closer look at the link to the relay you have purchased it looks like it is active high, as it has 2 grounds

so you have
VCC = 5v
GND = ground
IN = control input
SGND = sdignal ground which is jumped to GND

So you might find that connecting a gpio output to the IN pin and driving it high will turn on the relay , but as its designed to be used with the arduino it might find that you need to drive the IN pin with 5v because of the resistors used in the opto isolator input circuit which might also include an LED, its hard to tell from a picture.

Which is why I said you would need to test it , if you do find it need 5v on the IN pin to activate the relay, then there are several ways we can do it ,

1. use a NPN - PNP transistor driver circuit to actually provide 5v to the IN pin.

2. connect 5V directly to the in pin , remove the jumper from SGND-GUD and use a single NPN transistor to switch the GND

but you need to actually test it first to see if it works in the way I have suggested.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

comet424
Posts: 51
Joined: Fri Jan 03, 2020 11:42 pm

Re: whats best way to control relays by button

Mon Jan 13, 2020 1:06 pm

ah ok ya that's fine we will see when it comes hopefully end of this week maybe next.. no 2 day shipping from china lol

is there a certain transitor you need.. so basically the transistor I guessing is like a Relay... you need a 5v source then wire goes to the input side and its powered by 3.3v

but ill re look google it how it works.. I appreciate it... and hopefully I don't need to less modifications the better lol (:

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

Re: whats best way to control relays by button

Mon Jan 13, 2020 1:16 pm

Once you know how the relay works from the testing then we can decide if you need to add any transistors at that point we can select the appropriate one for the job, till then supplying possibles transistor numbers will only lead to confusion later.

The simple explanation of a transistor is its just a switch which you can turn on using a small voltage/current to allow a bigger voltage/current to flow.

https://www.explainthatstuff.com/howtra ... swork.html
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

comet424
Posts: 51
Joined: Fri Jan 03, 2020 11:42 pm

Re: whats best way to control relays by button

Mon Jan 13, 2020 1:20 pm

I guess transistor is both it can be a relay or it can amplifiy the 3vs to 5 volts
wonder if it can amplifiy amps too have a relay solid states 3v to 32v 3.2amps at 24v cant drive it I guessing needs 5 10 amps can transistors amplify amps too or just volts

comet424
Posts: 51
Joined: Fri Jan 03, 2020 11:42 pm

Re: whats best way to control relays by button

Mon Jan 13, 2020 1:23 pm

ah nice I just reading this article too I googled before you sent it … (:
and ya tha works if I don't need I don't need...

my other project I was working on was converting a APC UPS has 12volts on the network jack.. and I was trying to trip a relay...when it powers as it only puts power to it when it goes on battery... would a transistor help me in that way would you know? to drive a relay but to do amperate not current..

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

Re: whats best way to control relays by button

Mon Jan 13, 2020 1:31 pm

comet424 wrote:
Mon Jan 13, 2020 1:23 pm

my other project I was working on was converting a APC UPS has 12volts on the network jack.. and I was trying to trip a relay...when it powers as it only puts power to it when it goes on battery... would a transistor help me in that way would you know? to drive a relay but to do amperate not current..
You would need to know how much current that 12V output can supply, it may just be a 12V signal with just a few mA of current available, if that is the case then you may be able to use it to drive the base of a transistor to activate a relay.

without knowing a lot more about the output and it uses/capabilities its impossible to say how it might be used.

you should also be aware that it is probably not a network jack for connecting to a LAN/network but is just using the same type of socket as one.

As its not pi related probably not a topic for discussion on this forum..
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

comet424
Posts: 51
Joined: Fri Jan 03, 2020 11:42 pm

Re: whats best way to control relays by button

Mon Jan 13, 2020 1:38 pm

ah ok no I just figured id ask since you mentioned about transistors tranistor page.. and I was reading how it amplifiys… ya its not a regular network jack its 10 pin where network is 8 I just used it as a visual... and ya the 12volts is milliamps less the 300ma but I guess id need 5000ma but I dunno if a transistor can do that

and no worries I was only asking.. I realize raspberry pi it only popped in my head about the amplifying part in the transistor.. sorry about that

comet424
Posts: 51
Joined: Fri Jan 03, 2020 11:42 pm

Re: whats best way to control relays by button

Mon Jan 13, 2020 1:58 pm

see I bougth this relay orginally for the raspberry pi
https://www.amazon.ca/Twidec-Output-Sin ... ljaz10cnVl

as I couldn't find a 15amp relay for raspberry pi... but this relay im guessing 5 to 10amps it takes to draw it... as it works 12volts directly to a car battery to drive it...
but I ordered the ones I sent above and I just gonna return these... but I figured it was good for raspberry pi as it starts off at 3v
but I don't think 1 transistor can amplify amps from raspberry GPIO to 5 or 10 amps to drive this... would you need multiple ones? if I do I just gonna return it.. but it was my orginal idea then I moved it to my other project and it didn't work..

but ya orginal project was the raspberry I wanted to drive that puppy... but I was thinking either I need lke 20 transistors to amplify GPIO to 5 to 10 amps probably in parral..
or my other idea was a smaller relay powers the 2nd relay to get the higher amperage really..

but I appreciate the help and input …. now to wait for the new relays to come in and test it with the pi... (:
thank you I really enjoy the help you provided (:

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

Re: whats best way to control relays by button

Mon Jan 13, 2020 2:15 pm

Yes you may be able to drive that solid state relay from the 3.3v of the gpio , but it depends on a quality of the produce , some of the cheaper examples will only work correctly when drive from 5v minimum, they normally only require a few mA on the control side to switch on.

you should also note it will only switch AC voltages between 24 - 480V on the output.


Were are you getting this " but this relay im guessing 5 to 10amps it takes to draw it " from ?
5 to 10 A sounds more like the rating on the contacts.

A relay coil would normally draw well under 1A ,

for example this relay with a 5v coil would draw about 90mA ( 0.09A ) to switch the relay on

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

comet424
Posts: 51
Joined: Fri Jan 03, 2020 11:42 pm

Re: whats best way to control relays by button

Mon Jan 13, 2020 3:56 pm

ah ok
ya no the amps I ment is for activating
sorry my dyslexia I don't explain things better

what I was doing was wanting it for my 3/4 hp well pump to come on when the raspberry tells it to
so I chose this relay as its good for 40 amps and can handle 120volts AC

and I chose the relay because it could activate at 3volts so should be good for the raspberry

but what it does it just lights up the LED on the relay a little and makes it buzz
I tried
power adapters
3-12volt changed adapter
9v 300ma
19v 1000ma
24v 3.2amp
they light the LED up bright on the solid state relay but didn't actually activate.. at 24v 3.2amp I had a LED shop light hooked up as its 120vac and the light was flickering... like the relay was clicking on and off

so if I went directly 12volt battery to power it.. then the the relay worked... reason I guessing it can handle say 3v to32v but needs 5amps or more to draw since 3.2amps kinda worked but was flickering

and I bought it for the raspberry pi but since it couldn't work at the changed adapter or the others I didn't wanna damage pi
as a power adapter easily replaced..

so I never found answers from them how much does a solid state relay draw to activate as 300ma, 1000ma,3.2amp can not drive it.. and I not sure if your transistors can up the amperaged from a GPIO to say 5 or 10amps at 3.3volts to power it... so reason I found the ones I ordered from china.. that I still waiting for...

sorry for miss wording things words work in my head better then I right

comet424
Posts: 51
Joined: Fri Jan 03, 2020 11:42 pm

Re: whats best way to control relays by button

Mon Jan 13, 2020 4:22 pm

and how many milliamps does a gpio put out? does those boards with those little looking resisters on top are those tinny transistors to step up the voltage or amperage..

User avatar
rpdom
Posts: 17029
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: whats best way to control relays by button

Mon Jan 13, 2020 4:33 pm

comet424 wrote:
Mon Jan 13, 2020 4:22 pm
and how many milliamps does a gpio put out? does those boards with those little looking resisters on top are those tinny transistors to step up the voltage or amperage..
A GPIO can source or sink up to 16mA, but it is best to keep that lower.

The transistors on the relay boards require only a few mA to switch the voltage to the relay. They will handle the higher voltage and amperage required.
Unreadable squiggle

comet424
Posts: 51
Joined: Fri Jan 03, 2020 11:42 pm

Re: whats best way to control relays by button

Mon Jan 13, 2020 5:17 pm

ah ok so then then
say if I kept those white solid state relay for future raspiberry pi project as I bought 2 of them

what transistor would I need then to go from 3.3v 16ma to 3.3v 5amps or 10amps and would you use the same transistor for 5v 9v 12v 24v or would there be different transistors..

I only ask for curiosty for the raspberry pi... if I should keep the solid state relays or just return them as id keep it and the ones coming in the mail

boyoh
Posts: 1468
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: whats best way to control relays by button

Mon Jan 13, 2020 8:46 pm

What is holding you back on this project is not
Understanding basic electronics, So a course on
Basic electronics is your next move ,
A starter kit will be very useful .it will tell you
How to use transistors and many other components,

1. Breadboard
2, 0 / 12vdc 3 /4a Adapter
3 Multimeter
4 Components ( Mix)
Book on simple starter circuits and Ohms Law

Do Not Use the Raspberry Pi as your Power Supply

Regards BoyOh
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

comet424
Posts: 51
Joined: Fri Jan 03, 2020 11:42 pm

Re: whats best way to control relays by button

Mon Jan 13, 2020 8:51 pm

ah ok thanks ill look into that

Return to “Beginners”