⇧
vadnica-logo
Editor My Blog Password Manager Finance My Services About the Project Telegram O meni O meni

Project: Magic Touchless Switch

In this project, we will use the TCRT5000 infrared (IR) reflective sensor (labeled HW-006 v1.3 on the board). Instead of classic buttons, we will use a hand wave to toggle the display output.

Technical Reminder

Wiring Instructions

Connecting components to the Arduino Nano ESP32:

  1. TFT VCC -> 3.3V
  2. TFT GND -> GND
  3. TFT SCL (SCK) -> D13
  4. TFT SDA (MOSI) -> D11
  5. TFT CS -> D10
  6. TFT DC -> D9
  7. TFT RES (RST) -> D8
  8. TCRT VCC -> 3.3V
  9. TCRT GND -> GND
  10. TCRT D0 (Digital Out) -> D4

Complete Project Code

The code below allows switching between the text "STATUS: OK" and the warning "DETECTED!" when the sensor detects proximity.

// Project: Touchless Switch (TCRT5000 + TFT 2.0 SPI)
// Author: Borut Bukovnik - vadnica.org

#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>

// Pins for TFT display
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8
#define IR_PIN 4 // Pin for IR sensor

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

void setup() {
    tft.init(240, 320);
    tft.setRotation(1);
    tft.fillScreen(ST77XX_BLACK);
    
    pinMode(IR_PIN, INPUT); // Set sensor as input
    
    tft.setTextColor(ST77XX_WHITE);
    tft.setTextSize(2);
    tft.setCursor(20, 20);
    tft.print("Proximity Sensor Active");
}

void loop() {
    // Read state (LOW means proximity detected)
    int state = digitalRead(IR_PIN);
    
    tft.setCursor(50, 110);
    tft.setTextSize(4);
    
    if (state == LOW) {
        // Obstacle detected
        tft.setTextColor(ST77XX_RED, ST77XX_BLACK);
        tft.print(" DETECTED! ");
    } else {
        // Path clear
        tft.setTextColor(ST77XX_GREEN, ST77XX_BLACK);
        tft.print(" STATUS: OK ");
    }
    
    delay(100); // Fast responsiveness
}

Required Material