Widget HTML Atas

Relay Wiring Diagram For 2006 Matrix

Introduction: Handle Lots of Relay race With Only 2 Wires

I freshly worked on a project that needed to control a lot of relay race. On that point are these nice boards with 8 OR 16 relays that are well suited for my use. Some boards have a virile oarlock coping with GND and 5Volt pins on the outside and a pin for every relay race (the 8 relay race board uses a single row of ten pins, the 16 relays board uses two rows of ten pins). The logic is low for closing (trigger) a relay and high for opening a relay.

This post was first published here!

The only problem is that for controlling so many relays with a little processor you need a lot of wires and a micro processor with a lot of GPIO pins. For this project the ESP8266 is the micro mainframe of choice expected to it ability to connect to a local Wireless local area network network, the speed and the amount of flash memory. The only drawback is: The ESP8266 does not have enough GPIO pins for the task ahead. The resolution, of-course, is to user interface with the relays card over I2C which only need two GPIO pins plus GND and Vlogic. But then we penury a way to drive the relays plug-in with I2C which, natively, information technology can't! Therefor I designed a dedicated I2C multiplexer board to tie in A a pig-a-back to these relays boards to make them I2C compliant!

Design Goals

The board should fit happening both 8 and 16 relays boards with as teentsy hassle arsenic possible. The I2C bus must comply to both 3v3 and 5 volt logical system soh it can be used with, for instance, an Arduino UNO (5 volt) and modern 3v3 boards like the ESP family. For convenience it must be accomplishable to programme the ATmega328 by a standard ISP connecter. Opening and closing of a specific relay should be as easy A digitalWrite() to GPIO pins (we need an accompanying library for this).

How did I do it?

Well, I designed a board with an ATmega328P-PU small processor which has 28 pins. Two of these pins are for Vcc (7 and 20) two for GND (8 and 22) 2 for the external oscillator (9 and 10) AREF (21) is connected to GND past a 100nF cap and RESET (1) is attached to a Readjust racing circuit. That leaves us with 20 free pins. To be able to program the ATmega with an ISP we need troika more pins: MOSI(17), MISO(18) and SCK(19) and of-course the I2C lines SDA(27) and SCL(28). But that's 13 ill-used pins out of 28 which leaves us with only 15 liberated pins! 1 pin stumpy if we want a single pin for every single relay!! Luckily, SCK is only used for programming when the Multiplexer is non siamese to the relay circuit card (to program the ATmega328 you mustiness polish of the I2C Relay Multiplexer Board from the Relay Board!). This substance that pin 19 can be used for some SCK and for controlling a relay. Great!

To be able to utilise the 5Volt I2C logical system of the ATmega with the 3v3 I2C system of logic of modern boards we need deuce sol called "Bi Directional Logic Level Shifters". As the name implies, these devices crapper convert a system of logic (zero or one) signal from one voltage to an other and they can ut that both shipway. A Level Shifter has a Low side and a Tall side. We will connect the high side to the ATmega (5Vin) and the low-growing side to the device that will eventually control the I2C motorbus. So how act we make this I2C Electrical relay Multiplexer Board appropriate for both 3v3 and 5Volt? Thats sagittate. You can make the Low broadside of the Tear down Shifter as high as the High side. And so if we associate the Vlogic (existence 3v3 or 5volt) of the dominant micro processor to Vext (the Dispirited pull of the Tied Shifter) it will work for some 3v3 and 5volt! Complete Schematic of the I2C Relay Multiplexer.

For the ATmega328P I wrote firmware and then the ATmega can translate I2C commands and act accordantly to the commands acknowledged. As all I2C device IT has registers you can take from Beaver State publish to. The register correspondenc looks like this:

registerLayout: 	  byte      condition;         // 0x00 (RO) 	  byte      majorRelease;   // 0x01 (RO) 	  byte      minorRelease;   // 0x02 (RO) 	  byte      lastGpioState;  // 0x03 (RO) 	  byte      whoAmI;         // 0x04 (R/W) 	  byte      numberOfRelays; // 0x05 (R/W) 	  byte      Command;        // 0xF0 (W)            

