PIR Sensor for Automatic Sink Faucet

Project Overview

This project converts a standard sink faucet into a touchless automatic faucet. When you place your hands under the faucet, a PIR sensor detects motion and opens a solenoid valve, allowing water to flow. When you remove your hands, the water stops after a short delay. This is perfect for kitchens, bathrooms, and public spaces where hygiene is important.

Difficulty: Intermediate
Estimated time: 3-4 hours
Estimated cost: $40-60

How It Works

A PIR sensor is positioned under the faucet spout, facing down toward the sink. When hands enter the detection zone, the sensor triggers an Arduino/ESP32, which activates a solenoid valve connected to the water line. The valve opens, water flows, and when hands are removed, the valve closes after a brief delay (to prevent rapid cycling).

An optional temperature sensor can detect water temperature, and an LCD can display status.

Materials Needed

  • Arduino Uno or ESP32 (1)
  • HC-SR501 PIR sensor (1) – facing downward
  • 12V solenoid valve (normally closed, 1/2″ or 3/4″ NPT)
  • 12V power supply (2A minimum)
  • MOSFET or relay module (to control solenoid)
  • Plumbing fittings (to adapt to your faucet supply)
  • Waterproof enclosure (for electronics)
  • Jumper wires and soldering equipment
  • Teflon tape (for plumbing connections)
  • Optional: DS18B20 temperature sensor, LCD display

Important Safety Notes

  • This project involves plumbing and electrical work. If you are not comfortable with either, consult a professional.
  • Always turn off water supply before installing the solenoid valve.
  • Use a GFCI-protected outlet for the power supply.
  • Ensure all electrical connections are protected from moisture.

Circuit Diagram

Connection Table

Component Pin Arduino Pin
PIR Sensor VCC 5V
PIR Sensor GND GND
PIR Sensor OUT Digital Pin 2
Relay Module VCC 5V
Relay Module GND GND
Relay Module IN Digital Pin 3
Solenoid Valve Positive Relay COM (power supply +)
Solenoid Valve Negative Relay NO (to power supply -)

Plumbing Installation

  1. Turn off water supply: Close the shutoff valves under the sink.
  2. Locate supply line: Identify the cold water supply line to your faucet.
  3. Install solenoid valve: Cut the supply line (or use existing connections) and install the solenoid valve in-line. Use Teflon tape on all threaded connections.
  4. Secure valve: Mount the solenoid valve securely under the sink where it won’t be disturbed.
  5. Test for leaks: Turn water on briefly to check for leaks before connecting electronics.

Arduino Code

// Automatic Faucet with PIR Sensor
// Opens solenoid valve when hands detected

const int pirPin = 2;
const int valvePin = 3;

unsigned long lastTriggerTime = 0;
const unsigned long waterDuration = 3000;  // Water flows for 3 seconds after hands removed
const unsigned long minInterval = 1000;     // Minimum time between cycles

bool waterOn = false;
bool motionDetected = false;

void setup() {
  Serial.begin(9600);
  
  pinMode(pirPin, INPUT);
  pinMode(valvePin, OUTPUT);
  
  digitalWrite(valvePin, LOW);
  
  Serial.println("Automatic Faucet Ready");
  Serial.println("Waiting 60 seconds for PIR warm-up...");
  delay(60000);
}

void turnWaterOn() {
  digitalWrite(valvePin, HIGH);
  waterOn = true;
  Serial.println("Water ON");
}

void turnWaterOff() {
  digitalWrite(valvePin, LOW);
  waterOn = false;
  Serial.println("Water OFF");
}

void loop() {
  bool motion = digitalRead(pirPin) == HIGH;
  
  if (motion && !motionDetected) {
    // Hands detected - turn water on
    motionDetected = true;
    lastTriggerTime = millis();
    
    if (!waterOn) {
      turnWaterOn();
    }
  }
  
  if (!motion && motionDetected) {
    // Hands removed - start timer
    motionDetected = false;
    lastTriggerTime = millis();
  }
  
  // If water is on and no motion, turn off after delay
  if (waterOn && !motionDetected && (millis() - lastTriggerTime > waterDuration)) {
    turnWaterOff();
  }
  
  // Safety: auto-off after 30 seconds regardless (prevent flooding)
  if (waterOn && (millis() - lastTriggerTime > 30000)) {
    Serial.println("Safety timeout - turning water off");
    turnWaterOff();
  }
  
  delay(100);
}

