Smart Home Automation Forum
[arduino code examples for A2v3]-02 Read digital input ports state - Printable Version

+- Smart Home Automation Forum (https://www.kincony.com/forum)
+-- Forum: Technical Support (https://www.kincony.com/forum/forumdisplay.php?fid=20)
+--- Forum: KC868-A2v3 (https://www.kincony.com/forum/forumdisplay.php?fid=77)
+--- Thread: [arduino code examples for A2v3]-02 Read digital input ports state (/showthread.php?tid=7961)



[arduino code examples for A2v3]-02 Read digital input ports state - admin - 04-20-2025

Code:
/**
* @brief Simple example to read two digital inputs using ESP32
* @details This program demonstrates how to read two digital input states
*          from GPIO16 and GPIO17 of an ESP32 development board.
*
* Made by KinCony IoT: https://www.kincony.com
*/

// Define the GPIO pins for digital inputs
#define INPUT1_PIN 16  // GPIO16 for Digital Input 1
#define INPUT2_PIN 17  // GPIO17 for Digital Input 2

void setup() {
    // Initialize the serial communication for debugging
    Serial.begin(115200);
    Serial.println("ESP32 Digital Input Read Example");

    // Set the input pins as INPUT
    pinMode(INPUT1_PIN, INPUT);
    pinMode(INPUT2_PIN, INPUT);
}

void loop() {
    // Read the state of the digital inputs
    int state1 = digitalRead(INPUT1_PIN);
    int state2 = digitalRead(INPUT2_PIN);

    // Print the states to the Serial Monitor
    Serial.print("Digital Input 1 State: ");
    Serial.println(state1);
    Serial.print("Digital Input 2 State: ");
    Serial.println(state2);

    // Wait for 500 milliseconds before reading again
    delay(500);
}
arduino ino file download:

.zip   2-digital-input.zip (Size: 667 bytes / Downloads: 371)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   2-digital-input.ino.merged.zip (Size: 179.35 KB / Downloads: 353)