In this illustration we will going to wire the 16×2 i2C lCD Screen with 4 channel relay to monitor each channel of the relay, please refer to this link if you need to know and understand how i2c works. Basically driving the 4 channel relay it is very simple and good thing about i2c it works only 4 wires to be connected to the i2C SCL (Serial Clock Line) protocol is clock stretching. An addressed slave device may hold the clock line (SCL) low after receiving (or sending) a byte, indicating that it is not yet ready to process more data and the i2C SDA(Serial Data Line) Every master monitors the bus for start and stop bits, and does not start a message while another master is keeping the bus busy. However, two masters may start transmission at about the same time; in this case, arbitration occurs. Slave transmit mode can also be arbitrated, when a master addresses multiple slaves, but this is less common. In contrast to protocols (such as Ethernet) that use random back-off delays before issuing a retry, I²C has a deterministic arbitration policy. Each transmitter checks the level of the data line (SDA) and compares it with the levels it expects; if they do not match, that transmitter has lost arbitration, and drops out of this protocol interaction. Below are the required components for this lab all can be purchase at souq.
Required Components
- Arduino Board
- 2 or 4 channel relay
- 16×2 I2C Driven LCD Display
- Solder less bread board.
- Jumper Wires / DuPont Wires
Wiring Diagram and Pinouts
Arduino Sketch
Note: Mostly use address is 0x27, 0x3f, 0x38
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
/* ################################################### 14CORE Monitoring 4 Channel relay with LCD 16x2 i2C www.14core.com $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */ #include <LiquidCrystal_I2C.h> #include <Wire.h> //#define BACKLIGHT_PIN 3 // For 2 Channel Relay #define P1_PIN 4 #define P2_PIN 5 // For 4 Channel Relay //#define P3_PIN 6 //#define P4_PIN 7 // For 8 Channel Relay //#define P5_PIN 8 //#define P6_PIN 9 //#define P7_PIN 10 //#define P8_PIN 11 LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); //Note: Mostly use address is 0x27, 0x3f, 0x38 void setup() { //analogWrite(BACKLIGHT_PIN, 255 ); lcd.begin(16, 2); lcd.print("14CORE / Relay "); lcd.setCursor(0, 1); } int Delay = 1000; void loop() { for ( int i = 0; i < 2; i++ ) { lcd.setCursor(0, 1); lcd.print("Channel-"); lcd.print( i + 1 ); lcd.print(": On "); pinMode( P1_PIN + i, 1 ); delay( Delay ); lcd.setCursor(0, 1); lcd.print("Channel-"); lcd.print( i + 1 ); lcd.print(": Off"); pinMode( P1_PIN + i, 0 ); delay( Delay ); } Delay += 1000; if ( Delay > 2000 ) Delay = 1000; } |
Required Code Library
Download LiquidCrystal_I2C.h Library here | Zip
Download Wire.h Code Library here | Zip