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?
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 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);
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.