Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
rypsmith
Published © GPL3+

Micro:Bit Light Sensor

Use a mini photocell wired with a breadboard and breadout board for the micro:bit to make a simple light sensor!

BeginnerShowcase (no instructions)1 hour4,086
Micro:Bit Light Sensor

Things used in this project

Hardware components

Resistor 10k ohm
Resistor 10k ohm
×1
SparkFun Mini Photocell
×1
Breadboard (generic)
Breadboard (generic)
×1
SparkFun micro:bit Breakout (with Headers)
×1
BBC micro:bit board
BBC micro:bit board
×1

Story

Read more

Schematics

Wiring Guide

Instructions building using block-based editor

Code

Light Sensor Code

Python
Fairly straightforward code. See attached pdf for block-based example too.
from microbit import *

while True:
    lightSensor = pin0.read_analog()
    if lightSensor > 512:
        sun = Image("90909:"
                    "09990:"
                    "99999:"
                    "09990:"
                    "90909")
        display.show(sun)
    elif lightSensor < 512:
        moon = Image("99900:"
                     "09990:"
                     "00990:"
                     "09990:"
                     "99900")
        display.show(moon)

Credits

rypsmith

rypsmith

1 project • 2 followers

Comments