new project using uno and pwm pca9685 to control bank of 16 5v relays

have seen some posts on using pwm to control servos dont know how to use this info to control 16 relays
want to use the relays to control various strings of 110v christmas lights any help would be greatly appreciated is there a sketch. have googled it and havent found anything yet

Relays don't work with PWM.* They simply turn on/off.

Do you have some kind of relay board with built-in drivers, or just 16 relays?

Have you tried connecting ONE relay with the Blink Example? If you understand the Blink Example or the Blink Without Delay Example, you should be able to blink more than one (in a programmed sequence, or whatever).

Which Arduino do you have? i.e. The Uno only has 14 general purpose I/O pins, and do you need any digital input pins or is everything controlled under software?

  • Some solid state relays will work with PWM, but most AC solid state relays will not... It you want to dim AC you generally need to use phase-controlled dimming which adds some hardware & software complexity.

LM2576 Power Supply 16-Channel 5V Relay Shield Module With Optocoupler 16 CH Relay Microcontroller For Arduino
all i want it to do is to turn relays on and off the uno has only 13 digital pins, i am able to control 13 using the uno, and was hoping the pwm would do the trick using only 2 pins on the uno or am i barking up the wrong tree i am new to this please be kind lol

You will find a multiplexor chip to be your friend for that project.

Common one just needs 4 control pins to control 16 outputs

The Uno's analog pins can be used as digital pins as well.

i would need to convert 3 of the analogue pins to digital how do i do it? thanks in advance

box24grp335:
i would need to convert 3 of the analogue pins to digital how do i do it? thanks in advance

pinMode(A0, OUTPUT);

https://www.arduino.cc/en/Tutorial/DigitalPins

it is important to note that vast majority of Arduino (Atmega) analog pins, may be configured, and used, in exactly the same manner as digital pins.

What 16relay shield do you have?
pca9685 Does not have relays so your title is confusing

16relay_01
Uses 16 relay module board
Turns on an relays one at a time on for one half second steps , hold for 1 second then off for one half second steps, hold 1 second repeat.
Requires external 12VDC power suppply to blue connectors for RELAY power.
LED lights on board will work with no external power supply.

modified 15 Sep 2017
by Bob Wistrand

Use Constants for larger programs
*/
const int D0pin = 0;
const int D1pin = 1;
const int D2pin = 2;
const int D3pin = 3;
const int D4pin = 4;
const int D5pin = 5;
const int D6pin = 6;
const int D7pin = 7;
const int D8pin = 8;
const int D9pin = 9;
const int D10pin = 10;
const int D11pin = 11;
const int D12pin = 12;
//const int D13pin = 13; LED_BUILTIN Pin do not use as OUTPUT
const int A0pin = 14;
const int A1pin = 15;
const int A2pin = 16;

// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.

pinMode(D0pin, OUTPUT);
pinMode(D1pin, OUTPUT);
pinMode(D2pin, OUTPUT);
pinMode(D3pin, OUTPUT);
pinMode(D4pin, OUTPUT);
pinMode(D5pin, OUTPUT);
pinMode(D6pin, OUTPUT);
pinMode(D7pin, OUTPUT);
pinMode(D8pin, OUTPUT);
pinMode(D9pin, OUTPUT);
pinMode(D10pin, OUTPUT);
pinMode(D11pin, OUTPUT);
pinMode(D12pin, OUTPUT);

pinMode(A0pin, OUTPUT);
pinMode(A1pin, OUTPUT);
pinMode(A2pin, OUTPUT);

}

// the loop function runs over and over again forever
void loop() {
digitalWrite(D0pin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500);
digitalWrite(D1pin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(D2pin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(D3pin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(D4pin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(D5pin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(D6pin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(D7pin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(D8pin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(D9pin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(D10pin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(D11pin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(D12pin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second

digitalWrite(A0pin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(A1pin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(A2pin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second

delay(1000); // wait for a second

digitalWrite(D0pin, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(D1pin, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(D2pin, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(D3pin, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(D4pin, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(D5pin, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(D6pin, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(D7pin, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(D8pin, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(D9pin, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(D10pin, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(D11pin, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(D12pin, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second

digitalWrite(A0pin, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(A1pin, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second
digitalWrite(A2pin, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second

delay(1000); // wait for a second
}

the analogue to digital doesnt work

const int D0pin = 0;
const int D1pin = 1;

Can't use those pins. They are already used by the USB<>Serial chip.

Get two 74HC595 shift register breakout boards, and control it all with three Arduino pins.
SparkFun used to sell that as an add-on module.
Leo..

P.S. Take care with mains power and 16-channel relay boards.
They have optos but no opto isolation, because of a design fault.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

the code i posted is not working on all the pins on the uno that is why i thought a pwm would work i need to get pins a0 through a5 to work as digital
thanks to all who have made suggestions
i am new and need all the help i can get

Hi,

  const int A0pin = A0;
  const int A1pin = A1;
  const int A2pin = A2;

Try that. Tom... :slight_smile:

thank to all who replied
i got it the pins working on the uno got all 16 relays clicking now to put it to the test

Hi,

Can please post your working code and a circuit diagram please, to help anyone doing a similar project?

Thanks.. Tom.. :slight_smile: