0

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?

3
  • That's silly. Find something with GPIOs. Commented May 5, 2015 at 22:48
  • sorry can you expand a little bit your comment?
    – nkint
    Commented 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); thanks Commented Jul 21, 2019 at 17:51

2 Answers 2

1

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);
3
  • Sorry I haven't specified before, I need both: PWM and digital output. In this way you are "removing" the pwm, right?
    – nkint
    Commented May 7, 2015 at 15:45
  • No. The only thing I changed is the PWM frequency (to the highest possible value).
    – Gerben
    Commented 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
    Commented Jul 21, 2019 at 20:55
0

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.

1
  • Sorry I had no specified before, I need both: PWM and digital output. Hanks anyway.
    – nkint
    Commented May 7, 2015 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.