status is a read-entirely register (0x00) that holds the status of the multiplexer. The major- and minorRelease registers (0x01 and 0x02) gives you information on the firmware release of the multiplexer. The lastGpioState register (0x03) provides information on the state (Inebriated/Dejected) of the last used electrical relay. whoAmI is the register (0x04) that holds the I2C address of the multiplexer. The default address is 0x48 but you can change IT to everything between 0x01 (1dec) and 0x7F (127dec). Once varied the new address is saved in EEPROM and that will embody the new device address from then connected (until you change it again). numberOfRelays is the register (0x05) that holds, well, the add up of relay race on the used board. You can set this to 16 (for a 16 relays plug-in) operating theatre 8 (for an 8 relays board). This value will also be saved in EEPROM. To interface between your program (sketch) and the I2C Relay Multiplexer I made a depository library (I2C_RelaysMux). This program library has the following methods:

              bool    begin(Wire, deviceAddress);   bool    isConnected();   byte    getMajorRelease();   byte    getMinorRelease();   byte    getWhoAmI();   byte    getNumRelays();   byte    getStatus();   bool    writeCommand(COMMAND);   bool    digitalRead(relayNr);    bool    digitalWrite(relayNr, {HIGH|LOW});    bool    setI2Caddress(newAddress);  // 1 .. 127 (dec)           bool    setNumRelays(numRelays);    // 8 or 16 (dec)           void    showRegister(regSize, *regPtr, &adenosine monophosphate;Teem);            

To practice this library you first have to install it. From github download the depository library as a .ZIP file. Then, in the Arduino IDE goto [Sketch] and then to "Include Library" -> "Add .ZIP depository library…" In the popup window select the "I2C_RelaysMux-master.zip" filing cabinet and click on the [Choose] button. In your political platform you bear to include the library with the following code:

              #admit I2CMUX          electrical relay;     //Produce instance of the I2CMUX object

In the setup() serve you make the connection to the multiplexer:

Wire.commenc();
if (!electrical relay.begin(Wire, 0x48))
{
Sequent.println("No twist found. Abort!");
while (typical) {}
}

You can now start victimisation the multiplexer by sending instructions like this:

              

electrical relay.digitalWrite(2, Full); // close relay 2

state = relay.digitalRead(2); // state should now be 1

relay.digitalWrite(5, HIGH); // close relay 5

relay.digitalWrite(2, LOW); // expressed electrical relay 2

for (int r=1; r<=16; r++) // switch every relays HIGH

electrical relay.digitalWrite(r, Graduate);

The I2C_RelaysMux library with the ATmega firmware and two example programs are along github.

Step 1:

Example Programs

The I2C_RelaysMux depository library comes with two example programs. The original same is for an Arduino UNO board, the second, more than elaborate exercise, is for an ESP8266 board.

I2C UNO RelaysMux Test

The I2C_UNO_RelaysMux_Test is for an Arduino UNO board. After initialisation (the setup() operate) it loops over a readCommand(); purpose. This function reads command from the Serial Monitor and, if the command is recognized, it wish put to death it. The following commands are valid:

n=1;set electrical relay n to 'closed' (spark) [n= 1 to 16]n=0;set electrical relay n to 'open' (de-touch of)all=1;set all relay race to 'enclosed'all=0;set all relays to 'open'address48;set I2C address to 0x48 (default)address24;set I2C address to 0x24board8;set board type to 8-relays boardboard16;set display panel type to 16-relay race plug-in (default)status;I2C Electrical relay Multiplexer statuspinstate;Heel the res publica of every last the relayslooptest;Chasing relays until a fres remember is enteredmuxtest;test along relays card (this test is performed local connected the I2C Relay Multiplexer Board)whoami;returns I2C address of the I2C Relay Multiplexer Boardwriteconfig;write config to EEPROM (I2C call and board-case)reboot;reboot the I2C Relay Multiplexer Boardrescan;re-scan for I2C Relay Multiplexer Board addresshelp;Shows valid commands

You can embark quaternate commands at nonpareil credit line, separating them by a semicolon (;). Afterward a period of in-activity the looptest will automatically starting line.

looptest (Chasing Relays)

I2C ESP8266 RelaysMux Test

The I2C_ESP8266_RelaysMux_Test is for an ESP8266 board. The functionality of this run program is the selfsame A that of the I2C_UNO_RelaysMux_Test program with some added functionality. For this program to work you have to minimal brain damage the credentials of your WiFi network (lines 61 and 62).            
              

#ifndef STASSID #define STASSID "your-ssid" #define STAPSK "your-password"