I'm wondering if using the Adafruit 16-Channel 12-bit PWM/Servo Shield is it possible to switch relays, such as use that shield as a multiplexer and use digital output without PWM.
Is it possible? example code?
-
That's silly. Find something with GPIOs.Ignacio Vazquez-Abrams– Ignacio Vazquez-Abrams2015年05月05日 22:48:50 +00:00Commented May 5, 2015 at 22:48
-
sorry can you expand a little bit your comment?nkint– nkint2015年05月06日 05:45:13 +00:00Commented May 6, 2015 at 5:45
-
Thank you for your interest and the time that to allow to answer to our questions. I have the same problem and i want a sample code to control relay by 16 channel pwm i2c. can you help me please? How can i use this code in the answer in the top : pwm.setPWMFreq(1000);//put this in setup() ... // enable relay at channel 15 pwm.setPWM(15, 1, 0); ... // disable relay at channel 15 pwm.setPWM(15, 1, 1); thankszarki mouhcine– zarki mouhcine2019年07月21日 17:51:39 +00:00Commented Jul 21, 2019 at 17:51
2 Answers 2
That will work. Just make sure you are not using Servo part of the library, but only the PWM part, and set the duty cycle to 100%. The relay should still work, even if the duty cycle is slightly lower, as the magnetic field takes a bit of time to collapse. Just make sure you don't forget to add a (flyback) diode to the relay.
Looking at the datasheet I think you need to use the following code
pwm.setPWMFreq(1000);//put this in setup()
...
// enable relay at channel 15
pwm.setPWM(15, 1, 0);
...
// disable relay at channel 15
pwm.setPWM(15, 1, 1);
-
Sorry I haven't specified before, I need both: PWM and digital output. In this way you are "removing" the pwm, right?nkint– nkint2015年05月07日 15:45:32 +00:00Commented May 7, 2015 at 15:45
-
No. The only thing I changed is the PWM frequency (to the highest possible value).Gerben– Gerben2015年05月07日 15:48:11 +00:00Commented May 7, 2015 at 15:48
-
@nkint Why would you want to control a relay with PWM? At best, PWM would be fast enough to not affect your relay. At worst it might make it buzz. Or are you saying you need some lines to control relays and others to drive PWM outputs?Duncan C– Duncan C2019年07月21日 20:55:56 +00:00Commented Jul 21, 2019 at 20:55
Using the adafruit PWM servo shield seems like overkill, you are paying for a lot facilities (PWM) that you won't be using. If you want to use the shield to reduce the number of pins used on your arduino board, consider a pair of shift out registers (74HC595 for example). The relays need a logic 1 or a logic 0 to change state. You send a bit pattern to the shiftout register that sets the output pins of the shift register to 1 or 0. I found this page helpful.
-
Sorry I had no specified before, I need both: PWM and digital output. Hanks anyway.nkint– nkint2015年05月07日 15:39:44 +00:00Commented May 7, 2015 at 15:39