M42 S -Value for Relay Control
-
Hello all,
I'm using GPIO pins on my Duex to control a relay with the M42 command. However, I'm not sure what S-Value is suitable for a relay (or maybe mine specifically)?
I tried with an S value of both 0, 0.5, & 1 and got no reaction out of the relay. I have the positive terminal of my relay input to the GPIO4 pin on my Duex and the negative terminal to GND on the same header pin row as the GPIO4.
It's currently in my config.g as:
M950 P3 C"duex.gp4" Q500
and then I've been attempting to control with
M42 P3 SX
where X was attempted with 0, 0.5, & 1
-
-
I would think you would want 0 and 1 to turn it off and on.
If you send M98 P"config.g" do you get any syntax errors?
-
@phaedrux That was my thinking as well. M98 on my config returns only a warning about heater 1 being potentially overpowered but I haven't had any issues with that outside this warning.
-
@jrcl I’m not sure about the fanout of the GPIO pins on the DUEX, but it may be less than needed to drive an SSR which typically requires 6-12 mA. With luck, you can get along if you use the pin to pull the relay to GND, I.e. connect the positive relay terminal to +5V.
The better way is to use a transistor like this:
A suitable NPN transistor is the BC547C or 2N3904. For the diode, use a 1N4148 or BAT48 (ore something similar, it is not critical).
The S parameter of
M42
is either 1 or 0 (to set the relay’s state on or off), or it can be any value in between to control PWM. -
@infiniteloop I see, appreciate the diagram too! Any clue if there are relays more fit for this sort of application that can support such a 120VAC load with that sort of signal or internalize the transistor and additional diode?
Additionally what sort of diode would you recommend or is that uneeded?
-
This post is deleted! -
@infiniteloop Pulling it through GND and putting the positive terminal on the 5V pin did fix it though! Thank you!
-
-
@jrcl said in M42 S -Value for Relay Control:
Any clue if there are relays more fit for this sort of application that can support such a 120VAC load with that sort of signal or internalize the transistor and additional diode?
There are many offers like these.
But, especially for relays applicable to mains voltages with high currents, I don't know of any.
@jrcl said in M42 S -Value for Relay Control:
Additionally what sort of diode would you recommend or is that uneeded?
For the diode, use a 1N4148 or BAT48. Some SSRs are equipped with a diode, some are not. If you are in doubt, provide one.
Pulling it through GND and putting the positive terminal on the 5V pin did fix it though! Thank you!
Just got that post. Great!