16xRelay with ESP12F Onboard and two Shift Register (74HC595)

I have been looking for more information about this plate and after much searching I have found in a Chinese blog this information that is quite similar to this plate, to see if someone can decipher and understand it.
https://blog.csdn.net/weixin_43796593/article/details/84639021
(sorry for my bad English)

I just received mine.
I measured the board and I come to the conclusion that U4 is connected to the I/Os not U5.

Nevertheless:
Can you try this config once:

sn74hc595:
  - id: 'sn74hc595_hub'
    data_pin: GPIO14
    clock_pin: GPIO13
    latch_pin: GPIO12
    oe_pin: GPIO05
    sr_count: 2

THis is indead what I have measured on the board.

I will test mine later on, I have currently not much time left.

1 Like

BTW: Yes right this China LC
ESP12F 16x Relay

1 Like

Congratulations Chirstian, with this code that you have sent everything worked perfectly, thank you very much :+1: :clap: :clap: :clap:

Thats nice @juanjovi
For me only the LED on the Relay switches on, but the Relay is still not switching.

Have you measured the function of the relay?

Thanks and BR
Christian

1 Like

And I found my issue…
When bying a 24V Version, you should supply 24V and not 12V.
With 12V the relays are not working…

For completenes, hereby the code which is working.

esphome:
  name: coverlivingroom

esp8266:
  board: esp01_1m

wifi:
  reboot_timeout: 0s
  domain: ".my.secret.domain"
  networks:
  - ssid: !secret wifi_ssid
  - password: !secret wifi_pass
  - ssid: 'rescue'
  - password: '12345678'
  #use_address: ''

# Enable logging
logger:

  # Enable Web server
web_server:
  port: 80

# Enable Home Assistant API/OTA
api:
  password: !secret api_pass2
  reboot_timeout: 0s
ota:
  safe_mode: true
  password: !secret ota_pass

# Sync time with Home Assistant
time:
  - platform: homeassistant
    id: homeassistant_time

# Example configuration entry
sn74hc595:
  - id: 'sn74hc595_hub'
    data_pin: GPIO14
    clock_pin: GPIO13
    latch_pin: GPIO12
    oe_pin: GPIO05
    sr_count: 2

# Individual outputs
switch:
  - platform: gpio
    name: "SN74HC595 Pin #0"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 0
      number: 0
      inverted: false
  - platform: gpio
    name: "SN74HC595 Pin #1"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 1
      number: 1
      inverted: false
  - platform: gpio
    name: "SN74HC595 Pin #2"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 2
      number: 2
      inverted: false
  - platform: gpio
    name: "SN74HC595 Pin #3"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 3
      number: 3
      inverted: false
  - platform: gpio
    name: "SN74HC595 Pin #4"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 4
      number: 4
      inverted: false
  - platform: gpio
    name: "SN74HC595 Pin #5"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 5
      number: 5
      inverted: false
  - platform: gpio
    name: "SN74HC595 Pin #6"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 6
      number: 6
      inverted: false
  - platform: gpio
    name: "SN74HC595 Pin #7"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 7
      number: 7
      inverted: false
  - platform: gpio
    name: "SN74HC595 Pin #8"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 8
      number: 8
      inverted: false
  - platform: gpio
    name: "SN74HC595 Pin #9"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 9
      number: 9
      inverted: false
  - platform: gpio
    name: "SN74HC595 Pin #10"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 10
      number: 10
      inverted: false
  - platform: gpio
    name: "SN74HC595 Pin #11"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 11
      number: 11
      inverted: false
  - platform: gpio
    name: "SN74HC595 Pin #12"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 12
      number: 12
      inverted: false
  - platform: gpio
    name: "SN74HC595 Pin #13"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 13
      number: 13
      inverted: false
  - platform: gpio
    name: "SN74HC595 Pin #14"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 14
      number: 14
      inverted: false
  - platform: gpio
    name: "SN74HC595 Pin #15"
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 15
      number: 15
      inverted: false

And for everyone who plans to use this board as “time-based-cover”, my v1 config:

substitutions:
#Substitutions added for easy maintenance
  device_name: living16xrelay
  cover_kitchen: coverkitchen
  cover_kitchen_open_duration: 16.05sec
  cover_kitchen_close_duration: 15.00sec
  cover_island: coverisland
  cover_island_open_duration: 16.05sec
  cover_island_close_duration: 15.00sec
  cover_diner: coverdiner
  cover_diner_open_duration: 16.05sec
  cover_diner_close_duration: 15.00sec
  cover_living: coverliving
  cover_living_open_duration: 16.05sec
  cover_living_close_duration: 15.00sec
  cover_bath: coverbath
  cover_bath_open_duration: 16.05sec
  cover_bath_close_duration: 15.00sec
  
  
