Hi guys,
I have a project in which I have to open or close a relay depending on the measured voltage. My friend/ teammate has drawn the electric circuit and chosen some compoments. We have a G5Q EL3 power relay working on a voltage of 5V DC. But we don't know what type of signal we need to send to open/close it (because we find it difficult to understand the technical file of the compoment.) First we tought we could open or close the relay by sending a pulse to the NPN transistor, shown in the circuit added to this post, that leads to a ICE of the rated current, given in the technical file of the relay. But in the technical file there's also something about the must operate voltage and must release voltage. So we tought maybe we have to change the voltage over the relais (so we change the circuit we remove the 5V source and connect it to a PWM pin of the arduino). And by changing the duty ratio of the PWM signal we could change the voltage over the relay and maybe close/open it.
But now we're not sure what to do. We don't know which is the right way to open/close the relay and we hope you guys could provide us an answer.
I have added the circuit and the technical file.
Btw in the circuit we have connected wires to the 0 and 1 pin of the arduino but that's a mistake of ours. My teammate didn't know that those aren't PWM pins. (and we have an Arduino uno)
The first thing that I notice is that the circuit uses pins 0 and 1 of the Arduino
This is generally not a good idea because those pins are used for Serial communication including uploading programs to the Arduino. Were they chosen for a particular reason in your project ?
We don't know which is the right way to open/close the relay and we hope you guys could provide us an answer.
As a starting pint, look at the Blink example in the IDE and substitute a 5V relay for the LED but I suggest that you use pin 10 instead of pin 13, which is implied by LED_BUILTIN in the example
If you have the 5V coil version then the simple transistor circuit does the job, ignore all the other specifications,
5V will energize it and 0V will de-energize it.
Except change the base resistor to 220 ohms, people often get this wrong. The diode is
essential, do not omit it, do not get it the wrong way round either(!)
Your circuit is fine, but lose the zener and replace the two resistors with a single 220 ohm
resistor. 220 ohms gives 20mA base current, enough to drive any relay coil upto about 300mA
current.
And finally you don't send a pulse, you energize the circuit for as long as you want the relay
to operate.
UKHeliBob:
The first thing that I notice is that the circuit uses pins 0 and 1 of the Arduino
This is generally not a good idea because those pins are used for Serial communication including uploading programs to the Arduino. Were they chosen for a particular reason in your project ?
The use of the 0 and 1 pin was a mistake of ours. My friend who designed the circuit tought all the digital pins were the same. Later we will use those pins to use serial communication with the ESP32. So you could say that the wires attached to pin 0 and 1 are attached to pin 5 and 6.
UKHeliBob:
As a starting pint, look at the Blink example in the IDE and substitute a 5V relay for the LED but I suggest that you use pin 10 instead of pin 13, which is implied by LED_BUILTIN in the example
The problem is that our university is going to order the compoments in a week or two (and with shipping it will take even longer), so I can't test it yet, because in my starter kit there is no relay.
That's why I was wondering how to open/close the relay, because I can't test it, if I could I think it would have been easier to understand by trial and error.
And may I ask why pin 13 is better than pin 10?
Its the standard relay circuit driving a standard relay, just make sure to get the pinouts
right and do not omit the diode (that will risk destroying the transistor).
Its wise to add some bulk decoupling to the 5V supply driving the relay, a 100uF or so ought to
do it. Ensure your supply can handle the extra 80mA drawn by the relay coil.
paulpaulson:
Hello,
did you check the usebility of this type of relais for your project?
Is the relay bad because it's 5V for motor load EL3 type? I don't know the difference between it and, let's say EL1 resistive load.
MarkT:
Your circuit is fine, but lose the zener and replace the two resistors with a single 220 ohm
resistor. 220 ohms gives 20mA base current, enough to drive any relay coil upto about 300mA
current.
And finally you don't send a pulse, you energize the circuit for as long as you want the relay
to operate.
I understand why we need to remove the zener diode, but our assistants insisted on a zener diode being there (even if it's impossible to have a higher current than the pin of the arduino can handle).
But if I want to operate it, I understand I have to energize the circuit for as long as I want, but it's possible to do that with PWM right? Let's say if I want to operate it I say dutycycle 1 and when I don't want it to operate duty cycle 0 (or reverse, I'm not so sure).
snormanlol:
Is the relay bad because it's 5V for motor load EL3 type? I don't know the difference between it and, let's say EL1 resistive load.
I understand why we need to remove the zener diode, but our assistants insisted on a zener diode being there (even if it's impossible to have a higher current than the pin of the arduino can handle).
But if I want to operate it, I understand I have to energize the circuit for as long as I want, but it's possible to do that with PWM right? Let's say if I want to operate it I say dutycycle 1 and when I don't want it to operate duty cycle 0 (or reverse, I'm not so sure).
Is the relay bad because it's 5V for motor load EL3 type? I don't know the difference between it and, let's say EL1 resistive load.
snormanlol:
Is the relay bad because it's 5V for motor load EL3 type? I don't know the difference between it and, let's say EL1 resistive load.
I understand why we need to remove the zener diode, but our assistants insisted on a zener diode being there (even if it's impossible to have a higher current than the pin of the arduino can handle).
But if I want to operate it, I understand I have to energize the circuit for as long as I want, but it's possible to do that with PWM right? Let's say if I want to operate it I say dutycycle 1 and when I don't want it to operate duty cycle 0 (or reverse, I'm not so sure).
Lose the zener, its complete nonsense as the circuit is 5V throughout. The diode across the load
is the only protection needed.
Don't use PWM. Relays are slow switching devices, orders of magnitude slower than PWM.
snormanlol:
I understand why we need to remove the Zener diode, but our assistants insisted on a Zener diode being there (even if it's impossible to have a higher current than the pin of the Arduino can handle).
So come on, who are these assistants? Do you mean tutors?
We really want to hear their basis for the suggestion. They certainly appear to know no more than you do about electronics, if that.
Do you understand what "PWM" means; what it is? Why do you think it might be appropriate here?
It sometimes comes into argument that it does not matter much, but you have "R_pd" shown on the wrong side of "R_G". It should go from the Arduino output pin to ground.
Paul__B:
So come on, who are these assistants? Do you mean tutors?
We really want to hear their basis for the suggestion. They certainly appear to know no more than you do about electronics, if that.
Do you understand what "PWM" means; what it is? Why do you think it might be appropriate here?
Well these assistants are PhD students, but I think they want that because they think we might make mistakes.
I have a basis understanding of PWM, but I guess it's better to set the relaispin to output and then changing it to high or low to open/close the relay?
I have one remaining question about the relay.
Let's say it's normally closed (NC).
If I set the Relay pin (which is pin 1 on the sketch) to high (so 5V is applied) then I think that the relay will OPEN, or am I wrong?
Later we will use those pins to use serial communication with the ESP32.
This is the first mention of an ESP32. Previously you said that you had an Arduino Uno
My comments regarding Serial comms, pins 10 and 13 and LED_BUILTIN relate to the Uno, not to an ESP32. On a Uno the LED_BUILTIN is on pin 13 which is why I was suggesting that you do not use it for the relay
As far as I can see an ESP alone could do what you want with no Uno required. If you intend the Uno to communicate with an ESP32 via Serial then using pins 0 and 1 on the Uno for that purpose is a bad idea and you would be better off using other pins of your choice and the SoftwareSerial library
Please clarify the microcontroller hardware that you intend to use and for what purpose.
UKHeliBob:
This is the first mention of an ESP32. Previously you said that you had an Arduino Uno
My comments regarding Serial comms, pins 10 and 13 and LED_BUILTIN relate to the Uno, not to an ESP32. On a Uno the LED_BUILTIN is on pin 13 which is why I was suggesting that you do not use it for the relay
As far as I can see an ESP alone could do what you want with no Uno required. If you intend the Uno to communicate with an ESP32 via Serial then using pins 0 and 1 on the Uno for that purpose is a bad idea and you would be better off using other pins of your choice and the SoftwareSerial library
Please clarify the microcontroller hardware that you intend to use and for what purpose.
I was going to use the ESP32 to send data to my databank on google firebase.
snormanlol:
Well these assistants are PhD students, but I think they want that because they think we might make mistakes.
...
Uhm ... sorry for saying this, but, are they sure they are PhD ? ... i mean, you're using a 5V powered MCU board for drive a 5V relay through a transistor with a common open-collector scheme, from a 5V power source ... using a resistor divider and a 5.1V zener in the middle of it for drive the base of the transistor, in these conditions is simply a nonsense, imho ... transistors are driven in current, once you use a resistor for limit this current appropriately, there's no need for anything other ... but, hey, it's all about personal preferences, i suppose ...
snormanlol:
If I set the Relay pin (which is pin 1 on the sketch) to high (so 5V is applied) then I think that the relay will OPEN, or am I wrong?
Well, noting as before that you should not be using either "pin 0" or "pin 1" on a UNO (or Nano or Pro Mini), it is the case that if having correctly set pinMode to OUTPUT you then write the relay pin HIGH the relay should actuate and switch the COM from the NC to the NO connection.
We do not talk of relays "opening" - when a switch contact opens it is no longer connected, a contact is connected when it is "closed".
A relay should either be actuated or not actuated, there is no partial action involved and PWM has no relevance here.
Etemenanki:
Uhm ... sorry for saying this, but, are they sure they are PhD?
Ergo my earlier comment, they appear in that respect to be entirely ignorant of actual electronic engineering theory or practice!
And ... an ESP32 certainly supersedes a UNO (which is a poor choice for the vast majority of projects in any case as the Nano is more practical), once you have an ESP32 you can dispose of the UNO/ Nano.
snormanlol:
But I didn't know that the ESP32 could do the same stuff as an Arduino
Why not? What else did you think it did? It is much faster, much more memory and has all sorts of additional inclusions for WiFi, Bluetooth etc.
Its only real limitation is that you have to code for all the extra things that you will want to do which can potentially interfere with the "simple" things you did with the Arduino in terms of timing but that does not seem to be a particular concern for you.
And it operates at 3.3 V instead of five and has only one input to the ADC and which is limited to 1 V maximum. Actually, I am speaking for the ESP8266, I have not fully studied the ESP32.
Paul__B:
Why not? What else did you think it did? It is much faster, much more memory and has all sorts of additional inclusions for WiFi, Bluetooth etc.
I tought the ESP32 was something more like a data transmittor, my idea was to do the programming with the arduino connect it with TXD & RXD pin and then use some serial communication to send the data from the arduino to the ESP (and then send it to my database)