Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

Automatic Lighting System Using Arduino

Automatic lighting systems are an essential part of modern home automation. They enhance convenience, improve energy efficiency, and provide security by controlling lights based on environmental conditions or user presence. In this article, we will create an automatic lighting system using an Arduino microcontroller. This project will focus on using a PIR (Passive Infrared) sensor to detect motion and a relay module to control the lighting. The Arduino environment is ideal for this project due to its simplicity, versatility, and extensive community support.

Project: The objective of this project is to create a system that automatically turns on a light when motion is detected and turns it off after a set period of inactivity. This system can be used in various applications such as home corridors, bathrooms, or outdoor lighting. The functionalities include:

  • Detecting motion using a PIR sensor.
  • Controlling a light bulb via a relay module.
  • Setting a timer to turn off the light after a specified duration of no motion.

Components List:

  • Arduino Uno (1)
  • PIR Motion Sensor (1)
  • Relay Module (1)
  • Light Bulb (1)
  • Bulb Holder (1)
  • Connecting Wires (Several)
  • Breadboard (1)
  • USB Cable (1)
  • Power Supply (1)

Examples:

Here is the Arduino code for the automatic lighting system:

// Define the pins
const int pirPin = 2; // PIR motion sensor connected to digital pin 2
const int relayPin = 8; // Relay module connected to digital pin 8

// Variables to store the PIR state
int pirState = LOW; // Start with no motion detected
int val = 0; // Variable to read the PIR sensor value

void setup() {
  pinMode(pirPin, INPUT); // Set the PIR pin as input
  pinMode(relayPin, OUTPUT); // Set the relay pin as output
  digitalWrite(relayPin, LOW); // Ensure the relay is off initially
  Serial.begin(9600); // Initialize serial communication for debugging
}

void loop() {
  val = digitalRead(pirPin); // Read the state of the PIR sensor
  if (val == HIGH) { // If motion is detected
    digitalWrite(relayPin, HIGH); // Turn on the relay (and the light)
    if (pirState == LOW) {
      Serial.println("Motion detected! Light ON."); // Print to serial monitor
      pirState = HIGH; // Update the PIR state
    }
  } else {
    digitalWrite(relayPin, LOW); // Turn off the relay (and the light)
    if (pirState == HIGH) {
      Serial.println("No motion. Light OFF."); // Print to serial monitor
      pirState = LOW; // Update the PIR state
    }
  }
  delay(1000); // Wait for 1 second before checking again
}

Explanation of the Code:

  1. Pin Definitions:

    • pirPin is set to digital pin 2 where the PIR sensor is connected.
    • relayPin is set to digital pin 8 where the relay module is connected.
  2. Setup Function:

    • pinMode(pirPin, INPUT); configures the PIR pin as an input.
    • pinMode(relayPin, OUTPUT); configures the relay pin as an output.
    • digitalWrite(relayPin, LOW); ensures the relay is off initially.
    • Serial.begin(9600); initializes serial communication for debugging purposes.
  3. Loop Function:

    • val = digitalRead(pirPin); reads the state of the PIR sensor.
    • If motion is detected (val == HIGH), the relay is turned on (digitalWrite(relayPin, HIGH);) and a message is printed to the serial monitor.
    • If no motion is detected (val == LOW), the relay is turned off (digitalWrite(relayPin, LOW);) and a message is printed to the serial monitor.
    • delay(1000); introduces a 1-second delay before the next reading to avoid rapid toggling.

This project demonstrates a simple yet effective way to automate lighting using Arduino, enhancing both convenience and energy efficiency.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.