esphome:
  name: ${device_name}

esp8266:
  board: esp01_1m

<<: !include templates/templatesensorsv1.yaml

wifi:
  reboot_timeout: 0s
  domain: ".my.secret.domain"
  networks:
  - ssid: !secret wifi_ssid
  - password: !secret wifi_pass
  - ssid: 'rescue'
  - password: '12345678'
  #use_address: 'coverlivingroom.my.secret.domain'

# Enable logging
logger:

  # Enable Web server
web_server:
  port: 80

# Enable Home Assistant API/OTA
api:
  password: !secret api_pass2
  reboot_timeout: 0s
ota:
  safe_mode: true
  password: !secret ota_pass

# Sync time with Home Assistant
time:
  - platform: homeassistant
    id: homeassistant_time

# Intiate Shift Register GPIOs
sn74hc595:
  - id: "sn74hc595_hub"
    data_pin: GPIO14
    clock_pin: GPIO13
    latch_pin: GPIO12
    oe_pin: GPIO05
    sr_count: 2


switch:

# Switch to restart the shutter
  - platform: restart
    id: reset
    name: "${device_name} Restart"

#Relay by ShiftRegister (id only, so only internal)
#Even if not required, in case motors are correctly wired, adding interlock to always make sure only 1 Relay is driving, especially in Web Server
  - platform: gpio
    id: relay_kitchen_up
    interlock: &interlock_group0 [relay_kitchen_up, relay_kitchen_down]
    restore_mode: always off
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 0
      number: 0
      inverted: false
  
  - platform: gpio
    id: relay_kitchen_down
    interlock: *interlock_group0
    restore_mode: always off
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 1
      number: 1
      inverted: false
  
  - platform: gpio
    id: relay_island_up
    interlock: &interlock_group1 [relay_island_up, relay_island_down]
    restore_mode: always off
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 2
      number: 2
      inverted: false
  
  - platform: gpio
    id: relay_island_down
    interlock: *interlock_group1
    restore_mode: always off
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 3
      number: 3
      inverted: false
  
  - platform: gpio
    id: relay_diner_up
    interlock: &interlock_group3 [relay_diner_up, relay_diner_down]
    restore_mode: always off
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 4
      number: 4
      inverted: false
 
  - platform: gpio
    id: relay_diner_down
    interlock: *interlock_group3
    restore_mode: always off
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 5
      number: 5
      inverted: false
  
  - platform: gpio
    id: relay_living_up
    interlock: &interlock_group4 [relay_living_up, relay_living_down]
    restore_mode: always off
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 6
      number: 6
      inverted: false
  
  - platform: gpio
    id: relay_living_down
    interlock: *interlock_group4
    restore_mode: always off
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 7
      number: 7
      inverted: false
  
  - platform: gpio
    id: relay_bath_up
    interlock: &interlock_group5 [relay_bath_up, relay_bath_down]
    restore_mode: always off
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 8
      number: 8
      inverted: false
  
  - platform: gpio
    id: relay_bath_down
    interlock: *interlock_group5
    restore_mode: always off
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 9
      number: 9
      inverted: false
 
  - platform: gpio
    id: no_use10
    restore_mode: always off
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 10
      number: 10
      inverted: false
  - platform: gpio
    id: no_use11
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 11
      number: 11
      inverted: false
  - platform: gpio
    id: no_use12
    restore_mode: always off
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 12
      number: 12
      inverted: false
  - platform: gpio
    id: no_use13
    restore_mode: always off
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 13
      number: 13
      inverted: false
  - platform: gpio
    id: no_use14
    restore_mode: always off
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 14
      number: 14
      inverted: false
  - platform: gpio
    id: no_use15
    restore_mode: always off
    pin:
      sn74hc595: sn74hc595_hub
      # Use pin number 15
      number: 15
      inverted: false

cover:
- platform: time_based
  name: "${cover_kitchen}"
  id: cover_kitchen
  open_action:
    - switch.turn_on: relay_kitchen_up
  open_duration: ${cover_kitchen_open_duration}
  close_action:
    - switch.turn_on: relay_kitchen_down
  close_duration: ${cover_kitchen_close_duration}
  stop_action:
    - switch.turn_off: relay_kitchen_up
    - switch.turn_off: relay_kitchen_down

- platform: time_based
  name: "${cover_island}"
  id: cover_island
  open_action:
    - switch.turn_on: relay_island_up
  open_duration: ${cover_island_open_duration}
  close_action:
    - switch.turn_on: relay_island_down
  close_duration: ${cover_island_close_duration}
  stop_action:
    - switch.turn_off: relay_island_up
    - switch.turn_off: relay_island_down


