Arduino UNO Q - Light Sensor Control LED

In this guide, you will learn how to:

Arduino UNO Q Light Sensor controls LED

Hardware Preparation

1×Arduino UNO Q
1×USB Cable for Arduino Uno Q
1×Light Sensor
1×LED Kit
1×LED (red)
1×LED Module
1×220Ω Resistor
1×10 kΩ Resistor
1×Breadboard
1×Jumper Wires
1×Recommended: Screw Terminal Block Shield for Arduino Uno
1×Recommended: Sensors/Servo Expansion Shield for Arduino Uno
1×Recommended: Breadboard Shield for Arduino Uno
1×Recommended: Enclosure for Arduino Uno
1×Recommended: Prototyping Base Plate & Breadboard Kit for Arduino UNO

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Buy Note: Use the LED Module for easier wiring. It includes an integrated resistor.

The LDR light sensor requires a resistor for wiring. To simplify the setup, you can use an LDR light sensor module as an alternative.

Overview of LED and Light Sensor

Learn about LED and light sensors in the tutorials below:

Wiring Diagram

The wiring diagram between Arduino UNO Q Light Sensor LED

This image is created using Fritzing. Click to enlarge image

MCU Code

The Arduino UNO Q has two processors: the STM32 MCU (handles real-time hardware control) and the Qualcomm MPU (runs Debian Linux). In this section, only the STM32 MCU is programmed — the Linux side stays idle. A later section will show how both processors work together.

※ NOTE THAT:

The Arduino UNO Q STM32 MCU has a 12-bit ADC (0–4095) with a 3.3V reference. The threshold in the code is scaled accordingly compared to 10-bit Arduino boards (0–1023).

/* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-light-sensor-controls-led */ #define LIGHT_SENSOR_PIN A0 // The Arduino UNO Q pin connected to the light sensor #define LED_PIN 3 // The Arduino UNO Q pin connected to the LED #define ANALOG_THRESHOLD 200 // Scaled for 12-bit ADC (0-4095) on Arduino UNO Q int analogValue; void setup() { pinMode(LED_PIN, OUTPUT); } void loop() { analogValue = analogRead(LIGHT_SENSOR_PIN); // 0-4095 on Arduino UNO Q (12-bit, 3.3V) if (analogValue < ANALOG_THRESHOLD) digitalWrite(LED_PIN, HIGH); // turn on LED else digitalWrite(LED_PIN, LOW); // turn off LED }

Detailed Instructions

  • First time with Arduino UNO Q? Follow the Getting Started with Arduino UNO Q tutorial to get your development environment ready before proceeding.
  • Wire the components: Connect the photoresistor and 10 kΩ resistor (voltage divider) to A0. Connect the LED (with 220 Ω resistor) to pin 3.
  • Connect: Plug the Arduino UNO Q into your computer with a USB-C cable.
  • Open Arduino App Lab: Launch Arduino App Lab and wait until it detects your Arduino UNO Q.
  • Create a new App: Click the Create New App button.
Create New App in Arduino App Lab on Arduino UNO Q
  • Give the App a name, for example: DIYables_LightSensorLED
  • Click Create to confirm.
  • You will see a set of folders and files generated inside your new App.
