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

How to Create Automated Lighting with Arduino

Automated lighting, or "Iluminação Automatizada," is a popular application for Arduino, allowing you to control lights based on various inputs such as time, motion, or ambient light levels. This article will guide you through setting up a basic automated lighting system using an Arduino board, a light sensor, and a relay module to control a lamp.

Examples:

Components Required:

  1. Arduino Uno or any compatible board
  2. Light sensor (e.g., LDR - Light Dependent Resistor)
  3. Relay module
  4. Jumper wires
  5. Breadboard
  6. A lamp or LED (for demonstration purposes)
  7. Resistor (10k ohm for the LDR)

Circuit Connection:

  1. Connect the LDR to the Arduino:

    • Connect one end of the LDR to 5V on the Arduino.
    • Connect the other end of the LDR to A0 (analog pin 0) on the Arduino.
    • Connect a 10k ohm resistor from the LDR's connection to GND.
  2. Connect the Relay Module:

    • Connect the VCC of the relay module to the 5V pin on the Arduino.
    • Connect the GND of the relay module to the GND on the Arduino.
    • Connect the IN pin on the relay to digital pin 7 on the Arduino.
    • Connect the lamp or LED to the relay's output, ensuring it is powered safely.

Arduino Code:

const int lightSensorPin = A0; // Pin connected to the LDR
const int relayPin = 7;        // Pin connected to the relay
int sensorValue = 0;           // Variable to store the sensor value
int threshold = 500;           // Threshold for turning the light on/off

void setup() {
  pinMode(relayPin, OUTPUT);   // Set relay pin as an output
  Serial.begin(9600);          // Initialize serial communication for debugging
}

void loop() {
  sensorValue = analogRead(lightSensorPin); // Read the value from the LDR
  Serial.println(sensorValue);              // Print the sensor value for debugging

  if (sensorValue < threshold) {
    digitalWrite(relayPin, HIGH); // Turn on the light
  } else {
    digitalWrite(relayPin, LOW);  // Turn off the light
  }

  delay(1000); // Wait for a second before the next reading
}

Explanation:

  • The LDR is used to detect the ambient light level. When the light level drops below a certain threshold, the relay is activated, turning on the connected lamp or LED.
  • The relay module acts as a switch to control the power to the lamp, allowing the Arduino to manage higher voltage devices safely.
  • The threshold value can be adjusted based on the desired sensitivity to light changes.

Safety Note:

When working with high voltages, such as those used in household lighting, ensure that all connections are secure and insulated to prevent electrical hazards. If you're not experienced with handling high-voltage devices, consider using low-voltage LEDs for testing.

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.