Enhanced Version with Temperature Display

#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>

#define ONE_WIRE_BUS 4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

LiquidCrystal_I2C lcd(0x27, 16, 2);

const int pirPin = 2;
const int valvePin = 3;

unsigned long lastTriggerTime = 0;
const unsigned long waterDuration = 3000;
bool waterOn = false;
bool motionDetected = false;
float currentTemp = 0;

void setup() {
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(valvePin, OUTPUT);
  digitalWrite(valvePin, LOW);
  
  sensors.begin();
  
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Touchless Faucet");
  lcd.setCursor(0, 1);
  lcd.print("Ready");
  
  delay(60000);
}

void readTemperature() {
  sensors.requestTemperatures();
  currentTemp = sensors.getTempCByIndex(0);
  
  if (currentTemp != -127) {
    lcd.setCursor(0, 1);
    lcd.print("Temp: ");
    lcd.print(currentTemp);
    lcd.print("C");
  }
}

void loop() {
  readTemperature();
  
  bool motion = digitalRead(pirPin) == HIGH;
  
  if (motion && !motionDetected) {
    motionDetected = true;
    lastTriggerTime = millis();
    if (!waterOn) {
      digitalWrite(valvePin, HIGH);
      waterOn = true;
      lcd.setCursor(0, 0);
      lcd.print("Water ON       ");
    }
  }
  
  if (!motion && motionDetected) {
    motionDetected = false;
    lastTriggerTime = millis();
  }
  
  if (waterOn && !motionDetected && (millis() - lastTriggerTime > waterDuration)) {
    digitalWrite(valvePin, LOW);
    waterOn = false;
    lcd.setCursor(0, 0);
    lcd.print("Ready         ");
  }
  
  if (waterOn && (millis() - lastTriggerTime > 30000)) {
    digitalWrite(valvePin, LOW);
    waterOn = false;
    lcd.setCursor(0, 0);
    lcd.print("Safety OFF    ");
  }
  
  delay(100);
}

PIR Sensor Positioning

Position the PIR sensor under the faucet spout, facing downward. The sensor should be angled so it detects hands in the sink but not people walking past. For best results:

  • Mount sensor 10-15cm above the sink bottom.
  • Angle sensor slightly away from user to avoid detecting the user’s body.
  • Adjust sensitivity potentiometer to minimum range (so it only detects directly below).
  • Use a narrow field of view lens or add a shield to limit detection area.

Enclosure and Waterproofing

  1. Place Arduino and relay module in a waterproof enclosure under the sink.
  2. Run sensor wires through a sealed cable gland.
  3. Mount PIR sensor in a small waterproof housing, sealed with silicone.
  4. Ensure all electrical connections are away from water lines.
  5. Use a GFCI outlet for power.

Installation Steps

  1. Install solenoid valve: Turn off water, install valve in supply line.
  2. Test for leaks: Turn water on and check connections.
  3. Build electronics: Assemble circuit in enclosure.
  4. Mount PIR sensor: Position under faucet spout.
  5. Connect solenoid to relay: Wire to 12V power supply.
  6. Program Arduino: Upload code and test with hand.
  7. Adjust sensitivity: Fine-tune PIR to detect only hands.
  8. Secure enclosure: Mount under sink away from water.

Project Extensions

  • Temperature control: Add mixing valve for temperature adjustment.
  • Flow sensor: Monitor water usage and detect leaks.
  • Voice control: Add Alexa/Google Assistant integration.
  • Battery backup: Add battery for operation during power outages.
  • Soap dispenser: Add second solenoid for automatic soap.
  • UV sterilization: Add UV LED for water sterilization.

Troubleshooting

  • Water doesn’t flow: Check solenoid valve wiring; test by applying 12V directly. Ensure water supply is on.
  • Water runs continuously: Solenoid may be stuck open; check for debris. Replace if faulty.
  • Sensor not detecting: Adjust sensitivity. Check wiring.
  • False triggering: Reduce sensitivity or add shield to limit field of view.
  • Water hammer: Add water hammer arrestor to plumbing.

Conclusion

This touchless faucet project adds convenience and improves hygiene in your kitchen or bathroom. With proper installation, it provides years of reliable, hands-free operation.

Leave a Reply

Your email address will not be published. Required fields are marked *