Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Raspberry Pi-Controlled LED Lighting System with Time-Based Color Switching

View and Edit Project In Cirkit DesignerImage of Raspberry Pi-Controlled LED Lighting System with Time-Based Color Switching

Circuit Documentation

Summary

The circuit in question appears to be a lighting control system utilizing a Raspberry Pi 5 as the central microcontroller. The system is designed to control two sets of LEDs (blue and green) through MOSFET switches. The LEDs are connected in series with resistors to limit the current. The Raspberry Pi 5 controls the MOSFETs, which in turn switch the LEDs on and off. The blue LEDs are programmed to turn on during a specific time window, while the green LEDs are turned on indefinitely. The circuit is powered by a USB power source.

Component List

Resistors

LEDs

MOSFET Switch SPDT

Raspberry Pi 5

USB Power

Wiring Details

Resistors

LEDs

MOSFET Switch SPDT

Raspberry Pi 5

USB Power

Documented Code

import RPi.GPIO as GPIO
import time
from datetime import datetime

# Pin definitions
GREEN_LED_CTRL_PIN = 4  # GPIO pin connected to the control pin of the MOSFET for green LEDs
BLUE_LED_CTRL_PIN = 17   # GPIO pin connected to the control pin of the MOSFET for blue LEDs

# Setup
GPIO.setmode(GPIO.BCM)
GPIO.setup(GREEN_LED_CTRL_PIN, GPIO.OUT)
GPIO.setup(BLUE_LED_CTRL_PIN, GPIO.OUT)

# Turn on green LEDs
GPIO.output(GREEN_LED_CTRL_PIN, GPIO.HIGH)

try:
    while True:
        current_time = datetime.now().time()
        if current_time >= datetime.strptime("18:00", "%H:%M").time() and current_time <= datetime.strptime("22:00", "%H:%M").time():
            GPIO.output(BLUE_LED_CTRL_PIN, GPIO.HIGH)  # Turn on blue LEDs
        else:
            GPIO.output(BLUE_LED_CTRL_PIN, GPIO.LOW)   # Turn off blue LEDs
        time.sleep(60)  # Check every minute
except KeyboardInterrupt:
    pass
finally:
    GPIO.cleanup()

This code is designed to run on the Raspberry Pi 5. It sets up two GPIO pins as outputs to control the MOSFETs that power the green and blue LEDs. The green LEDs are turned on as soon as the program starts. The blue LEDs are controlled based on the current time: they are turned on between 18:00 and 22:00 and turned off otherwise. The time is checked every minute to update the state of the blue LEDs.