PIR Sensor for Solar Pathway Lighting

Project Overview

This project creates solar-powered pathway lights that automatically turn on when someone walks by. The system uses a PIR sensor to detect motion and turns on LED strips for a set duration. Solar charging keeps the battery topped up during the day.

Difficulty: Intermediate
Estimated time: 2-3 hours
Estimated cost: $30-45

How It Works

A solar panel charges a lithium battery during the day. A PIR sensor mounted on the pathway detects approaching pedestrians. When motion is detected, the system turns on LED lights for 30-60 seconds. A light sensor can be added to ensure lights only activate at night.

Materials Needed

  • ESP32 or ATtiny85 (1) – ATtiny85 for ultra-low power
  • HC-SR501 PIR sensor (1)
  • Solar panel (5V, 5-10W)
  • 18650 lithium battery (1 or 2)
  • TP4056 charging module (with battery protection)
  • Boost converter (to 5V if needed)
  • LED strip (12V or 5V, length as needed)
  • MOSFET or relay (for switching LEDs)
  • LDR (photoresistor) (optional, for day/night detection)
  • Waterproof enclosure
  • Jumper wires and soldering equipment

Circuit Diagram

Power Section

Solar Panel (+) --- TP4056 IN+ --- 18650 Battery (+)
Solar Panel (-) --- TP4056 IN- --- 18650 Battery (-)
Battery (+) --- Boost Converter (3.7V → 5V) --- ESP32 VIN

Sensor Connections

Arduino Code (ATtiny85 Version – Ultra Low Power)

// Solar Pathway Lighting with ATtiny85
#include <avr/sleep.h>

const int pirPin = 0;   // PB0 (pin 5)
const int ledPin = 1;   // PB1 (pin 6)
const int ldrPin = 2;   // PB2 (pin 7)

unsigned long lastTrigger = 0;
const unsigned long lightDuration = 30000; // 30 seconds

void setup() {
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(ldrPin, INPUT);
  digitalWrite(ledPin, LOW);
  
  // Allow PIR warm-up
  delay(30000);
}

bool isDark() {
  // Read LDR (simple threshold)
  int value = analogRead(ldrPin);
  return value < 500; // Dark when below 500
}

void goToSleep() {
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  sleep_cpu();
  sleep_disable();
}

void loop() {
  bool motion = digitalRead(pirPin) == HIGH;
  bool dark = isDark();
  
  if (motion && dark) {
    digitalWrite(ledPin, HIGH);
    lastTrigger = millis();
  }
  
  if (digitalRead(ledPin) == HIGH && (millis() - lastTrigger > lightDuration)) {
    digitalWrite(ledPin, LOW);
  }
  
  // Deep sleep to save battery (wake on PIR interrupt)
  if (!motion && !digitalRead(ledPin)) {
    // Enable wake on PIR change
    attachInterrupt(0, wakeUp, RISING);
    goToSleep();
    detachInterrupt(0);
  }
  
  delay(100);
}

void wakeUp() {}

ESP32 Version with Wi-Fi Monitoring

// Solar Pathway Lights with Wi-Fi Monitoring
#include <WiFi.h>

const int pirPin = 4;
const int ledPin = 5;
const int ldrPin = 34;

unsigned long lastTrigger = 0;
const unsigned long lightDuration = 30000;
float batteryVoltage = 0;

void setup() {
  Serial.begin(115200);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(ldrPin, INPUT);
  digitalWrite(ledPin, LOW);
  
  delay(30000); // PIR warm-up
}

float readBattery() {
  // Read voltage divider (assumes 100k/100k divider)
  int raw = analogRead(36); // VP pin
  return (raw / 4095.0) * 3.3 * 2; // 2x divider factor
}

bool isDark() {
  return analogRead(ldrPin) < 500;
}

void loop() {
  bool motion = digitalRead(pirPin) == HIGH;
  bool dark = isDark();
  batteryVoltage = readBattery();
  
  if (motion && dark && batteryVoltage > 3.0) {
    digitalWrite(ledPin, HIGH);
    lastTrigger = millis();
    Serial.println("Motion detected - lights ON");
  }
  
  if (digitalRead(ledPin) == HIGH && (millis() - lastTrigger > lightDuration)) {
    digitalWrite(ledPin, LOW);
    Serial.println("Lights OFF");
  }
  
  // Report battery every 10 minutes
  static unsigned long lastReport = 0;
  if (millis() - lastReport > 600000) {
    Serial.printf("Battery: %.2fV\n", batteryVoltage);
    lastReport = millis();
  }
  
  delay(100);
}

Installation Steps

  1. Assemble power system: Connect solar panel to TP4056, battery, and boost converter.
  2. Test charging: Place in sun and verify battery voltage increases.
  3. Mount PIR sensor: Place at 1m height along pathway, angled to detect pedestrians.
  4. Install LEDs: Place LED strips along pathway edges or under handrails.
  5. Enclose electronics: Place all components in waterproof enclosure with solar panel mounted on top.
  6. Test: Walk along pathway at night, verify lights turn on.

Power Calculations

  • PIR sensor: 50µA standby
  • ATtiny85 sleep: 5µA
  • Total standby: ~55µA
  • Daily standby consumption: 1.32 mAh
  • LEDs (10W for 30 seconds, 10 events/night): 0.83 mAh
  • Daily total: ~2.2 mAh
  • 18650 battery (2000 mAh) lasts: 900+ days
  • Solar panel ensures indefinite operation

Project Extensions

  • Color-changing lights: Use RGB LEDs that change color based on battery level.
  • Direction detection: Add second PIR to light path in direction of travel.
  • Remote monitoring: Add LoRa to report battery level and events.
  • Smart home integration: Connect to Home Assistant via MQTT.
  • Music sync: Add microphone for sound-reactive lighting.

Troubleshooting

  • Lights not turning on at night: Check LDR threshold. Test with hand covering LDR.
  • Lights turning on during day: Adjust LDR threshold upward.
  • Battery not charging: Check solar panel connections. Ensure TP4056 is working.
  • Short battery life: Verify deep sleep is working. Check for leaks in code.
  • False triggers: Adjust PIR sensitivity. Ensure not facing road traffic.

Conclusion

These solar-powered pathway lights add safety and beauty to your walkway without increasing your electric bill. With motion activation, they only illuminate when needed, saving battery power.

Leave a Reply

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

Component Pin ESP32 Pin
PIR Sensor OUT GPIO 4 LDR (voltage divider) Output GPIO 34 LED MOSFET Gate GPIO 5