- platform: time_based
  name: "${cover_diner}"
  id: cover_diner
  open_action:
    - switch.turn_on: relay_diner_up
  open_duration: ${cover_diner_open_duration}
  close_action:
    - switch.turn_on: relay_diner_down
  close_duration: ${cover_diner_close_duration}
  stop_action:
    - switch.turn_off: relay_diner_up
    - switch.turn_off: relay_diner_down

- platform: time_based
  name: "${cover_living}"
  id: cover_living
  open_action:
    - switch.turn_on: relay_living_up
  open_duration: ${cover_living_open_duration}
  close_action:
    - switch.turn_on: relay_living_down
  close_duration: ${cover_living_close_duration}
  stop_action:
    - switch.turn_off: relay_living_up
    - switch.turn_off: relay_living_down
    
- platform: time_based
  name: "${cover_bath}"
  id: cover_bath
  open_action:
    - switch.turn_on: relay_bath_up
  open_duration: ${cover_bath_open_duration}
  close_action:
    - switch.turn_on: relay_bath_down
  close_duration: ${cover_bath_close_duration}
  stop_action:
    - switch.turn_off: relay_bath_up
    - switch.turn_off: relay_bath_down


The wiring, I recommend to do it like that:
wiring_cover

This enables you to forget about interlock_wait_time, as it can never power both ends of your motor.
Thanks to @alfredopironti (Github Time-Based Cover - calculate interlock_wait_time to open/close duration + add max_duration #778

…send Line (220V) to the COM of relay_1, use NO of relay_1 for cover direction UP, join NC of relay_1 with NO of relay_2; use COM of relay_2 for cover direction DOWN. This makes programming straightforward as you get one relay per direction, and electrical interlock (but, again, no interlock_wait_time!)…

Happy ESP-ing :slight_smile:

6 Likes

Awesome work! Can this be adapted to turn on 16 valves?

1 Like

Sure!
If fitting to the relay, no issue.
Just connect your power to the relay and configure ESPhome to your needs.

e.g. Sprinkler system, some example also here:
Sprinkler

2 Likes

Awesome! Thx. Now I can compare mine to that code see how to use ESPHome as this is a nice complicated setup.

Thx again :smile:

any one was able to use al 16 relays?

Yes.
All tested and working.

Hello All,

I’ve got the same board with 16 relays.
Can anyone please share the source code for the demo sample (Arduino code)?

Thank you.

Hello smart people,

I have purchased a couple of these boards, and was hoping based on the above discussion if someone knows how to adapt this to address the relays directly when uploading a sketch, so something like:

int latchPin = 12;  // Latch pin of 74HC595 is connected to Digital pin 5
int clockPin = 13; // Clock pin of 74HC595 is connected to Digital pin 6
int dataPin = 14;  // Data pin of 74HC595 is connected to Digital pin 4

void setup() 
{
  // Set all the pins of 74HC595 as OUTPUT
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);

My problem is, if these 3 pins are the ones to use to address the 74HC595’s then how would you go about sending the data to trigger the LED/RELAY for each of the 16 relays, I’m just a bit out of my depth here and there is no doco and I am awaiting responses from LC Tech in china.

Do I need to care about the OE pin ? Tried to gain some better understanding from this article: In-Depth: How 74HC595 Shift Register Works & Interface with Arduino

But yeah wondering if anyone had any ideas on how to actually control the LED’s/RELAYS on these 16 relay boards when you flash the code it comes shipped with.

Does anyone have example code or the code with which these units are shipped so I could reverse engineer ? The code provided in some of the listings doesn’t seem to do anything I think it is for the lower count relay boards that do direct pinout to relay: DC 5V/12V/24V ESP8266 WIFI 16 Channels Relay Module ESP-12F Development Board | eBay

I know this is more of a HOME automation site, but its the only place I have found a conversation about this board and the code to control it.

I have some code that sort of works on this board (short pin IO0 to GND to put in flash mode)
If anyone knows what the data format you need to feed the 74HC595 I would be eternally grateful, I am just trying stuff but its not particularly reliable (different results dependant on data order sent, makes me think sending too much data and there is overflow from one request to the next).

This version seems to activate Relay 9 (not sure how), then it jump switches between relay 8 and 16.

// LCTech 16ch Relay board with 2x74HC595 shift registers - replicates close to out of box relay testing function
int latchPin = 12;  // Latch pin of 74HC595 is connected to Digital pin 5
int clockPin = 13; // Clock pin of 74HC595 is connected to Digital pin 6
int dataPin = 14;  // Data pin of 74HC595 is connected to Digital pin 4
int oePin = 5;    // oePin - not using this

void setup() 
{
  // Set all the pins of 74HC595 as OUTPUT
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
  pinMode(oePin, OUTPUT);

  // Setup serial comms
  Serial.begin(115200);  
}

void loop() 
{

      Serial.println("Relay #16 = 0b0000");       
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, 0b0000);
      digitalWrite(latchPin, HIGH);
      delay(3000);

      Serial.println("Relay #8 = 0b0001");       
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, LSBFIRST, 0b0001);
      digitalWrite(latchPin, HIGH);
      delay(3000);

}