Arduino App Lab App folders and files on Arduino UNO Q
  • Find the sketch/sketch.ino file — this is where you will paste the MCU sketch.
  • Paste the sketch: Copy the MCU code above and paste it into the sketch file. Keep other files as default.
    • Install the library: Click the Add sketch library button (the open book icon with a + sign) in the left sidebar.
    Add sketch library in Arduino App Lab on Arduino UNO Q
    • Search for Arduino_RouterBridge created by Arduino and click the Install button.
    My Apps / DIYables Apps
    Run
    Bricks
    No bricks added...
    Sketch Libraries
    No sketch libra...
    Files
    python
    sketch
    .gitignore
    README.md
    app.yaml
    sketch.ino
    Add sketch library
    Arduino_RouterBridge Arduino

    This library provides a simple RPC bridge for Arduino UNO Q boards, allowing communication between the board and other devices using MsgPack serialization.

    0.4.1
    Install
    More Info
    • Upload: Click the Run button in Arduino App Lab to compile and upload to the STM32.
    Click Run button in Arduino App Lab on Arduino UNO Q
    • Test: Shine a bright light on the sensor — the LED turns on. Cover the sensor — the LED turns off.

    Linux + MCU Bridge Programming

    The Arduino UNO Q has two processors that work together: the MPU (Qualcomm, runs Debian Linux) and the MCU (STM32, runs Zephyr OS with your Arduino sketch). They communicate using RPC via the Arduino_RouterBridge library — never via raw serial ports.

    • The light sensor and LED are both connected to the MCU (STM32) — A0 reads the sensor, pin 3 drives the LED.
    • The MPU cannot control this directly — it calls Bridge.call("check_light") on the MCU, which reads the sensor and sets the LED accordingly.
    • The MPU has Wi-Fi — because the MPU runs full Debian Linux with Wi-Fi, it can run Telegram and loop the check automatically.
    • Communication: Bridge.call() on the Linux side invokes Bridge.provide_safe() on the MCU side (since digitalWrite() is a hardware API)
    • ⚠️ Reserved: /dev/ttyHS1 (Linux) and Serial1 (MCU) are used by the Arduino Router — never open them directly

    In short: Python calls check → MCU reads sensor → MCU sets LED and prints to Monitor.

    MCU sketch — light sensor LED control with Bridge and Monitor output:

    /* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-light-sensor-controls-led */ #include "Arduino_RouterBridge.h" #define LIGHT_SENSOR_PIN A0 #define LED_PIN 3 #define ANALOG_THRESHOLD 200 void check_light() { int value = analogRead(LIGHT_SENSOR_PIN); bool led_on = value < ANALOG_THRESHOLD; digitalWrite(LED_PIN, led_on ? HIGH : LOW); Monitor.print("Sensor: "); Monitor.print(value); Monitor.print(" -> LED: "); Monitor.println(led_on ? "ON" : "OFF"); } void setup() { Bridge.begin(); Monitor.begin(); pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, LOW); Bridge.provide_safe("check_light", check_light); Monitor.println("Light Sensor LED Bridge ready"); } void loop() {}

    Python script (Arduino App Lab) — run light check loop from Linux:

    /* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-light-sensor-controls-led */ from arduino.app_utils import * import time def loop(): Bridge.call("check_light") time.sleep(0.5) App.run(user_loop=loop)
    • Note: Make sure Bridge.begin() is called in the MCU sketch and the sketch is uploaded before running the Python script on the Linux side.
    • ⚠️ Warning: Never directly open /dev/ttyHS1 (on Linux) or use Serial1 (on MCU) in your code — these are reserved by the Arduino Router and accessing them will break the Bridge.

    Detailed Instructions

    • Upload the MCU sketch: Open Arduino App Lab, create a new App, paste the Bridge MCU sketch into sketch/sketch.ino, install the Arduino_RouterBridge library, and click Run.
    • Add the Python script: Paste the Python code above into the Python tab of the same App.
    • Run the App: Click Run — Python calls check_light every 500 ms; the MCU reads the sensor and controls the LED.
    • Check the console: Open the Console tab → MCU Monitor subtab to see sensor values and LED state.

    App Lab Console Output

    DIYables_Apps
    Stop
    sketch.ino
    1#include "Arduino_RouterBridge.h"
    Serial Monitor
    Python
    Message (Enter to send a message to "Newbiely" on usb(2820070321))
    New Line
    9600 baud
    Light Sensor LED Bridge ready Sensor: 145 -> LED: ON Sensor: 152 -> LED: ON Sensor: 890 -> LED: OFF Sensor: 3210 -> LED: OFF Sensor: 48 -> LED: ON

    Telegram Integration

    Monitor the light sensor and LED state remotely via Telegram.

    If you do not have a Telegram bot yet, see How to Create a Telegram Bot to get your bot token before continuing.

    MCU sketch: Keep the same MCU sketch from the previous Bridge section — no changes needed. Make sure it is already uploaded and running on the STM32 before proceeding.

    Python script (Arduino App Lab) — Telegram bot for light sensor LED monitoring:

    /* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-light-sensor-controls-led */ from arduino.app_utils import * import requests import time BOT_TOKEN = "YOUR_BOT_TOKEN" API_URL = f"https://api.telegram.org/bot{BOT_TOKEN}" last_update_id = 0 def send_message(chat_id, text): requests.post(f"{API_URL}/sendMessage", json={"chat_id": chat_id, "text": text}) def get_updates(): global last_update_id resp = requests.get(f"{API_URL}/getUpdates", params={"offset": last_update_id + 1, "timeout": 5}) return resp.json().get("result", []) def loop(): global last_update_id Bridge.call("check_light") # continuously control LED based on light updates = get_updates() for update in updates: last_update_id = update["update_id"] msg = update.get("message", {}) chat_id = msg.get("chat", {}).get("id") text = msg.get("text", "").strip() if text == "/read": status = Bridge.call("check_light") send_message(chat_id, status) else: send_message(chat_id, "Commands:\n/read — check light sensor value and LED state") time.sleep(0.5) App.run(user_loop=loop)
    • Note: Replace YOUR_BOT_TOKEN with the token obtained from @BotFather on Telegram.
    • The bot continuously checks the light sensor and controls the LED while listening for Telegram commands.
    • Send /read to request confirmation that the status was logged to MCU Monitor.

    Detailed Instructions

    • Upload the MCU sketch: Use the Bridge MCU sketch from the previous section (upload it first if not already done).
    • Paste the Telegram script: Copy the Python code above into the Python tab of your App in Arduino App Lab.
    • Set your token: Replace YOUR_BOT_TOKEN in the script with your actual bot token.
    • Run the App: Click Run — the bot starts controlling the LED and listening for Telegram messages.
    • Test it: Send /read — the bot replies with the current sensor value and LED state.

    App Lab Console Output

    DIYables_Apps
    Stop
    sketch.ino
    1#include "Arduino_RouterBridge.h"
    Serial Monitor
    Python
    [2026-04-29 12:00:01] Telegram: /read [2026-04-29 12:00:01] Sensor: 150 -> LED: ON
    Telegram
    Telegram 12:45
    Welcome to Telegram!
    ArduinoBot 10:19
    Chatting with Arduino...
    telegram-botfather
    BotFather Yesterday
    Your bot has been created.

    ArduinoBot

    bot
    Today
    /read
    10:15 AM ✓✓
    Sensor: 150 -> LED: ON
    10:16 AM

    OpenClaw Integration

    OpenClaw integration for Arduino UNO Q light sensor controls LED is coming soon.

    • Coming Soon: OpenClaw support for this project on Arduino UNO Q will be covered in a future update.

    Application/Project Ideas

    • Automatic desk lamp: Turn on an LED (or LED strip via relay) when ambient light drops below a threshold
    • Display backlight control: Dim or brighten a display based on surrounding light levels
    • Smart aquarium light: Automatically switch aquarium lighting ON at sunset and OFF at sunrise
    • Night mode indicator: Use an LED to signal that it is dark enough for low-power mode
    • Greenhouse light supplement: Add supplemental LED grow light when natural light is insufficient

    Challenge Yourself

    • Easy: Adjust the ANALOG_THRESHOLD value so the LED turns on at twilight rather than very bright light
    • Medium: Send a Telegram alert when the LED turns on or off (light-change event notification)
    • Advanced: Implement a hysteresis band (e.g., turn on below 150, turn off above 300) to prevent rapid flickering at the threshold

    ※ OUR MESSAGES

    • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
    • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!