Autonomous Lighting

The Automatic LED Turn On/Off application is a Python-based project that integrates an SMD Motor Driver, an add-on LED Module, and an Ambient Light Sensor Module to create an intelligent lighting system. This project is designed to automatically control the state of an LED based on the ambient light conditions, providing an energy-efficient solution for various environments.

Project Media:

Project Key Components:

  1. SMD Motor Driver:

    • The SMD Motor Driver serves as the communication interface between the Python script and the connected hardware components. It interprets commands from the script and translates them into actions that control the LED based on ambient light readings.

  2. LED Module Add-on:

    • An additional LED module is connected to the SMD Motor Driver. This module functions as the output device, displaying the result of the Python script's commands to turn the LED on or off.

  3. Ambient Light Sensor Module:

    • An Ambient Light Sensor Module is integrated into the project to measure the surrounding light intensity. The sensor provides feedback to the Python script, enabling it to make decisions about whether to turn the LED on or off.

  4. Python Script:

    • The Python script is the central component of the application. It establishes communication with the SMD Motor Driver, reads data from the Ambient Light Sensor Module, and sends commands to control the LED based on the ambient light conditions.

Project Key Features:

  1. Automatic Light Sensing:

    • The application leverages the Ambient Light Sensor Module to continuously monitor the ambient light conditions. When the environment is dark, the script commands the LED to turn on. Conversely, when sufficient light is detected, the LED is turned off.

  2. Energy-Efficient Operation:

    • By automatically adjusting the LED state based on ambient light levels, the application promotes energy efficiency. The LED is only active when needed, reducing unnecessary power consumption.

  3. Real-time Monitoring:

    • The Python script may include real-time monitoring of the ambient light sensor readings, providing users with insights into how the system responds to changing light conditions.

Project Wiring Diagram:

Getting Started:

  1. Hardware Setup:

    • Connect the SMD Motor Driver to both the LED module and the Ambient Light Sensor Module following the provided documentation.

    • Ensure secure connections and provide appropriate power to the hardware components.

  2. Run the Python Script:

    • Execute the Python script on your computer. This will establish communication with the SMD Motor Driver, continuously monitor the ambient light conditions through the sensor, and control the LED based on the readings.

  3. Observe Automatic Operation:

    • Observe how the LED automatically turns on when the environment becomes dark and turns off when there is sufficient ambient light.

Project Codes:

from smd.red import *

SerialPort = "COM3"     # Serial port of the USB gateway module
baudrate = 115200       # Baud rate of communication
ID = 0                  # ID of the SMD board
rgb_module_id = 1       # ID of the RGB module
ambient_module_id = 1    # ID of the ambient light module

master = Master(SerialPort, baudrate)       # Defines the USB gateway module
master.attach(Red(ID))                      # Gives acces to the SMD of specified ID

while True:
    light = master.get_light(ID, ambient_module_id)             # Variable to store the ambient light data
    print(light)                                                # Printing the value to observe 

    if light < 30:
        master.set_rgb(ID, rgb_module_id, 255, 255, 255)        # Numbers are correspond to the R - G - B color values
    else:
        master.set_rgb(ID, rgb_module_id, 0, 0, 0)              # Sets all colors to zero, meaning turning the RGB LED off

Last updated