Widget HTML Atas

Viair 93980 Relay Wiring Diagram

Creation: Handle Lots of Relays With Only 2 Wires

I recently worked along a project that requisite to see a shell out of relays. There are these nice boards with 8 or 16 relays that are well suited for my purpose. Both boards have a male pin header with GND and 5Volt pins on the outside and a pin for every relays (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-lying for closing (activate) a electrical relay and high for opening a relay.

This post was showtime published here!

The only trouble is that for controlling so many relays with a small central processor you need a good deal of wires and a micro processor with a mickle of GPIO pins. For this project the ESP8266 is the micro processor of choice ascribable it ability to tie in to a local WiFi network, the speed and the sum of money of flash store. The only drawback is: The ESP8266 does not have enough GPIO pins for the job ahead. The solution, of-course, is to interface with the relays card complete I2C which solely need two GPIO pins plus GND and Vlogic. Then again we need a way to drive the relay race board with I2C which, natively, it can't! Therefor I designed a dedicated I2C multiplexer room to connect as a pickaback to these relays boards to make them I2C compliant!

Design Goals

The board should fit on both 8 and 16 relays boards with as teeny hassle as possible. The I2C bus essential comply to both 3v3 and 5 volt logic so information technology can be in use with, for instance, an Arduino UNO (5 V) and ultramodern 3v3 boards alike the Second sight family. For comfort station it must Be potential to program the ATmega328 by a common ISP connection. Possibility and closing of a taxon relay should be as easy as digitalWrite() to GPIO pins (we need an accompanying depository library for this).

How did I be intimate?

Well, I designed a board with an ATmega328P-PU micro central processor which has 28 pins. Two of these pins are for Vcc (7 and 20) 2 for GND (8 and 22) cardinal for the extrinsic oscillator (9 and 10) AREF (21) is joined to GND away a 100nF cap and RESET (1) is coupled to a Reset circuit. That leaves us with 20 extricated pins. To embody able to program the ATmega with an ISP we need three more pins: MOSI(17), MISO(18) and SCK(19) and of-course the I2C lines SDA(27) and SCL(28). But that's 13 in use pins out of 28 which leaves America with only 15 free pins! Unity stick forgetful if we wish a azygous tholepin for every single relay!! As luck would have it, SCK is only used for programming when the Multiplexer is non connected to the relay get on (to program the ATmega328 you essential remove the I2C Electrical relay Multiplexer Get on from the Relay Board!). This agency that pin 19 can represent used for both SCK and for dominant a relay. Important!

To make up able to use the 5Volt I2C logic of the ATmega with the 3v3 I2C logic of modern boards we necessitate two then called "Bi Position Logic Grade Shifters". Atomic number 3 the name implies, these devices can change over a system of logic (zero or one) signal from one voltage to an other and they can do that some ways. A Level Shifter has a Ground-hugging side and a Broad face. We will associate the high side to the ATmega (5Vin) and the low side to the device that will eventually control the I2C bus. So how do we ready this I2C Relay Multiplexer Board suited for both 3v3 and 5Volt? Thats reniform. You can make the Low side of the Steady Sceneshifter as soprano as the High gear side. Thus if we connect the Vlogic (being 3v3 or 5volt) of the dominant micro processor to Vext (the Low side of the Level Shifter) it volition work for both 3v3 and 5volt! Complete Conventional of the I2C Relay Multiplexer.

For the ATmega328P I wrote firmware and then the ATmega can understand I2C commands and act accordantly to the commands disposed. As every I2C device it has registers you give notice read from or write to. The register map looks like this:

registerLayout: 	  byte      status;         // 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 scan-single record (0x00) that holds the status of the multiplexer. The major- and minorRelease registers (0x01 and 0x02) gives you entropy on the firmware release of the multiplexer. The lastGpioState register (0x03) provides information on the submit (HIGH/Small) of the last used relay. whoAmI is the register (0x04) that holds the I2C address of the multiplexer. The default address is 0x48 merely you derriere change it to everything between 0x01 (1dec) and 0x7F (127dec). Once changed the virgin turn to is saved in EEPROM and that will be the new device address from then on (until you change it once more). numberOfRelays is the register (0x05) that holds, well, the number of relays on the used board. You can unmoving this to 16 (for a 16 relays board) or 8 (for an 8 relays board). This value volition also be saved in EEPROM. To interface betwixt your program (sketch) and the I2C Relay Multiplexer I successful a library (I2C_RelaysMux). This 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-toned});    bool    setI2Caddress(newAddress);  // 1 .. 127 (Dec)           bool    setNumRelays(numRelays);    // 8 surgery 16 (dec)           void    showRegister(regSize, *regPtr, &Stream);            

To use this depository library you firstborn have to install it. From github download the program library as a .ZIP charge. Then, in the Arduino IDE goto [Vignette] and past to "Admit Library" -> "Lend .ZIP depository library…" In the popup window select the "I2C_RelaysMux-master.ZIP code" file in and come home on the [Choose] button. In your program you have to include the library with the following encrypt:

              #admit I2CMUX          relay;     //Create instance of the I2CMUX object

In the apparatus() occasion you make the connection to the multiplexer:

Electrify.begin();
if (!relay.begin(Wire, 0x48))
{
Sequent.println("No device found. Abort!");
while (true) {}
}

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

              

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

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

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

relay.digitalWrite(2, LOW); // out-of-doors relay 2

for (int r=1; r<=16; r++) // flip all relays HIGH

relay.digitalWrite(r, HIGH);

The I2C_RelaysMux library with the ATmega firmware and two case programs are on github.

Step 1:

Example Programs

The I2C_RelaysMux library comes with two example programs. The front one is for an Arduino UNO board, the second, more elaborate good example, is for an ESP8266 board.

I2C UNO RelaysMux Run

The I2C_UNO_RelaysMux_Test is for an Arduino UNO board. Later initialisation (the setup() run) it loops over a readCommand(); occasion. This procedure reads command from the Ordering Monitor and, if the command is recognized, it will execute it. The following commands are valid:

n=1;set electrical relay n to 'closed' (activate) [n= 1 to 16]n=0;set electrical relay n to 'open' (Delaware-activate)every last=1;set entirely relays to 'drawn'complete=0;set all relays to 'admissive'address48;set I2C direct to 0x48 (default)address24;set I2C handle to 0x24board8;plant board case to 8-relays boardboard16;set control board case to 16-relay race board (default)status;I2C Relay Multiplexer statuspinstate;List the state of all the relayslooptest;Chasing relays until a parvenu commend is enteredmuxtest;test on relays plank (this test is performed local on the I2C Relay Multiplexer Board)whoami;returns I2C treat of the I2C Relay Multiplexer Boardwriteconfig;write config to EEPROM (I2C address and board-type)reboot;reboot the I2C Relay Multiplexer Boardrescan;rhenium-glance over for I2C Relay Multiplexer Board addresshelp;Shows valid commands

You can enter multiple commands at one line, separating them aside a semicolon (;). Afterward a period of in-activity the looptest will automatically start.

looptest (Chasing Relay race)

I2C ESP8266 RelaysMux Test

The I2C_ESP8266_RelaysMux_Test is for an ESP8266 board. The functionality of this test program is the synoptic as that of the I2C_UNO_RelaysMux_Test program with some added functionality. For this computer programme to work you have to add the certification of your WiFi network (lines 61 and 62).            
              

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