Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
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:
Circuit Connection:
Connect the LDR to the Arduino:
Connect the Relay Module:
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:
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.