This circuit is designed to control the brightness of a set of LEDs based on the ambient light level detected by a light sensor. The core of the circuit is an Arduino UNO microcontroller, which reads the light sensor data and adjusts the LED brightness accordingly through a TIP120 Darlington Transistor. The LEDs are connected with resistors to limit the current, and the entire circuit is powered by a supply unit.
// Pin definitions
const int lightSensorPin = A4; // Analog pin for light sensor (SDA)
const int ledPin = 9; // PWM pin for LED control (connected to TIP120 base)
int lightValue = 0; // Variable to store light sensor value
void setup() {
// Initialize serial communication for debugging
Serial.begin(9600);
// Set pin modes
pinMode(lightSensorPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
// Read the light sensor value
lightValue = analogRead(lightSensorPin);
// Print the light sensor value to the Serial Monitor
Serial.print("Light Sensor Value: ");
Serial.println(lightValue);
// Map the light sensor value to a PWM value (0-255)
int pwmValue = map(lightValue, 0, 1023, 255, 0); // Invert to increase LED brightness in lower light
// Set the LED brightness based on the light sensor value
analogWrite(ledPin, pwmValue);
// Delay before the next loop iteration
delay(100);
}
This code is designed to run on the Arduino UNO microcontroller. It initializes the serial communication for debugging purposes, sets the pin modes for the light sensor and LED control, reads the light sensor value, maps it to a PWM value, and adjusts the LED brightness accordingly. The loop runs continuously with a delay of 100 milliseconds between iterations.