Smart Home Automation Forum
[arduino code examples for MT4v2]-05 Read free GPIO state - Printable Version

+- Smart Home Automation Forum (https://www.kincony.com/forum)
+-- Forum: Technical Support (https://www.kincony.com/forum/forumdisplay.php?fid=114)
+--- Forum: MT4v2 (https://www.kincony.com/forum/forumdisplay.php?fid=120)
+--- Thread: [arduino code examples for MT4v2]-05 Read free GPIO state (/showthread.php?tid=9883)



[arduino code examples for MT4v2]-05 Read free GPIO state - admin - 10-20-2026

Code:
/*
* ESP32 GPIO State Reader
* Reads the state of GPIO47, GPIO48, GPIO7, GPIO40, GPIO0, and GPIO5
* and prints the results to the serial monitor.
*
* Made by KinCony IoT: https://www.kincony.com
*/


#define GPIO_40  40
#define GPIO_48  48
#define GPIO_0   0
#define GPIO_47  47
#define GPIO_17  17



void setup() {
    Serial.begin(115200); // Initialize serial communication at 115200 baud rate
   
    // Set GPIOs as input

    pinMode(GPIO_40, INPUT);
    pinMode(GPIO_48, INPUT);
    pinMode(GPIO_0, INPUT);
    pinMode(GPIO_47, INPUT);
    pinMode(GPIO_17, INPUT);           
}

void loop() {
    // Read GPIO states
    int state_40 = digitalRead(GPIO_40);
    int state_48 = digitalRead(GPIO_48);
    int state_0  = digitalRead(GPIO_0);
    int state_47 = digitalRead(GPIO_47);
    int state_17 = digitalRead(GPIO_17);


    // Print GPIO states to the serial monitor
    Serial.printf("GPIO40: %d, GPIO48: %d, GPIO0: %d, GPIO47: %d, GPIO17: %d\n",
                  state_40, state_48, state_0, state_47, state_17);
   
    delay(1000); // Read GPIO states every second
}
arduino ino file download:

.zip   5-free-gpio-state.zip (Size: 685 bytes / Downloads: 7)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download: 

.zip   5-free-gpio-state.ino.merged.zip (Size: 180.12 KB / Downloads: 7)