<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title><![CDATA[Smart Home Automation Forum - B16]]></title>
		<link>https://www.kincony.com/forum/</link>
		<description><![CDATA[Smart Home Automation Forum - https://www.kincony.com/forum]]></description>
		<pubDate>Sat, 09 May 2026 08:50:22 +0000</pubDate>
		<generator>MyBB</generator>
		<item>
			<title><![CDATA[B16 Smart Controller Wiring Examples]]></title>
			<link>https://www.kincony.com/forum/showthread.php?tid=9253</link>
			<pubDate>Sat, 18 Apr 2026 10:40:47 +0800</pubDate>
			<dc:creator><![CDATA[<a href="https://www.kincony.com/forum/member.php?action=profile&uid=1">admin</a>]]></dc:creator>
			<guid isPermaLink="false">https://www.kincony.com/forum/showthread.php?tid=9253</guid>
			<description><![CDATA[<!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/image.png" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=9626" target="_blank" title="">B16_wiring.jpg</a> (Size: 269.12 KB / Downloads: 62)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[<!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/image.png" title="JPG Image" border="0" alt=".jpg" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=9626" target="_blank" title="">B16_wiring.jpg</a> (Size: 269.12 KB / Downloads: 62)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[B16 Smart Controller ESP32 system block diagram]]></title>
			<link>https://www.kincony.com/forum/showthread.php?tid=9252</link>
			<pubDate>Sat, 18 Apr 2026 10:40:07 +0800</pubDate>
			<dc:creator><![CDATA[<a href="https://www.kincony.com/forum/member.php?action=profile&uid=1">admin</a>]]></dc:creator>
			<guid isPermaLink="false">https://www.kincony.com/forum/showthread.php?tid=9252</guid>
			<description><![CDATA[<!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/image.png" title="PNG Image" border="0" alt=".png" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=9625" target="_blank" title="">KinCony-B16-smart-controller-diagram.png</a> (Size: 836.5 KB / Downloads: 52)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[<!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/image.png" title="PNG Image" border="0" alt=".png" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=9625" target="_blank" title="">KinCony-B16-smart-controller-diagram.png</a> (Size: 836.5 KB / Downloads: 52)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Separate loading Firmware and configurations]]></title>
			<link>https://www.kincony.com/forum/showthread.php?tid=9052</link>
			<pubDate>Sun, 15 Feb 2026 04:26:55 +0800</pubDate>
			<dc:creator><![CDATA[<a href="https://www.kincony.com/forum/member.php?action=profile&uid=10213">danielrio</a>]]></dc:creator>
			<guid isPermaLink="false">https://www.kincony.com/forum/showthread.php?tid=9052</guid>
			<description><![CDATA[Hi, as i wrote previously in another thread i'm quite new on this modules so sorry if i write something already discussed.<br />
I'm recently facing the need to update the firmware of my B16s because i see new feature that i want to try. The problem is that i'm not finding any way to preserve the configuration (Network settings, IFTTT settings, custom Protocols and so on) so i could be able to load the new firmware but don't spend too much time reconfiguring manually all the stuffs.<br />
<br />
Is there something i'm missing to backup the module configurations?<br />
<br />
Thanks in advance.<br />
Kind regards]]></description>
			<content:encoded><![CDATA[Hi, as i wrote previously in another thread i'm quite new on this modules so sorry if i write something already discussed.<br />
I'm recently facing the need to update the firmware of my B16s because i see new feature that i want to try. The problem is that i'm not finding any way to preserve the configuration (Network settings, IFTTT settings, custom Protocols and so on) so i could be able to load the new firmware but don't spend too much time reconfiguring manually all the stuffs.<br />
<br />
Is there something i'm missing to backup the module configurations?<br />
<br />
Thanks in advance.<br />
Kind regards]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[http requesto to toggle switch]]></title>
			<link>https://www.kincony.com/forum/showthread.php?tid=9032</link>
			<pubDate>Mon, 09 Feb 2026 03:27:32 +0800</pubDate>
			<dc:creator><![CDATA[<a href="https://www.kincony.com/forum/member.php?action=profile&uid=10213">danielrio</a>]]></dc:creator>
			<guid isPermaLink="false">https://www.kincony.com/forum/showthread.php?tid=9032</guid>
			<description><![CDATA[Hi all,<br />
i have some B16 currently with the 3.80 kcs firmware.<br />
I had the need to control an output on the module 2 when a DI on module 1 is pressed.<br />
I saw i can do it with custom protocol. I tried with UDP message, but it seems a bit loosy, in some ways each 10 clicks, 2 or 3 are lost,  alternatively i thought i could do it with http call (POST or GET).<br />
The problem is that i don't know how to do it with the KCS firmware, i don't know if there are some preconfigured urls to let the modules relays to be switched on off or toggled.<br />
I saw on ESPHome there are some documentations talking about this possibility, but i'm not sure these are usable on KCS firmware.<br />
<br />
Sorry i'm a bit new and i cannot find a way to do this, but i'm pretty sure it can be done easily, and i'm just not able to do it.<br />
Could someone please help me?]]></description>
			<content:encoded><![CDATA[Hi all,<br />
i have some B16 currently with the 3.80 kcs firmware.<br />
I had the need to control an output on the module 2 when a DI on module 1 is pressed.<br />
I saw i can do it with custom protocol. I tried with UDP message, but it seems a bit loosy, in some ways each 10 clicks, 2 or 3 are lost,  alternatively i thought i could do it with http call (POST or GET).<br />
The problem is that i don't know how to do it with the KCS firmware, i don't know if there are some preconfigured urls to let the modules relays to be switched on off or toggled.<br />
I saw on ESPHome there are some documentations talking about this possibility, but i'm not sure these are usable on KCS firmware.<br />
<br />
Sorry i'm a bit new and i cannot find a way to do this, but i'm pretty sure it can be done easily, and i'm just not able to do it.<br />
Could someone please help me?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[B16 mqtt code]]></title>
			<link>https://www.kincony.com/forum/showthread.php?tid=8818</link>
			<pubDate>Fri, 12 Dec 2025 19:09:19 +0800</pubDate>
			<dc:creator><![CDATA[<a href="https://www.kincony.com/forum/member.php?action=profile&uid=1528">Sameh</a>]]></dc:creator>
			<guid isPermaLink="false">https://www.kincony.com/forum/showthread.php?tid=8818</guid>
			<description><![CDATA[Need for mqtt code for cover shutter and water level]]></description>
			<content:encoded><![CDATA[Need for mqtt code for cover shutter and water level]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[B16 password reset]]></title>
			<link>https://www.kincony.com/forum/showthread.php?tid=8743</link>
			<pubDate>Sun, 16 Nov 2025 20:17:52 +0800</pubDate>
			<dc:creator><![CDATA[<a href="https://www.kincony.com/forum/member.php?action=profile&uid=9869">lelik_ku</a>]]></dc:creator>
			<guid isPermaLink="false">https://www.kincony.com/forum/showthread.php?tid=8743</guid>
			<description><![CDATA[Hello, I try to login to B16 default web UI (<a href="http://192.168.4.1/login.html" target="_blank" rel="noopener" class="mycode_url">http://192.168.4.1/login.html</a>) and enter admin/admin password.<br />
Receive Password incorrect error.<br />
I don't remember if I changed the password, so I need to reset it do default.<br />
Tried to push DL and Reset buttons for 10+ seconds, the device reboots, but admin/admin is still not correct.<br />
Also tried admin without a password, also tried admin/jingkong - still not getting access.]]></description>
			<content:encoded><![CDATA[Hello, I try to login to B16 default web UI (<a href="http://192.168.4.1/login.html" target="_blank" rel="noopener" class="mycode_url">http://192.168.4.1/login.html</a>) and enter admin/admin password.<br />
Receive Password incorrect error.<br />
I don't remember if I changed the password, so I need to reset it do default.<br />
Tried to push DL and Reset buttons for 10+ seconds, the device reboots, but admin/admin is still not correct.<br />
Also tried admin without a password, also tried admin/jingkong - still not getting access.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Reed water meter]]></title>
			<link>https://www.kincony.com/forum/showthread.php?tid=8677</link>
			<pubDate>Sat, 25 Oct 2025 13:42:50 +0800</pubDate>
			<dc:creator><![CDATA[<a href="https://www.kincony.com/forum/member.php?action=profile&uid=9750">mdiessner</a>]]></dc:creator>
			<guid isPermaLink="false">https://www.kincony.com/forum/showthread.php?tid=8677</guid>
			<description><![CDATA[I would like to use this product:<br />
<a href="https://www.kincony.com/esp32-s3-16ch-smart-relay-controller.html" target="_blank" rel="noopener" class="mycode_url">https://www.kincony.com/esp32-s3-16ch-sm...oller.html</a><br />
<br />
In order to read water meter<br />
<a href="https://www.transducers.co.za/media/1868/ttmjv-trantech-multijet-bulk-water-flow-meter.pdf" target="_blank" rel="noopener" class="mycode_url">https://www.transducers.co.za/media/1868...-meter.pdf</a><br />
<br />
Please advise if this is possible, it not what else to use?<br />
<br />
The idea is to count every pulse using the digital input, and increasing the count value and storing the value in case of reboot/power failure]]></description>
			<content:encoded><![CDATA[I would like to use this product:<br />
<a href="https://www.kincony.com/esp32-s3-16ch-smart-relay-controller.html" target="_blank" rel="noopener" class="mycode_url">https://www.kincony.com/esp32-s3-16ch-sm...oller.html</a><br />
<br />
In order to read water meter<br />
<a href="https://www.transducers.co.za/media/1868/ttmjv-trantech-multijet-bulk-water-flow-meter.pdf" target="_blank" rel="noopener" class="mycode_url">https://www.transducers.co.za/media/1868...-meter.pdf</a><br />
<br />
Please advise if this is possible, it not what else to use?<br />
<br />
The idea is to count every pulse using the digital input, and increasing the count value and storing the value in case of reboot/power failure]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[RTC Battery Holder]]></title>
			<link>https://www.kincony.com/forum/showthread.php?tid=8627</link>
			<pubDate>Sun, 05 Oct 2025 15:33:28 +0800</pubDate>
			<dc:creator><![CDATA[<a href="https://www.kincony.com/forum/member.php?action=profile&uid=9636">molelightn</a>]]></dc:creator>
			<guid isPermaLink="false">https://www.kincony.com/forum/showthread.php?tid=8627</guid>
			<description><![CDATA[Hi, <br />
<br />
may a stupid question, but what kind of cell i do have to use for KinCony B16 in the battery holder for the RTC Clock? <br />
Tested some small different ones but none of them fit really good. <br />
<br />
br mole]]></description>
			<content:encoded><![CDATA[Hi, <br />
<br />
may a stupid question, but what kind of cell i do have to use for KinCony B16 in the battery holder for the RTC Clock? <br />
Tested some small different ones but none of them fit really good. <br />
<br />
br mole]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[Does KCS v3 firmware for KC868-H16S3 support a 'delay' parameter in MQTT SET commands]]></title>
			<link>https://www.kincony.com/forum/showthread.php?tid=8167</link>
			<pubDate>Mon, 09 Jun 2025 14:21:03 +0800</pubDate>
			<dc:creator><![CDATA[<a href="https://www.kincony.com/forum/member.php?action=profile&uid=538">itzek</a>]]></dc:creator>
			<guid isPermaLink="false">https://www.kincony.com/forum/showthread.php?tid=8167</guid>
			<description><![CDATA[Hello admin<br />
I am using a B16 smart relay controller with your KCS v3 firmware. I am integrating it with Home Assistant to control a Somfy WT roller shutter.<br />
For this application, I need to send an MQTT command to activate a relay for a specific duration (e.g., "turn on output1 for 3 seconds, then turn it off automatically").<br />
I've reviewed the KCS v3 MQTT protocol document (specifically, section 1 about setting ON/OFF of a digital output channel). It shows how to turn relays ON or OFF: <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{"outputX":{"value":true}}</code></div></div> <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{"outputX":{"value":false}}</code></div></div>My question is: <span style="font-weight: bold;" class="mycode_b">Does KCS v3 firmware support an additional parameter like </span><br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{"delay": milliseconds}</code></div></div><span style="font-weight: bold;" class="mycode_b"> within the MQTT SET command, similar to how some other firmwares allow?</span><br />
For example, would a command like this work to turn on <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>output1</code></div></div> for 3 seconds and then automatically turn it off? <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{"output1":{"value":true}},{"delay":3000}</code></div></div>If not, what is the recommended method for implementing time-based relay control (e.g., activating a relay for a specific duration) when integrating with Home Assistant using KCS v3 firmware?<br />
Thank you for your assistance.]]></description>
			<content:encoded><![CDATA[Hello admin<br />
I am using a B16 smart relay controller with your KCS v3 firmware. I am integrating it with Home Assistant to control a Somfy WT roller shutter.<br />
For this application, I need to send an MQTT command to activate a relay for a specific duration (e.g., "turn on output1 for 3 seconds, then turn it off automatically").<br />
I've reviewed the KCS v3 MQTT protocol document (specifically, section 1 about setting ON/OFF of a digital output channel). It shows how to turn relays ON or OFF: <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{"outputX":{"value":true}}</code></div></div> <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{"outputX":{"value":false}}</code></div></div>My question is: <span style="font-weight: bold;" class="mycode_b">Does KCS v3 firmware support an additional parameter like </span><br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{"delay": milliseconds}</code></div></div><span style="font-weight: bold;" class="mycode_b"> within the MQTT SET command, similar to how some other firmwares allow?</span><br />
For example, would a command like this work to turn on <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>output1</code></div></div> for 3 seconds and then automatically turn it off? <br />
<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>{"output1":{"value":true}},{"delay":3000}</code></div></div>If not, what is the recommended method for implementing time-based relay control (e.g., activating a relay for a specific duration) when integrating with Home Assistant using KCS v3 firmware?<br />
Thank you for your assistance.]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[16B mqtt yaml file config how to]]></title>
			<link>https://www.kincony.com/forum/showthread.php?tid=8111</link>
			<pubDate>Sun, 25 May 2025 05:17:02 +0800</pubDate>
			<dc:creator><![CDATA[<a href="https://www.kincony.com/forum/member.php?action=profile&uid=538">itzek</a>]]></dc:creator>
			<guid isPermaLink="false">https://www.kincony.com/forum/showthread.php?tid=8111</guid>
			<description><![CDATA[Hello admin,<br />
 I have the B16 ESP32-S3 controller and I want to connect it to Home Assistant using a regular mqtt configuration (not using MQTT (For Home Assistant)). <br />
This is what I'm trying, but it's not working:<br />
    - name: " output-1 "<br />
      unique_id: output-1<br />
      state_topic: ' relay16/DCDA0C8B9B5C/state'<br />
      command_topic: ' relay16/DCDA0C8B9B5C/set'<br />
      payload_on:  '{"relay1":{"on":1}}'<br />
      payload_off:  '{"relay1":{"on":0}}'<br />
      value_template: '{{ value_json.relay1.on }}'<br />
      state_on: 1<br />
      state_off: 0<br />
<br />
Can you give me an example of the configuration?]]></description>
			<content:encoded><![CDATA[Hello admin,<br />
 I have the B16 ESP32-S3 controller and I want to connect it to Home Assistant using a regular mqtt configuration (not using MQTT (For Home Assistant)). <br />
This is what I'm trying, but it's not working:<br />
    - name: " output-1 "<br />
      unique_id: output-1<br />
      state_topic: ' relay16/DCDA0C8B9B5C/state'<br />
      command_topic: ' relay16/DCDA0C8B9B5C/set'<br />
      payload_on:  '{"relay1":{"on":1}}'<br />
      payload_off:  '{"relay1":{"on":0}}'<br />
      value_template: '{{ value_json.relay1.on }}'<br />
      state_on: 1<br />
      state_off: 0<br />
<br />
Can you give me an example of the configuration?]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[[arduino code examples for B16]-11 digital INPUT trigger OUTPUT directly]]></title>
			<link>https://www.kincony.com/forum/showthread.php?tid=7685</link>
			<pubDate>Sat, 22 Feb 2025 10:12:48 +0800</pubDate>
			<dc:creator><![CDATA[<a href="https://www.kincony.com/forum/member.php?action=profile&uid=1">admin</a>]]></dc:creator>
			<guid isPermaLink="false">https://www.kincony.com/forum/showthread.php?tid=7685</guid>
			<description><![CDATA[<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>/*<br />
 * Made by KinCony IoT: https://www.kincony.com<br />
 *<br />
 * This program reads 16 input states from a PCF8575 I/O expander and <br />
 * controls a corresponding 16-channel relay module. When an input pin <br />
 * is LOW, the corresponding relay is turned ON (LOW means ON for the relay).<br />
 * When the input pin is HIGH, the corresponding relay is turned OFF.<br />
 *<br />
 * Pin Definitions:<br />
 * - SDA: GPIO 8<br />
 * - SCL: GPIO 18<br />
 * - Input I2C Address: 0x24<br />
 * - Relay I2C Address: 0x25<br />
 */<br />
<br />
#include &lt;Wire.h&gt;        // I2C communication<br />
#include &lt;PCF8575.h&gt;   &nbsp;&nbsp;// Library to control the PCF8575 I/O expander<br />
<br />
// Define I2C pins<br />
#define SDA 8         &nbsp;&nbsp;// SDA pin<br />
#define SCL 18         &nbsp;&nbsp;// SCL pin<br />
<br />
// I2C addresses<br />
#define INPUT_I2C_ADDRESS 0x24 &nbsp;&nbsp;// I2C address for the input PCF8575 module<br />
#define RELAY_I2C_ADDRESS 0x22 &nbsp;&nbsp;// I2C address for the relay PCF8575 module<br />
<br />
PCF8575 pcf8575_IN(INPUT_I2C_ADDRESS);    // Create an object for the input PCF8575<br />
PCF8575 pcf8575_RL(RELAY_I2C_ADDRESS);    // Create an object for the relay PCF8575<br />
<br />
void setup() {<br />
  // Initialize I2C communication<br />
  Wire.begin(SDA, SCL);<br />
  <br />
  // Initialize serial communication<br />
  Serial.begin(115200);<br />
  <br />
  // Initialize input and relay modules<br />
  pcf8575_IN.begin();<br />
  pcf8575_RL.begin();<br />
  <br />
  // Turn off all relays at the start<br />
  for (int i = 0; i &lt; 16; i++) {<br />
    pcf8575_RL.write(i, LOW);  // Assuming relays are LOW when OFF, setting all relays to OFF initially<br />
  }<br />
  <br />
  Serial.println("System started: Input state controlling 16 relays");<br />
}<br />
<br />
void loop() {<br />
  uint16_t inputState = 0;<br />
<br />
  // Read the state of 16 inputs<br />
  for (int i = 0; i &lt; 16; i++) {<br />
    if (pcf8575_IN.read(i)) {<br />
      inputState |= (1 &lt;&lt; i);  // If input is HIGH, set the corresponding bit<br />
    } else {<br />
      inputState &amp;= ~(1 &lt;&lt; i); // Otherwise, clear the corresponding bit<br />
    }<br />
  }<br />
  <br />
  // Control the relays based on the input state<br />
  for (int i = 0; i &lt; 16; i++) {<br />
    if (inputState &amp; (1 &lt;&lt; i)) {<br />
      pcf8575_RL.write(i, HIGH);  // If input is HIGH, turn the relay OFF<br />
    } else {<br />
      pcf8575_RL.write(i, LOW); &nbsp;&nbsp;// If input is LOW, turn the relay ON<br />
    }<br />
  }<br />
<br />
  // Delay for 500 milliseconds<br />
  delay(500);<br />
}</code></div></div> arduino ino file download:  <br />
<!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/zip.png" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=7181" target="_blank" title="">11-input-trigger-output.zip</a> (Size: 1.02 KB / Downloads: 462)
<!-- end: postbit_attachments_attachment --><br />
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download: <br />
<!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/zip.png" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=7182" target="_blank" title="">11-input-trigger-output.ino.merged.zip</a> (Size: 189.4 KB / Downloads: 504)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>/*<br />
 * Made by KinCony IoT: https://www.kincony.com<br />
 *<br />
 * This program reads 16 input states from a PCF8575 I/O expander and <br />
 * controls a corresponding 16-channel relay module. When an input pin <br />
 * is LOW, the corresponding relay is turned ON (LOW means ON for the relay).<br />
 * When the input pin is HIGH, the corresponding relay is turned OFF.<br />
 *<br />
 * Pin Definitions:<br />
 * - SDA: GPIO 8<br />
 * - SCL: GPIO 18<br />
 * - Input I2C Address: 0x24<br />
 * - Relay I2C Address: 0x25<br />
 */<br />
<br />
#include &lt;Wire.h&gt;        // I2C communication<br />
#include &lt;PCF8575.h&gt;   &nbsp;&nbsp;// Library to control the PCF8575 I/O expander<br />
<br />
// Define I2C pins<br />
#define SDA 8         &nbsp;&nbsp;// SDA pin<br />
#define SCL 18         &nbsp;&nbsp;// SCL pin<br />
<br />
// I2C addresses<br />
#define INPUT_I2C_ADDRESS 0x24 &nbsp;&nbsp;// I2C address for the input PCF8575 module<br />
#define RELAY_I2C_ADDRESS 0x22 &nbsp;&nbsp;// I2C address for the relay PCF8575 module<br />
<br />
PCF8575 pcf8575_IN(INPUT_I2C_ADDRESS);    // Create an object for the input PCF8575<br />
PCF8575 pcf8575_RL(RELAY_I2C_ADDRESS);    // Create an object for the relay PCF8575<br />
<br />
void setup() {<br />
  // Initialize I2C communication<br />
  Wire.begin(SDA, SCL);<br />
  <br />
  // Initialize serial communication<br />
  Serial.begin(115200);<br />
  <br />
  // Initialize input and relay modules<br />
  pcf8575_IN.begin();<br />
  pcf8575_RL.begin();<br />
  <br />
  // Turn off all relays at the start<br />
  for (int i = 0; i &lt; 16; i++) {<br />
    pcf8575_RL.write(i, LOW);  // Assuming relays are LOW when OFF, setting all relays to OFF initially<br />
  }<br />
  <br />
  Serial.println("System started: Input state controlling 16 relays");<br />
}<br />
<br />
void loop() {<br />
  uint16_t inputState = 0;<br />
<br />
  // Read the state of 16 inputs<br />
  for (int i = 0; i &lt; 16; i++) {<br />
    if (pcf8575_IN.read(i)) {<br />
      inputState |= (1 &lt;&lt; i);  // If input is HIGH, set the corresponding bit<br />
    } else {<br />
      inputState &amp;= ~(1 &lt;&lt; i); // Otherwise, clear the corresponding bit<br />
    }<br />
  }<br />
  <br />
  // Control the relays based on the input state<br />
  for (int i = 0; i &lt; 16; i++) {<br />
    if (inputState &amp; (1 &lt;&lt; i)) {<br />
      pcf8575_RL.write(i, HIGH);  // If input is HIGH, turn the relay OFF<br />
    } else {<br />
      pcf8575_RL.write(i, LOW); &nbsp;&nbsp;// If input is LOW, turn the relay ON<br />
    }<br />
  }<br />
<br />
  // Delay for 500 milliseconds<br />
  delay(500);<br />
}</code></div></div> arduino ino file download:  <br />
<!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/zip.png" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=7181" target="_blank" title="">11-input-trigger-output.zip</a> (Size: 1.02 KB / Downloads: 462)
<!-- end: postbit_attachments_attachment --><br />
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download: <br />
<!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/zip.png" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=7182" target="_blank" title="">11-input-trigger-output.ino.merged.zip</a> (Size: 189.4 KB / Downloads: 504)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[[arduino code examples for B16]-10 Print TEXT on SSD1306 OLED displayer]]></title>
			<link>https://www.kincony.com/forum/showthread.php?tid=7684</link>
			<pubDate>Sat, 22 Feb 2025 10:10:15 +0800</pubDate>
			<dc:creator><![CDATA[<a href="https://www.kincony.com/forum/member.php?action=profile&uid=1">admin</a>]]></dc:creator>
			<guid isPermaLink="false">https://www.kincony.com/forum/showthread.php?tid=7684</guid>
			<description><![CDATA[<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>/*<br />
 * Made by KinCony IoT: https://www.kincony.com<br />
 * <br />
 * This Arduino program demonstrates how to display text on an SSD1306 128x64 OLED display using the U8g2 library.<br />
 * The program draws two lines of text on the display:<br />
 * - The first line is "KINCONY" in a larger font.<br />
 * - The second line is "www.kincony.com" in a smaller font.<br />
 * <br />
 * The display is connected via I2C (software implementation) with:<br />
 * - SCL (clock) on pin IO18<br />
 * - SDA (data) on pin IO8<br />
 * <br />
 * The display's I2C address is set to 0x3C.<br />
 */<br />
<br />
#include &lt;U8g2lib.h&gt;  // Include the U8g2 library for controlling the OLED display<br />
#include &lt;Wire.h&gt;   &nbsp;&nbsp;// Include the Wire library for I2C communication<br />
<br />
// Initialize the display using the software I2C method (SCL = IO39, SDA = IO38)<br />
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0,  18, 8, U8X8_PIN_NONE);  // Screen rotation: U8G2_R0<br />
<br />
// Function to display page 1 content<br />
void page1() {<br />
  // Set font size 18 for the larger "KINCONY" text<br />
  u8g2.setFont(u8g2_font_timR18_tf);  // Use the Times Roman font, size 18<br />
  u8g2.setFontPosTop();             &nbsp;&nbsp;// Set the text position at the top of the display<br />
  u8g2.setCursor(5, 0);             &nbsp;&nbsp;// Position the cursor at coordinates (5, 0)<br />
  u8g2.print("KINCONY");              // Display the text "KINCONY" on the screen<br />
<br />
  // Set font size 12 for the smaller "www.kincony.com" text<br />
  u8g2.setFont(u8g2_font_timR12_tf);  // Use the Times Roman font, size 12<br />
  u8g2.setCursor(0, 40);              // Position the cursor at coordinates (0, 40)<br />
  u8g2.print("www.kincony.com");      // Display the text "www.kincony.com"<br />
}<br />
<br />
// Setup function, runs once when the program starts<br />
void setup() {<br />
  // Set the I2C address for the display to 0x3C<br />
  u8g2.setI2CAddress(0x3C*2);  // I2C address shift for 8-bit format<br />
  <br />
  // Initialize the display<br />
  u8g2.begin();<br />
  <br />
  // Enable UTF-8 character printing for the display<br />
  u8g2.enableUTF8Print();  // Allow UTF-8 encoded text to be printed<br />
}<br />
<br />
// Main loop function, continuously runs after setup()<br />
void loop() {<br />
  // Begin the display drawing process<br />
  u8g2.firstPage();  // Prepare the first page for drawing<br />
  do {<br />
    // Call the page1() function to draw content on the display<br />
    page1();<br />
  } while (u8g2.nextPage());  // Continue to the next page until all pages are drawn<br />
}</code></div></div> arduino ino file download:  <!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/zip.png" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=7179" target="_blank" title="">10-oled-ssd1306.zip</a> (Size: 1.12 KB / Downloads: 477)
<!-- end: postbit_attachments_attachment --><br />
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download: <br />
<!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/zip.png" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=7180" target="_blank" title="">10-oled-ssd1306.ino.merged.zip</a> (Size: 201.24 KB / Downloads: 462)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>/*<br />
 * Made by KinCony IoT: https://www.kincony.com<br />
 * <br />
 * This Arduino program demonstrates how to display text on an SSD1306 128x64 OLED display using the U8g2 library.<br />
 * The program draws two lines of text on the display:<br />
 * - The first line is "KINCONY" in a larger font.<br />
 * - The second line is "www.kincony.com" in a smaller font.<br />
 * <br />
 * The display is connected via I2C (software implementation) with:<br />
 * - SCL (clock) on pin IO18<br />
 * - SDA (data) on pin IO8<br />
 * <br />
 * The display's I2C address is set to 0x3C.<br />
 */<br />
<br />
#include &lt;U8g2lib.h&gt;  // Include the U8g2 library for controlling the OLED display<br />
#include &lt;Wire.h&gt;   &nbsp;&nbsp;// Include the Wire library for I2C communication<br />
<br />
// Initialize the display using the software I2C method (SCL = IO39, SDA = IO38)<br />
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0,  18, 8, U8X8_PIN_NONE);  // Screen rotation: U8G2_R0<br />
<br />
// Function to display page 1 content<br />
void page1() {<br />
  // Set font size 18 for the larger "KINCONY" text<br />
  u8g2.setFont(u8g2_font_timR18_tf);  // Use the Times Roman font, size 18<br />
  u8g2.setFontPosTop();             &nbsp;&nbsp;// Set the text position at the top of the display<br />
  u8g2.setCursor(5, 0);             &nbsp;&nbsp;// Position the cursor at coordinates (5, 0)<br />
  u8g2.print("KINCONY");              // Display the text "KINCONY" on the screen<br />
<br />
  // Set font size 12 for the smaller "www.kincony.com" text<br />
  u8g2.setFont(u8g2_font_timR12_tf);  // Use the Times Roman font, size 12<br />
  u8g2.setCursor(0, 40);              // Position the cursor at coordinates (0, 40)<br />
  u8g2.print("www.kincony.com");      // Display the text "www.kincony.com"<br />
}<br />
<br />
// Setup function, runs once when the program starts<br />
void setup() {<br />
  // Set the I2C address for the display to 0x3C<br />
  u8g2.setI2CAddress(0x3C*2);  // I2C address shift for 8-bit format<br />
  <br />
  // Initialize the display<br />
  u8g2.begin();<br />
  <br />
  // Enable UTF-8 character printing for the display<br />
  u8g2.enableUTF8Print();  // Allow UTF-8 encoded text to be printed<br />
}<br />
<br />
// Main loop function, continuously runs after setup()<br />
void loop() {<br />
  // Begin the display drawing process<br />
  u8g2.firstPage();  // Prepare the first page for drawing<br />
  do {<br />
    // Call the page1() function to draw content on the display<br />
    page1();<br />
  } while (u8g2.nextPage());  // Continue to the next page until all pages are drawn<br />
}</code></div></div> arduino ino file download:  <!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/zip.png" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=7179" target="_blank" title="">10-oled-ssd1306.zip</a> (Size: 1.12 KB / Downloads: 477)
<!-- end: postbit_attachments_attachment --><br />
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download: <br />
<!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/zip.png" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=7180" target="_blank" title="">10-oled-ssd1306.ino.merged.zip</a> (Size: 201.24 KB / Downloads: 462)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[[arduino code examples for B16]-09 how to communication with Tuya WiFi module]]></title>
			<link>https://www.kincony.com/forum/showthread.php?tid=7683</link>
			<pubDate>Sat, 22 Feb 2025 10:08:53 +0800</pubDate>
			<dc:creator><![CDATA[<a href="https://www.kincony.com/forum/member.php?action=profile&uid=1">admin</a>]]></dc:creator>
			<guid isPermaLink="false">https://www.kincony.com/forum/showthread.php?tid=7683</guid>
			<description><![CDATA[<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>/*<br />
 * Made by KinCony IoT: https://www.kincony.com<br />
 * <br />
 * This Arduino program implements communication between ESP32 and the Tuya module<br />
 * via UART (serial communication). It listens for specific packets from the Tuya module<br />
 * and responds according to the predefined commands.<br />
 * <br />
 * Functionality:<br />
 * 1. When the ESP32 receives a heartbeat packet (55 AA 00 00 00 00 FF),<br />
 *    it sends a heartbeat response (55 AA 03 00 00 01 00 03).<br />
 * 2. When the ESP32 receives a product information request (55 AA 00 01 00 00 00),<br />
 *    it sends a product information response (55 AA 03 01 ...).<br />
 * 3. When the ESP32 receives a work mode request (55 AA 00 02 00 00 01),<br />
 *    it sends a work mode response (55 AA 03 02 00 03 10 1C 14 47).<br />
 * 4. When the ESP32 receives a network status request (55 AA 00 03 00 01 00 03),<br />
 *    it sends a network status response (55 AA 03 03 00 00 05).<br />
 * 5. Subsequent heartbeat packets (55 AA 00 00 00 00 FF) are responded to with<br />
 *    (55 AA 03 00 00 01 01 04).<br />
 */<br />
<br />
#include &lt;HardwareSerial.h&gt;<br />
<br />
// Create a HardwareSerial object for UART communication on ESP32<br />
HardwareSerial tuyaSerial(1);<br />
<br />
// Define the GPIO pins for TXD and RXD used for serial communication<br />
#define TXD_PIN 16<br />
#define RXD_PIN 17<br />
<br />
// Set the baud rate for Tuya module communication to 9600<br />
#define BAUD_RATE 9600<br />
<br />
// Define the response packets for different commands from the Tuya module<br />
<br />
// Heartbeat response: 55 AA 03 00 00 01 00 03<br />
uint8_t heartBeatResponse[] = {0x55, 0xAA, 0x03, 0x00, 0x00, 0x01, 0x00, 0x03};<br />
<br />
// Product info response with a detailed payload (e.g., firmware version, product name, etc.)<br />
uint8_t productInfoResponse[] = {<br />
  0x55, 0xAA, 0x03, 0x01, 0x00, 0x2A, 0x7B, 0x22, 0x70, 0x22, 0x3A, 0x22, <br />
  0x63, 0x68, 0x6D, 0x7A, 0x6C, 0x67, 0x6A, 0x70, 0x61, 0x64, 0x70, 0x71, <br />
  0x78, 0x64, 0x6B, 0x6F, 0x22, 0x2C, 0x22, 0x76, 0x22, 0x3A, 0x22, 0x31, <br />
  0x2E, 0x30, 0x2E, 0x30, 0x22, 0x2C, 0x22, 0x6D, 0x22, 0x3A, 0x30, 0x7D, 0xAA<br />
};<br />
<br />
// Work mode response: 55 AA 03 02 00 03 10 1C 14 47<br />
uint8_t workModeResponse[] = {0x55, 0xAA, 0x03, 0x02, 0x00, 0x03, 0x10, 0x1C, 0x14, 0x47};<br />
<br />
// Network status response: 55 AA 03 03 00 00 05<br />
uint8_t netStatusResponse[] = {0x55, 0xAA, 0x03, 0x03, 0x00, 0x00, 0x05};<br />
<br />
// Subsequent heartbeat response: 55 AA 03 00 00 01 01 04<br />
uint8_t secondHeartBeatResponse[] = {0x55, 0xAA, 0x03, 0x00, 0x00, 0x01, 0x01, 0x04};<br />
<br />
void setup() {<br />
  // Initialize the serial communication for debugging at 115200 baud rate<br />
  Serial.begin(115200);<br />
<br />
  // Initialize the serial communication with Tuya module at 9600 baud rate<br />
  tuyaSerial.begin(BAUD_RATE, SERIAL_8N1, RXD_PIN, TXD_PIN);<br />
<br />
  // Debug message to indicate that the serial communication has been initialized<br />
  Serial.println("ESP32-Tuya serial communication initialized.");<br />
}<br />
<br />
void loop() {<br />
  // Check if data is available from the Tuya module<br />
  if (tuyaSerial.available()) {<br />
    uint8_t incomingPacket[7];  // Array to store the received packet<br />
    size_t bytesRead = tuyaSerial.readBytes(incomingPacket, 7); // Read 7 bytes from Tuya<br />
<br />
    // Check if the packet has a valid header (0x55, 0xAA)<br />
    if (bytesRead &gt;= 2 &amp;&amp; incomingPacket[0] == 0x55 &amp;&amp; incomingPacket[1] == 0xAA) {<br />
      // If less than 7 bytes were received, wait for more data<br />
      if (bytesRead &lt; 7) {<br />
        Serial.println("Incomplete packet received. Waiting for remaining bytes...");<br />
        delay(50); // Delay to allow more data to be received<br />
        while (tuyaSerial.available()) {<br />
          incomingPacket[bytesRead++] = tuyaSerial.read(); // Continue reading remaining bytes<br />
          if (bytesRead &gt;= 7) break;<br />
        }<br />
      }<br />
<br />
      // If still less than 7 bytes, discard the incomplete packet<br />
      if (bytesRead &lt; 7) {<br />
        Serial.println("Error: Incomplete packet discarded.");<br />
        return;<br />
      }<br />
<br />
      // Debug: Print the received packet for logging<br />
      Serial.print("Received packet: ");<br />
      for (size_t i = 0; i &lt; 7; i++) {<br />
        Serial.print(incomingPacket[i], HEX);<br />
        Serial.print(" ");<br />
      }<br />
      Serial.println();<br />
<br />
      // Call the function to process the received packet<br />
      processTuyaPacket(incomingPacket, 7);<br />
<br />
    } else {<br />
      // If the header is invalid, discard the packet and flush the buffer<br />
      Serial.print("Error: Invalid packet header. Data received: ");<br />
      for (size_t i = 0; i &lt; bytesRead; i++) {<br />
        Serial.print(incomingPacket[i], HEX);<br />
        Serial.print(" ");<br />
      }<br />
      Serial.println();<br />
      tuyaSerial.flush(); // Clear the serial buffer<br />
    }<br />
  }<br />
<br />
  // Delay to avoid CPU overuse<br />
  delay(100);<br />
}<br />
<br />
// Function to process the received packet and send the appropriate response<br />
void processTuyaPacket(uint8_t* packet, size_t size) {<br />
  // Ensure the packet size is 7 and the header is valid<br />
  if (size == 7 &amp;&amp; packet[0] == 0x55 &amp;&amp; packet[1] == 0xAA) {<br />
    // Determine the command in the packet (packet[2])<br />
    switch(packet[2]) {<br />
      case 0x00:<br />
        if (packet[3] == 0x00 &amp;&amp; packet[4] == 0x00 &amp;&amp; packet[5] == 0x00 &amp;&amp; packet[6] == 0xFF) {<br />
          Serial.println("Heartbeat received.");<br />
          sendPacket(heartBeatResponse, sizeof(heartBeatResponse));<br />
        } else if (packet[3] == 0x01 &amp;&amp; packet[4] == 0x00 &amp;&amp; packet[5] == 0x00 &amp;&amp; packet[6] == 0x00) {<br />
          Serial.println("Product info request received.");<br />
          sendPacket(productInfoResponse, sizeof(productInfoResponse));<br />
        } else if (packet[3] == 0x02 &amp;&amp; packet[4] == 0x00 &amp;&amp; packet[5] == 0x00 &amp;&amp; packet[6] == 0x01) {<br />
          Serial.println("Work mode request received.");<br />
          sendPacket(workModeResponse, sizeof(workModeResponse));<br />
        } else if (packet[3] == 0x03 &amp;&amp; packet[4] == 0x00 &amp;&amp; packet[5] == 0x01 &amp;&amp; packet[6] == 0x00) {<br />
          Serial.println("Network status request received.");<br />
          sendPacket(netStatusResponse, sizeof(netStatusResponse));<br />
        }<br />
        break;<br />
<br />
      default:<br />
        Serial.println("Error: Unhandled command received.");<br />
        break;<br />
    }<br />
  }<br />
}<br />
<br />
// Function to send the response packet to the Tuya module<br />
void sendPacket(uint8_t* packet, size_t size) {<br />
  // Send the packet via UART to Tuya module<br />
  tuyaSerial.write(packet, size);<br />
<br />
  // Debug: Print the sent packet for logging<br />
  Serial.print("Sent packet: ");<br />
  for (size_t i = 0; i &lt; size; i++) {<br />
    Serial.print(packet[i], HEX);<br />
    Serial.print(" ");<br />
  }<br />
  Serial.println();<br />
}</code></div></div> arduino ino file download:  <br />
<!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/zip.png" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=7177" target="_blank" title="">9-tuya-wifi-config.zip</a> (Size: 2 KB / Downloads: 468)
<!-- end: postbit_attachments_attachment --><br />
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download: <br />
<!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/zip.png" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=7178" target="_blank" title="">9-tuya-wifi-config.ino.merged.zip</a> (Size: 184.93 KB / Downloads: 445)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>/*<br />
 * Made by KinCony IoT: https://www.kincony.com<br />
 * <br />
 * This Arduino program implements communication between ESP32 and the Tuya module<br />
 * via UART (serial communication). It listens for specific packets from the Tuya module<br />
 * and responds according to the predefined commands.<br />
 * <br />
 * Functionality:<br />
 * 1. When the ESP32 receives a heartbeat packet (55 AA 00 00 00 00 FF),<br />
 *    it sends a heartbeat response (55 AA 03 00 00 01 00 03).<br />
 * 2. When the ESP32 receives a product information request (55 AA 00 01 00 00 00),<br />
 *    it sends a product information response (55 AA 03 01 ...).<br />
 * 3. When the ESP32 receives a work mode request (55 AA 00 02 00 00 01),<br />
 *    it sends a work mode response (55 AA 03 02 00 03 10 1C 14 47).<br />
 * 4. When the ESP32 receives a network status request (55 AA 00 03 00 01 00 03),<br />
 *    it sends a network status response (55 AA 03 03 00 00 05).<br />
 * 5. Subsequent heartbeat packets (55 AA 00 00 00 00 FF) are responded to with<br />
 *    (55 AA 03 00 00 01 01 04).<br />
 */<br />
<br />
#include &lt;HardwareSerial.h&gt;<br />
<br />
// Create a HardwareSerial object for UART communication on ESP32<br />
HardwareSerial tuyaSerial(1);<br />
<br />
// Define the GPIO pins for TXD and RXD used for serial communication<br />
#define TXD_PIN 16<br />
#define RXD_PIN 17<br />
<br />
// Set the baud rate for Tuya module communication to 9600<br />
#define BAUD_RATE 9600<br />
<br />
// Define the response packets for different commands from the Tuya module<br />
<br />
// Heartbeat response: 55 AA 03 00 00 01 00 03<br />
uint8_t heartBeatResponse[] = {0x55, 0xAA, 0x03, 0x00, 0x00, 0x01, 0x00, 0x03};<br />
<br />
// Product info response with a detailed payload (e.g., firmware version, product name, etc.)<br />
uint8_t productInfoResponse[] = {<br />
  0x55, 0xAA, 0x03, 0x01, 0x00, 0x2A, 0x7B, 0x22, 0x70, 0x22, 0x3A, 0x22, <br />
  0x63, 0x68, 0x6D, 0x7A, 0x6C, 0x67, 0x6A, 0x70, 0x61, 0x64, 0x70, 0x71, <br />
  0x78, 0x64, 0x6B, 0x6F, 0x22, 0x2C, 0x22, 0x76, 0x22, 0x3A, 0x22, 0x31, <br />
  0x2E, 0x30, 0x2E, 0x30, 0x22, 0x2C, 0x22, 0x6D, 0x22, 0x3A, 0x30, 0x7D, 0xAA<br />
};<br />
<br />
// Work mode response: 55 AA 03 02 00 03 10 1C 14 47<br />
uint8_t workModeResponse[] = {0x55, 0xAA, 0x03, 0x02, 0x00, 0x03, 0x10, 0x1C, 0x14, 0x47};<br />
<br />
// Network status response: 55 AA 03 03 00 00 05<br />
uint8_t netStatusResponse[] = {0x55, 0xAA, 0x03, 0x03, 0x00, 0x00, 0x05};<br />
<br />
// Subsequent heartbeat response: 55 AA 03 00 00 01 01 04<br />
uint8_t secondHeartBeatResponse[] = {0x55, 0xAA, 0x03, 0x00, 0x00, 0x01, 0x01, 0x04};<br />
<br />
void setup() {<br />
  // Initialize the serial communication for debugging at 115200 baud rate<br />
  Serial.begin(115200);<br />
<br />
  // Initialize the serial communication with Tuya module at 9600 baud rate<br />
  tuyaSerial.begin(BAUD_RATE, SERIAL_8N1, RXD_PIN, TXD_PIN);<br />
<br />
  // Debug message to indicate that the serial communication has been initialized<br />
  Serial.println("ESP32-Tuya serial communication initialized.");<br />
}<br />
<br />
void loop() {<br />
  // Check if data is available from the Tuya module<br />
  if (tuyaSerial.available()) {<br />
    uint8_t incomingPacket[7];  // Array to store the received packet<br />
    size_t bytesRead = tuyaSerial.readBytes(incomingPacket, 7); // Read 7 bytes from Tuya<br />
<br />
    // Check if the packet has a valid header (0x55, 0xAA)<br />
    if (bytesRead &gt;= 2 &amp;&amp; incomingPacket[0] == 0x55 &amp;&amp; incomingPacket[1] == 0xAA) {<br />
      // If less than 7 bytes were received, wait for more data<br />
      if (bytesRead &lt; 7) {<br />
        Serial.println("Incomplete packet received. Waiting for remaining bytes...");<br />
        delay(50); // Delay to allow more data to be received<br />
        while (tuyaSerial.available()) {<br />
          incomingPacket[bytesRead++] = tuyaSerial.read(); // Continue reading remaining bytes<br />
          if (bytesRead &gt;= 7) break;<br />
        }<br />
      }<br />
<br />
      // If still less than 7 bytes, discard the incomplete packet<br />
      if (bytesRead &lt; 7) {<br />
        Serial.println("Error: Incomplete packet discarded.");<br />
        return;<br />
      }<br />
<br />
      // Debug: Print the received packet for logging<br />
      Serial.print("Received packet: ");<br />
      for (size_t i = 0; i &lt; 7; i++) {<br />
        Serial.print(incomingPacket[i], HEX);<br />
        Serial.print(" ");<br />
      }<br />
      Serial.println();<br />
<br />
      // Call the function to process the received packet<br />
      processTuyaPacket(incomingPacket, 7);<br />
<br />
    } else {<br />
      // If the header is invalid, discard the packet and flush the buffer<br />
      Serial.print("Error: Invalid packet header. Data received: ");<br />
      for (size_t i = 0; i &lt; bytesRead; i++) {<br />
        Serial.print(incomingPacket[i], HEX);<br />
        Serial.print(" ");<br />
      }<br />
      Serial.println();<br />
      tuyaSerial.flush(); // Clear the serial buffer<br />
    }<br />
  }<br />
<br />
  // Delay to avoid CPU overuse<br />
  delay(100);<br />
}<br />
<br />
// Function to process the received packet and send the appropriate response<br />
void processTuyaPacket(uint8_t* packet, size_t size) {<br />
  // Ensure the packet size is 7 and the header is valid<br />
  if (size == 7 &amp;&amp; packet[0] == 0x55 &amp;&amp; packet[1] == 0xAA) {<br />
    // Determine the command in the packet (packet[2])<br />
    switch(packet[2]) {<br />
      case 0x00:<br />
        if (packet[3] == 0x00 &amp;&amp; packet[4] == 0x00 &amp;&amp; packet[5] == 0x00 &amp;&amp; packet[6] == 0xFF) {<br />
          Serial.println("Heartbeat received.");<br />
          sendPacket(heartBeatResponse, sizeof(heartBeatResponse));<br />
        } else if (packet[3] == 0x01 &amp;&amp; packet[4] == 0x00 &amp;&amp; packet[5] == 0x00 &amp;&amp; packet[6] == 0x00) {<br />
          Serial.println("Product info request received.");<br />
          sendPacket(productInfoResponse, sizeof(productInfoResponse));<br />
        } else if (packet[3] == 0x02 &amp;&amp; packet[4] == 0x00 &amp;&amp; packet[5] == 0x00 &amp;&amp; packet[6] == 0x01) {<br />
          Serial.println("Work mode request received.");<br />
          sendPacket(workModeResponse, sizeof(workModeResponse));<br />
        } else if (packet[3] == 0x03 &amp;&amp; packet[4] == 0x00 &amp;&amp; packet[5] == 0x01 &amp;&amp; packet[6] == 0x00) {<br />
          Serial.println("Network status request received.");<br />
          sendPacket(netStatusResponse, sizeof(netStatusResponse));<br />
        }<br />
        break;<br />
<br />
      default:<br />
        Serial.println("Error: Unhandled command received.");<br />
        break;<br />
    }<br />
  }<br />
}<br />
<br />
// Function to send the response packet to the Tuya module<br />
void sendPacket(uint8_t* packet, size_t size) {<br />
  // Send the packet via UART to Tuya module<br />
  tuyaSerial.write(packet, size);<br />
<br />
  // Debug: Print the sent packet for logging<br />
  Serial.print("Sent packet: ");<br />
  for (size_t i = 0; i &lt; size; i++) {<br />
    Serial.print(packet[i], HEX);<br />
    Serial.print(" ");<br />
  }<br />
  Serial.println();<br />
}</code></div></div> arduino ino file download:  <br />
<!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/zip.png" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=7177" target="_blank" title="">9-tuya-wifi-config.zip</a> (Size: 2 KB / Downloads: 468)
<!-- end: postbit_attachments_attachment --><br />
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download: <br />
<!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/zip.png" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=7178" target="_blank" title="">9-tuya-wifi-config.ino.merged.zip</a> (Size: 184.93 KB / Downloads: 445)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[[arduino code examples for B16]-08 Ethernet W5500 chip work with TCP Server mode]]></title>
			<link>https://www.kincony.com/forum/showthread.php?tid=7682</link>
			<pubDate>Sat, 22 Feb 2025 10:07:31 +0800</pubDate>
			<dc:creator><![CDATA[<a href="https://www.kincony.com/forum/member.php?action=profile&uid=1">admin</a>]]></dc:creator>
			<guid isPermaLink="false">https://www.kincony.com/forum/showthread.php?tid=7682</guid>
			<description><![CDATA[<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>/*<br />
 * Made by KinCony IoT: https://www.kincony.com<br />
 *<br />
 * This Arduino program sets up an ESP32-S3 with a W5500 Ethernet module<br />
 * as a TCP server. It listens on port 4196 and echoes back any string <br />
 * received from a client.<br />
 *<br />
 * Hardware connections:<br />
 * - CLK: GPIO1<br />
 * - MOSI: GPIO2<br />
 * - MISO: GPIO41<br />
 * - CS: GPIO42<br />
 * - RST: GPIO44<br />
 * - INT: GPIO43<br />
 *<br />
 * Static IP address: 192.168.3.55<br />
 * Subnet Mask: 255.255.255.0<br />
 * Gateway: 192.168.3.1<br />
 * DNS: 192.168.3.1<br />
 */<br />
<br />
#include &lt;SPI.h&gt;<br />
#include &lt;Ethernet.h&gt;<br />
<br />
// Define the W5500 Ethernet module pins<br />
#define W5500_CS_PIN  42<br />
#define W5500_RST_PIN 44<br />
#define W5500_INT_PIN 43<br />
#define W5500_CLK_PIN 1<br />
#define W5500_MOSI_PIN 2<br />
#define W5500_MISO_PIN 41<br />
<br />
// MAC address for your Ethernet shield (must be unique on your network)<br />
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };<br />
<br />
// Static IP address configuration<br />
IPAddress ip(192, 168, 3, 55);     &nbsp;&nbsp;// Static IP address<br />
IPAddress subnet(255, 255, 255, 0); &nbsp;&nbsp;// Subnet mask<br />
IPAddress gateway(192, 168, 3, 1);    // Default gateway<br />
IPAddress dns(192, 168, 3, 1);        // DNS server address<br />
<br />
// Create an EthernetServer object to handle TCP connections<br />
EthernetServer server(4196);<br />
<br />
void setup() {<br />
  // Initialize serial communication<br />
  Serial.begin(115200);<br />
  while (!Serial) {<br />
    ; // Wait for serial port to connect<br />
  }<br />
<br />
  // Initialize the W5500 module<br />
  pinMode(W5500_RST_PIN, OUTPUT);<br />
  pinMode(W5500_INT_PIN, INPUT);<br />
  digitalWrite(W5500_RST_PIN, LOW);  // Reset the W5500 module<br />
  delay(100);                     &nbsp;&nbsp;// Wait for reset to complete<br />
  digitalWrite(W5500_RST_PIN, HIGH); // Release reset<br />
<br />
  // Initialize SPI with the correct pin definitions<br />
  SPI.begin(W5500_CLK_PIN, W5500_MISO_PIN, W5500_MOSI_PIN);<br />
<br />
  // Set up the Ethernet library with W5500-specific pins<br />
  Ethernet.init(W5500_CS_PIN);<br />
<br />
  // Start the Ethernet connection with static IP configuration<br />
  Ethernet.begin(mac, ip, dns, gateway, subnet);<br />
<br />
  // Print the IP address to the serial monitor<br />
  Serial.print("IP Address: ");<br />
  Serial.println(Ethernet.localIP());<br />
<br />
  // Start listening for incoming TCP connections<br />
  server.begin();<br />
}<br />
<br />
void loop() {<br />
  // Check for incoming client connections<br />
  EthernetClient client = server.available();<br />
  if (client) {<br />
    Serial.println("New client connected");<br />
<br />
    // Read data from the client and echo it back<br />
    while (client.connected()) {<br />
      if (client.available()) {<br />
        char c = client.read();<br />
        server.write(c);<br />
      }<br />
    }<br />
<br />
    // Close the connection when done<br />
    client.stop();<br />
    Serial.println("Client disconnected");<br />
  }<br />
}</code></div></div> arduino ino file download:  <!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/zip.png" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=7176" target="_blank" title="">8-Ethernet-W5500.ino.merged.zip</a> (Size: 188.93 KB / Downloads: 517)
<!-- end: postbit_attachments_attachment --><br />
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:  <br />
<!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/zip.png" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=7176" target="_blank" title="">8-Ethernet-W5500.ino.merged.zip</a> (Size: 188.93 KB / Downloads: 517)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/zip.png" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=7175" target="_blank" title="">8-Ethernet-W5500.zip</a> (Size: 1.23 KB / Downloads: 462)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>/*<br />
 * Made by KinCony IoT: https://www.kincony.com<br />
 *<br />
 * This Arduino program sets up an ESP32-S3 with a W5500 Ethernet module<br />
 * as a TCP server. It listens on port 4196 and echoes back any string <br />
 * received from a client.<br />
 *<br />
 * Hardware connections:<br />
 * - CLK: GPIO1<br />
 * - MOSI: GPIO2<br />
 * - MISO: GPIO41<br />
 * - CS: GPIO42<br />
 * - RST: GPIO44<br />
 * - INT: GPIO43<br />
 *<br />
 * Static IP address: 192.168.3.55<br />
 * Subnet Mask: 255.255.255.0<br />
 * Gateway: 192.168.3.1<br />
 * DNS: 192.168.3.1<br />
 */<br />
<br />
#include &lt;SPI.h&gt;<br />
#include &lt;Ethernet.h&gt;<br />
<br />
// Define the W5500 Ethernet module pins<br />
#define W5500_CS_PIN  42<br />
#define W5500_RST_PIN 44<br />
#define W5500_INT_PIN 43<br />
#define W5500_CLK_PIN 1<br />
#define W5500_MOSI_PIN 2<br />
#define W5500_MISO_PIN 41<br />
<br />
// MAC address for your Ethernet shield (must be unique on your network)<br />
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };<br />
<br />
// Static IP address configuration<br />
IPAddress ip(192, 168, 3, 55);     &nbsp;&nbsp;// Static IP address<br />
IPAddress subnet(255, 255, 255, 0); &nbsp;&nbsp;// Subnet mask<br />
IPAddress gateway(192, 168, 3, 1);    // Default gateway<br />
IPAddress dns(192, 168, 3, 1);        // DNS server address<br />
<br />
// Create an EthernetServer object to handle TCP connections<br />
EthernetServer server(4196);<br />
<br />
void setup() {<br />
  // Initialize serial communication<br />
  Serial.begin(115200);<br />
  while (!Serial) {<br />
    ; // Wait for serial port to connect<br />
  }<br />
<br />
  // Initialize the W5500 module<br />
  pinMode(W5500_RST_PIN, OUTPUT);<br />
  pinMode(W5500_INT_PIN, INPUT);<br />
  digitalWrite(W5500_RST_PIN, LOW);  // Reset the W5500 module<br />
  delay(100);                     &nbsp;&nbsp;// Wait for reset to complete<br />
  digitalWrite(W5500_RST_PIN, HIGH); // Release reset<br />
<br />
  // Initialize SPI with the correct pin definitions<br />
  SPI.begin(W5500_CLK_PIN, W5500_MISO_PIN, W5500_MOSI_PIN);<br />
<br />
  // Set up the Ethernet library with W5500-specific pins<br />
  Ethernet.init(W5500_CS_PIN);<br />
<br />
  // Start the Ethernet connection with static IP configuration<br />
  Ethernet.begin(mac, ip, dns, gateway, subnet);<br />
<br />
  // Print the IP address to the serial monitor<br />
  Serial.print("IP Address: ");<br />
  Serial.println(Ethernet.localIP());<br />
<br />
  // Start listening for incoming TCP connections<br />
  server.begin();<br />
}<br />
<br />
void loop() {<br />
  // Check for incoming client connections<br />
  EthernetClient client = server.available();<br />
  if (client) {<br />
    Serial.println("New client connected");<br />
<br />
    // Read data from the client and echo it back<br />
    while (client.connected()) {<br />
      if (client.available()) {<br />
        char c = client.read();<br />
        server.write(c);<br />
      }<br />
    }<br />
<br />
    // Close the connection when done<br />
    client.stop();<br />
    Serial.println("Client disconnected");<br />
  }<br />
}</code></div></div> arduino ino file download:  <!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/zip.png" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=7176" target="_blank" title="">8-Ethernet-W5500.ino.merged.zip</a> (Size: 188.93 KB / Downloads: 517)
<!-- end: postbit_attachments_attachment --><br />
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:  <br />
<!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/zip.png" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=7176" target="_blank" title="">8-Ethernet-W5500.ino.merged.zip</a> (Size: 188.93 KB / Downloads: 517)
<!-- end: postbit_attachments_attachment --><br /><!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/zip.png" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=7175" target="_blank" title="">8-Ethernet-W5500.zip</a> (Size: 1.23 KB / Downloads: 462)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
		<item>
			<title><![CDATA[[arduino code examples for B16]-07 how to DS3231 RTC clock]]></title>
			<link>https://www.kincony.com/forum/showthread.php?tid=7681</link>
			<pubDate>Sat, 22 Feb 2025 10:05:52 +0800</pubDate>
			<dc:creator><![CDATA[<a href="https://www.kincony.com/forum/member.php?action=profile&uid=1">admin</a>]]></dc:creator>
			<guid isPermaLink="false">https://www.kincony.com/forum/showthread.php?tid=7681</guid>
			<description><![CDATA[<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>/*<br />
 * Made by KinCony IoT: https://www.kincony.com<br />
 *<br />
 * DS3231 RTC with Arduino<br />
 *<br />
 * This program demonstrates how to use the DS3231 RTC (Real-Time Clock) module with the Arduino.<br />
 * It includes functionality to:<br />
 * - Initialize the DS3231 RTC module<br />
 * - Read the current date and time from the RTC<br />
 * - Set the RTC time based on a serial command:Command format: DYYYY-MM-DDTHH:MM:SS<br />
*    Set date and time command example: D2024-09-19T11:50:22<br />
*    print current date and time command: current time<br />
*<br />
 *<br />
 * Hardware Connections:<br />
 * - SDA: GPIO 8<br />
 * - SCL: GPIO 18<br />
 */<br />
<br />
#include &lt;DS3231.h&gt;<br />
#include &lt;Wire.h&gt;<br />
<br />
String serial_cmd_rcv = ""; // Serial port receiver<br />
<br />
typedef struct<br />
{<br />
  byte year;    // Last two digits of the year, library adds 2000.<br />
  byte month;<br />
  byte day;<br />
  byte hour;<br />
  byte minute;<br />
  byte second;<br />
} MY_DATE_STR;<br />
<br />
MY_DATE_STR my_date_str = {0};<br />
<br />
// Define constants for relay control<br />
#define OPEN_RLY_DATA    26<br />
#define OPEN_RLY_MONTH &nbsp;&nbsp;4<br />
#define CLOSE_RLY_DATA &nbsp;&nbsp;2<br />
#define CLOSE_RLY_MONTH  5<br />
<br />
// Define pin connections<br />
#define SDA_PIN &nbsp;&nbsp;8<br />
#define SCL_PIN &nbsp;&nbsp;18<br />
<br />
DS3231 rtc; // Create an instance of the DS3231 RTC<br />
bool h12Flag;<br />
bool pmFlag;<br />
static bool bCentury = false;<br />
static bool old_level_high = false;<br />
static bool old_level_low = false;<br />
<br />
<br />
/**<br />
 * @brief Print the current time from the RTC to the Serial Monitor.<br />
 */<br />
static void PrintfCurTime()<br />
{<br />
  Serial.print("Current time is: ");<br />
  int year = rtc.getYear() + 2000;<br />
  Serial.print(year);<br />
  Serial.print("-");<br />
<br />
  Serial.print(rtc.getMonth(bCentury), DEC);<br />
  Serial.print("-");<br />
<br />
  Serial.print(rtc.getDate(), DEC);<br />
  Serial.print(" ");<br />
<br />
  Serial.print(rtc.getHour(h12Flag, pmFlag), DEC);<br />
  Serial.print(":");<br />
  Serial.print(rtc.getMinute(), DEC);<br />
  Serial.print(":");<br />
  Serial.println(rtc.getSecond(), DEC);<br />
}<br />
<br />
/**<br />
 * @brief Process serial commands to set the RTC time.<br />
 * Command format: DYYYY-MM-DDTHH:MM:SS<br />
 */<br />
static void GetSerialCmd()<br />
{<br />
  if (Serial.available() &gt; 0)<br />
  {<br />
    delay(100);<br />
    int num_read = Serial.available();<br />
    while (num_read--)<br />
      serial_cmd_rcv += char(Serial.read());<br />
  }<br />
  else return;<br />
<br />
  serial_cmd_rcv.trim();<br />
<br />
  if (serial_cmd_rcv == "current time")<br />
  {<br />
    PrintfCurTime();<br />
    serial_cmd_rcv = "";<br />
    return;<br />
  }<br />
<br />
  Serial.print("Received length: ");<br />
  Serial.println(serial_cmd_rcv.length());<br />
<br />
  int indexof_d = serial_cmd_rcv.indexOf('D');<br />
  int indexof_t = serial_cmd_rcv.indexOf('T');<br />
<br />
  Serial.print("D index: ");<br />
  Serial.print(indexof_d);<br />
  Serial.print(" T index: ");<br />
  Serial.println(indexof_t);<br />
<br />
  if (serial_cmd_rcv.length() != 20 || <br />
      serial_cmd_rcv.substring(0, 1) != "D" ||<br />
      serial_cmd_rcv.substring(11, 12) != "T")  <br />
  {<br />
    Serial.println(serial_cmd_rcv);<br />
    serial_cmd_rcv = "";<br />
    return;<br />
  }<br />
<br />
  Serial.println("Setting time...");<br />
<br />
  my_date_str.year = (byte)serial_cmd_rcv.substring(3, 5).toInt();<br />
  my_date_str.month = (byte)serial_cmd_rcv.substring(6, 8).toInt();<br />
  my_date_str.day = (byte)serial_cmd_rcv.substring(9, 11).toInt();<br />
  my_date_str.hour = (byte)serial_cmd_rcv.substring(12, 14).toInt();<br />
  my_date_str.minute = (byte)serial_cmd_rcv.substring(15, 17).toInt();<br />
  my_date_str.second = (byte)serial_cmd_rcv.substring(18).toInt();<br />
<br />
  rtc.setYear(my_date_str.year);<br />
  rtc.setMonth(my_date_str.month);<br />
  rtc.setDate(my_date_str.day);<br />
  rtc.setHour(my_date_str.hour);<br />
  rtc.setMinute(my_date_str.minute);<br />
  rtc.setSecond(my_date_str.second);<br />
<br />
  serial_cmd_rcv = "";<br />
<br />
  Serial.println("Time set.");<br />
}<br />
<br />
void setup() {<br />
  // Initialize the I2C interface<br />
  Wire.begin(SDA_PIN, SCL_PIN, 40000);<br />
  <br />
  // Initialize Serial communication<br />
  Serial.begin(115200);<br />
 &nbsp;&nbsp;<br />
  // Set the RTC to 24-hour mode<br />
  rtc.setClockMode(false); // 24-hour format<br />
<br />
  // Print current time to Serial Monitor<br />
  PrintfCurTime();<br />
<br />
  // Clear any remaining serial data<br />
  while (Serial.read() &gt;= 0) {}<br />
}<br />
<br />
void loop() {<br />
  // Process incoming serial commands<br />
  GetSerialCmd(); <br />
  delay(1000); // Delay for 1 second<br />
}</code></div></div> arduino ino file download:  <!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/zip.png" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=7173" target="_blank" title="">7-DS3231-RTC.zip</a> (Size: 1.56 KB / Downloads: 467)
<!-- end: postbit_attachments_attachment --><br />
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:  <br />
<!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/zip.png" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=7174" target="_blank" title="">7-DS3231-RTC.ino.merged.zip</a> (Size: 191.08 KB / Downloads: 490)
<!-- end: postbit_attachments_attachment -->]]></description>
			<content:encoded><![CDATA[<div class="codeblock"><div class="title">Code:</div><div class="body" dir="ltr"><code>/*<br />
 * Made by KinCony IoT: https://www.kincony.com<br />
 *<br />
 * DS3231 RTC with Arduino<br />
 *<br />
 * This program demonstrates how to use the DS3231 RTC (Real-Time Clock) module with the Arduino.<br />
 * It includes functionality to:<br />
 * - Initialize the DS3231 RTC module<br />
 * - Read the current date and time from the RTC<br />
 * - Set the RTC time based on a serial command:Command format: DYYYY-MM-DDTHH:MM:SS<br />
*    Set date and time command example: D2024-09-19T11:50:22<br />
*    print current date and time command: current time<br />
*<br />
 *<br />
 * Hardware Connections:<br />
 * - SDA: GPIO 8<br />
 * - SCL: GPIO 18<br />
 */<br />
<br />
#include &lt;DS3231.h&gt;<br />
#include &lt;Wire.h&gt;<br />
<br />
String serial_cmd_rcv = ""; // Serial port receiver<br />
<br />
typedef struct<br />
{<br />
  byte year;    // Last two digits of the year, library adds 2000.<br />
  byte month;<br />
  byte day;<br />
  byte hour;<br />
  byte minute;<br />
  byte second;<br />
} MY_DATE_STR;<br />
<br />
MY_DATE_STR my_date_str = {0};<br />
<br />
// Define constants for relay control<br />
#define OPEN_RLY_DATA    26<br />
#define OPEN_RLY_MONTH &nbsp;&nbsp;4<br />
#define CLOSE_RLY_DATA &nbsp;&nbsp;2<br />
#define CLOSE_RLY_MONTH  5<br />
<br />
// Define pin connections<br />
#define SDA_PIN &nbsp;&nbsp;8<br />
#define SCL_PIN &nbsp;&nbsp;18<br />
<br />
DS3231 rtc; // Create an instance of the DS3231 RTC<br />
bool h12Flag;<br />
bool pmFlag;<br />
static bool bCentury = false;<br />
static bool old_level_high = false;<br />
static bool old_level_low = false;<br />
<br />
<br />
/**<br />
 * @brief Print the current time from the RTC to the Serial Monitor.<br />
 */<br />
static void PrintfCurTime()<br />
{<br />
  Serial.print("Current time is: ");<br />
  int year = rtc.getYear() + 2000;<br />
  Serial.print(year);<br />
  Serial.print("-");<br />
<br />
  Serial.print(rtc.getMonth(bCentury), DEC);<br />
  Serial.print("-");<br />
<br />
  Serial.print(rtc.getDate(), DEC);<br />
  Serial.print(" ");<br />
<br />
  Serial.print(rtc.getHour(h12Flag, pmFlag), DEC);<br />
  Serial.print(":");<br />
  Serial.print(rtc.getMinute(), DEC);<br />
  Serial.print(":");<br />
  Serial.println(rtc.getSecond(), DEC);<br />
}<br />
<br />
/**<br />
 * @brief Process serial commands to set the RTC time.<br />
 * Command format: DYYYY-MM-DDTHH:MM:SS<br />
 */<br />
static void GetSerialCmd()<br />
{<br />
  if (Serial.available() &gt; 0)<br />
  {<br />
    delay(100);<br />
    int num_read = Serial.available();<br />
    while (num_read--)<br />
      serial_cmd_rcv += char(Serial.read());<br />
  }<br />
  else return;<br />
<br />
  serial_cmd_rcv.trim();<br />
<br />
  if (serial_cmd_rcv == "current time")<br />
  {<br />
    PrintfCurTime();<br />
    serial_cmd_rcv = "";<br />
    return;<br />
  }<br />
<br />
  Serial.print("Received length: ");<br />
  Serial.println(serial_cmd_rcv.length());<br />
<br />
  int indexof_d = serial_cmd_rcv.indexOf('D');<br />
  int indexof_t = serial_cmd_rcv.indexOf('T');<br />
<br />
  Serial.print("D index: ");<br />
  Serial.print(indexof_d);<br />
  Serial.print(" T index: ");<br />
  Serial.println(indexof_t);<br />
<br />
  if (serial_cmd_rcv.length() != 20 || <br />
      serial_cmd_rcv.substring(0, 1) != "D" ||<br />
      serial_cmd_rcv.substring(11, 12) != "T")  <br />
  {<br />
    Serial.println(serial_cmd_rcv);<br />
    serial_cmd_rcv = "";<br />
    return;<br />
  }<br />
<br />
  Serial.println("Setting time...");<br />
<br />
  my_date_str.year = (byte)serial_cmd_rcv.substring(3, 5).toInt();<br />
  my_date_str.month = (byte)serial_cmd_rcv.substring(6, 8).toInt();<br />
  my_date_str.day = (byte)serial_cmd_rcv.substring(9, 11).toInt();<br />
  my_date_str.hour = (byte)serial_cmd_rcv.substring(12, 14).toInt();<br />
  my_date_str.minute = (byte)serial_cmd_rcv.substring(15, 17).toInt();<br />
  my_date_str.second = (byte)serial_cmd_rcv.substring(18).toInt();<br />
<br />
  rtc.setYear(my_date_str.year);<br />
  rtc.setMonth(my_date_str.month);<br />
  rtc.setDate(my_date_str.day);<br />
  rtc.setHour(my_date_str.hour);<br />
  rtc.setMinute(my_date_str.minute);<br />
  rtc.setSecond(my_date_str.second);<br />
<br />
  serial_cmd_rcv = "";<br />
<br />
  Serial.println("Time set.");<br />
}<br />
<br />
void setup() {<br />
  // Initialize the I2C interface<br />
  Wire.begin(SDA_PIN, SCL_PIN, 40000);<br />
  <br />
  // Initialize Serial communication<br />
  Serial.begin(115200);<br />
 &nbsp;&nbsp;<br />
  // Set the RTC to 24-hour mode<br />
  rtc.setClockMode(false); // 24-hour format<br />
<br />
  // Print current time to Serial Monitor<br />
  PrintfCurTime();<br />
<br />
  // Clear any remaining serial data<br />
  while (Serial.read() &gt;= 0) {}<br />
}<br />
<br />
void loop() {<br />
  // Process incoming serial commands<br />
  GetSerialCmd(); <br />
  delay(1000); // Delay for 1 second<br />
}</code></div></div> arduino ino file download:  <!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/zip.png" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=7173" target="_blank" title="">7-DS3231-RTC.zip</a> (Size: 1.56 KB / Downloads: 467)
<!-- end: postbit_attachments_attachment --><br />
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:  <br />
<!-- start: postbit_attachments_attachment -->
<br /><!-- start: attachment_icon -->
<img src="https://www.kincony.com/forum/images/attachtypes/zip.png" title="ZIP File" border="0" alt=".zip" />
<!-- end: attachment_icon -->&nbsp;&nbsp;<a href="attachment.php?aid=7174" target="_blank" title="">7-DS3231-RTC.ino.merged.zip</a> (Size: 191.08 KB / Downloads: 490)
<!-- end: postbit_attachments_attachment -->]]></content:encoded>
		</item>
	</channel>
</rss>