In this project, we will use the ESP32 for invisible presence detection. Instead of motion sensors, we will use the Wi-Fi network. The ESP32 will check if family members' smartphones are connected to the home router.
For the display to work correctly, connect the pins according to the following table:
| TFT Pin | Nano ESP32 Pin | Description |
|---|---|---|
| VCC | 3.3V | Power Supply (not 5V!) |
| GND | GND | Ground |
| SCL (SCK) | D13 | SPI Clock |
| SDA (MOSI) | D11 | SPI Data |
| RES (RST) | D8 | Reset (set in code) |
| DC | D9 | Data/Command |
| CS | D10 | Chip Select |
| BLK | 3.3V | Backlight |
The code below scans the local network and displays the device status on a TFT 2.0 display in real- time. Every 10 seconds, the system pings specific IP addresses and outputs whether the device is present in the network.
// Project: WiFi Scanner with TFT 2.0 Display
// Author: Borut Bukovnik - vadnica.org
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
#include <WiFi.h>
#include <ESP32Ping.h>
// Pins for TFT display
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8
// WiFi credentials
const char* ssid = "YOUR_WIFI_NAME";
const char* password = "YOUR_PASSWORD";
// Device IP addresses
const char* ip_first = "ENTER_DEVICE_IP";
const char* ip_second = "ENTER_DEVICE_IP";
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
void setup() {
tft.init(240, 320);
tft.setRotation(1);
tft.fillScreen(ST77XX_BLACK);
tft.setTextColor(ST77XX_WHITE);
tft.setTextSize(2);
tft.setCursor(10, 10);
tft.print("Connecting WiFi...");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
tft.fillScreen(ST77XX_BLACK);
}
void displayStatus(int y, const char* name, bool present) {
tft.setCursor(10, y);
tft.setTextSize(2);
tft.setTextColor(ST77XX_WHITE, ST77XX_BLACK);
tft.print(name);
tft.print(": ");
if (present) {
tft.setTextColor(ST77XX_GREEN, ST77XX_BLACK);
tft.println("HOME ");
} else {
tft.setTextColor(ST77XX_RED, ST77XX_BLACK);
tft.println("AWAY ");
}
}
void loop() {
tft.setCursor(10, 10);
tft.setTextColor(ST77XX_CYAN, ST77XX_BLACK);
tft.setTextSize(2);
tft.println("CHECKING... ");
// Check first device
bool status1 = Ping.ping(ip_first);
displayStatus(60, "Device 1", status1);
// Check second device
bool status2 = Ping.ping(ip_second);
displayStatus(100, "Device 2", status2);
delay(10000); // Refresh every 10 seconds
}