Learn Circuitpython - 10 Code Examples & CST Typing Practice Test
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.
View all 10 Circuitpython code examples →
Learn CIRCUITPYTHON with Real Code Examples
Updated Nov 21, 2025
Code Sample Descriptions
CircuitPython Counter and LED Theme Toggle
import board
import digitalio
count = 0
isDark = False
led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT
def updateUI():
print(f"Counter: {count}")
if isDark:
led.value = True
print("Theme: Dark")
else:
led.value = False
print("Theme: Light")
def increment():
global count
count += 1
updateUI()
def decrement():
global count
count -= 1
updateUI()
def reset():
global count
count = 0
updateUI()
def toggleTheme():
global isDark
isDark = not isDark
updateUI()
# Simulate actions
updateUI()
increment()
increment()
toggleTheme()
decrement()
reset()
Demonstrates a simple counter with theme toggling using CircuitPython variables and microcontroller GPIO control (LED indicator).
CircuitPython Temperature Sensor Monitor
import random
def readTemp():
return random.randint(20,35) # Simulated sensor
temp = readTemp()
print(f"Temperature: {temp}")
if temp > 30:
print("Warning: High Temperature!")
Reads temperature from a sensor and prints alerts.
CircuitPython Button Press Counter
presses = 0
def buttonPressed():
global presses
presses += 1
print(f"Button pressed: {presses}")
buttonPressed()
buttonPressed()
buttonPressed()
Counts the number of button presses and prints the count.
CircuitPython LED Blinker
import time
import board
import digitalio
led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT
for i in range(3):
led.value = True
print("LED ON")
time.sleep(0.5)
led.value = False
print("LED OFF")
time.sleep(0.5)
Blinks an LED on and off three times.
CircuitPython Light Sensor Alert
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}")
Monitors light sensor and turns on LED if it is dark.
CircuitPython Buzzer Alert
import random
sensorValue = random.randint(50,150)
if sensorValue > 100:
print("Buzzer ON")
else:
print("Buzzer OFF")
print(f"Sensor: {sensorValue}")
Activates buzzer if a threshold value is exceeded.
CircuitPython Motor Control
motorActive = True
if motorActive:
print("Motor ON")
else:
print("Motor OFF")
motorActive = False
if motorActive:
print("Motor ON")
else:
print("Motor OFF")
Starts and stops a motor based on a condition.
CircuitPython Distance Sensor Monitor
import random
distance = random.randint(5,20)
if distance < 10:
print("Alert: Object too close!")
print(f"Distance: {distance}")
Reads a distance sensor and prints alerts if object is too close.
CircuitPython Humidity Sensor Monitor
import random
humidity = random.randint(20,80)
if humidity < 30:
print("Too Dry!")
if humidity > 70:
print("Too Humid!")
print(f"Humidity: {humidity}")
Monitors humidity and prints if it is too high or low.
CircuitPython Multi-Sensor Dashboard
import random
import board
import digitalio
led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT
temp = random.randint(25,35)
light = random.randint(0,100)
if temp>30 or light<50:
led.value=True
print("LED ON")
else:
led.value=False
print("LED OFF")
print(f"Temp: {temp}, Light: {light}")
Reads multiple sensors and updates LED/buzzer accordingly.
Frequently Asked Questions about Circuitpython
What is Circuitpython?
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.
What are the primary use cases for Circuitpython?
Educational programming for beginners. Prototyping embedded electronics projects. Interactive art and maker projects. Home automation with microcontrollers. Quick testing of sensors and hardware modules
What are the strengths of Circuitpython?
Extremely beginner-friendly. Rapid prototyping and iteration. Cross-platform editing from Windows, macOS, Linux. Extensive Adafruit and community libraries. Real-time experimentation with hardware
What are the limitations of Circuitpython?
Not suitable for performance-critical embedded tasks. Limited memory and storage on microcontrollers. Not ideal for multi-threaded or heavy computation. Smaller ecosystem compared to full Python. Primarily focused on Adafruit hardware
How can I practice Circuitpython typing speed?
CodeSpeedTest offers 10+ real Circuitpython code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.