I contacted the manufacture as well, no answer received.
You could check the source code of the component in ESPhome and you would have some indications how to port to arduino.

Hello
I have found out how to control it using Arduino I will create a sample code with a function that takes the relay number and state as a parameter and chang the state.
I will be posting it later today.

Hi Again,
I tried to replicate the demo behavior below is the source code:

int latchPin = 12;  // Latch pin of 74HC595 is connected to Digital pin 5
int clockPin = 13; // Clock pin of 74HC595 is connected to Digital pin 6
int dataPin = 14;  // Data pin of 74HC595 is connected to Digital pin 4
int oePin = 5;    // oePin - not using this

uint16_t Data ;

void setup() 
{
  // Set all the pins of 74HC595 as OUTPUT
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);  
  pinMode(clockPin, OUTPUT);
  pinMode(oePin, OUTPUT);

}

void loop() 
{

            Data = 0b0000000000000001;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0000000000000011;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0000000000000111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0000000000001111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0000000000011111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0000000000111111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0000000001111111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0000000011111111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0000000111111111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0000001111111111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0000011111111111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0000111111111111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0001111111111111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0011111111111111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b0111111111111111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b1111111111111111;         
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);               
            Data = 0b1111111111111110;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100);
            Data = 0b1111111111111100;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100); 
            Data = 0b1111111111111000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100); 
            Data = 0b1111111111110000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100); 
            Data = 0b1111111111100000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100); 
            Data = 0b1111111111000000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100); 
            Data = 0b1111111110000000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100); 
            Data = 0b1111111100000000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100); 
            Data = 0b1111111000000000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100); 
            Data = 0b1111110000000000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100); 
            Data = 0b1111100000000000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100); 
            Data = 0b1111000000000000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100); 
            Data = 0b1110000000000000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100); 
            Data = 0b1100000000000000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100); 
            Data = 0b1000000000000000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100); 
            Data = 0b0000000000000000;
      digitalWrite(latchPin, LOW);
      shiftOut(dataPin, clockPin, MSBFIRST, (Data >> 8));
      shiftOut(dataPin, clockPin, MSBFIRST, Data);
      digitalWrite(latchPin, HIGH);
      delay(100); 
}
2 Likes

Hi All

I’ve noticed that if I leave the board unpowered for a long time then I try to plug it it doesn’t start only if I connect the external ttl frasher tx, rx and GND then power it.
Anyone is facing the same?
Once started it remains functional even if unplug the ttl but after 1 to 2 hours it returns to same state.
Is there a jumper that should remain connected ?
But somehow with the electricity stored in the capacitor it could word for some time?

Thank you.

Brilliant work ! That gives full control over all 16 relays including turning any number on at once. Saved me a bundle of pain and trial and error.

I can confirm this works as expected and yes emulates the test mode out of the box.

In regards to issues with it powering on or not powering on, I had real issues with the first one of these I tried to code, kept getting “Connecting ------…-----…Timeout”.
Admittedly I had tried to desolder some of the relay wire connection blocks and had also possibly pushed 5v TTL signals into it or overpowered it using the 5v from the TTL converter. I was at wits end, then pulled another one out of its box and it worked first go using separate regulated power and only RX/TX and GND pins from TTL that specifically pushes out 3.3v signals. My flash and power process is in the description of the video below.

Recorded a video and back-linked to this thread/code.

Note on wiring:
Yellow/Orange/Brown = RX/TX/GND only (I do not connect the power from the TTL unit, TTL unit is 3,3v switchable signal voltage output)
Green/blue leads = connects GND to IO0 through a push button, so I press this to go into flash mode on start
Red/Black = Separate regulated 12v lab supply, it max’s out around 500mA when all the relays are on using the test code above. (check which voltage version you bought before supplying power to board)

Thank you Atef, awesome solution.

Finally got a hold of a link to the manuals, code and utilities for this 16 relay board from LCTech
https://www.mediafire.com/file/vzx664wc9xle9hj/LC-Relay-ESP12-16R-DXX_EN.zip/file

Happy coding.

Anyone willing to share an esphome code aswell with all 16 relay configured? Just as simple switches?