1. Home
  2. /
  3. Circuitpython
  4. /
  5. Light Sensor Alert

Light Sensor Alert - Circuitpython Typing CST Test

Loading…

Light Sensor Alert — Circuitpython Code

Monitors light sensor and turns on LED if it is dark.

import random
import board
import digitalio

led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT
lightLevel = random.randint(0,100)
if lightLevel < 50:
	led.value = True
	print("LED ON")
else:
	led.value = False
	print("LED OFF")
print(f"Light Level: {lightLevel}")

Circuitpython Language Guide

CircuitPython is an open-source derivative of MicroPython, designed by Adafruit to simplify programming microcontrollers for beginners and makers. It emphasizes easy setup, rapid prototyping, and accessible hardware interaction with Python.

Primary Use Cases

  • ▸Educational programming for beginners
  • ▸Prototyping embedded electronics projects
  • ▸Interactive art and maker projects
  • ▸Home automation with microcontrollers
  • ▸Quick testing of sensors and hardware modules

Notable Features

  • ▸Easy-to-use Python APIs for hardware
  • ▸Cross-platform USB support for code editing
  • ▸Automatic code execution on device boot
  • ▸Wide library support for sensors and peripherals
  • ▸Interactive REPL for real-time experimentation

Origin & Creator

Created by Adafruit Industries in 2017, based on MicroPython, to make Python accessible for beginners working with microcontrollers.

Industrial Note

CircuitPython is primarily educational and hobbyist-focused, though it can also be used for light industrial prototyping and interactive installations.

More Circuitpython Typing Exercises

CircuitPython Counter and LED Theme ToggleCircuitPython Temperature Sensor MonitorCircuitPython Button Press CounterCircuitPython LED BlinkerCircuitPython Buzzer AlertCircuitPython Motor ControlCircuitPython Distance Sensor MonitorCircuitPython Humidity Sensor MonitorCircuitPython Multi-Sensor Dashboard

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher