BakeBit - Light Sensor
- The BakeBit - Light Sensor is a photoresistor module. The resistance of a photoresistor decreases with increasing incident light intensity.
- If incident light on a photoresistor exceeds a certain frequency, photons absorbed by the semiconductor give bound electrons enough energy to jump into the conduction band. The resulting free electrons (and their hole partners) conduct electricity, thereby lowering resistance.
- Standard 2.0mm pitch 4-Pin BakeBit Interface
- PCB dimension(mm): 20 x 24
- Analog Outpu
- Pin Description:
|5V||5V Supply Voltage|
Code Sample: Smart Lighting
By running this code sample your system adjusts the LEDs on the LED module(LED Bar) according to surrounding lightness. When the surrounding environment becomes darker the LEDs will be brighter. When the surrounding becomes bright enough the LEDs will be completely off. A BakeBit - LED Bar module is needed in this test case.
Connect the BakeBit - LED Bar module to the NanoHat Hub's D3 and the BakeBit - Light Sensor module to the NanoHat Hub's A0:
import time import bakebit # Connect the BakeBit Light Sensor to analog port A0 # SIG,NC,VCC,GND light_sensor = 0 # Connect the BakeBit LED Bar to digital port D3 # DI,DCKI,VCC,GND ledbar = 3 lowThreshold = 500 highTreshold = 600 bakebit.pinMode(light_sensor,"INPUT") bakebit.pinMode(ledbar,"OUTPUT") time.sleep(.2) bakebit.bakeBitLedBar_Init(ledbar, 0, 5) time.sleep(.5) old_color = 0 while True: try: light_count = 0 # Get sensor value sensor_value = bakebit.analogRead(light_sensor) if sensor_value > highTreshold: f=(1023-highTreshold)/4 light_count = (sensor_value-highTreshold)/f+1 # turn on ledbar color16bit = bakebit.Green if light_count > 1: color16bit = color16bit | (bakebit.Green << 3) if light_count > 2: color16bit = color16bit | (bakebit.Green << 6) if light_count > 3: color16bit = color16bit | (bakebit.Green << 9) if light_count > 4: color16bit = 0 color16bit = color16bit | bakebit.Blue color16bit = color16bit | (bakebit.Blue << 3) color16bit = color16bit | (bakebit.Blue << 6) color16bit = color16bit | (bakebit.Blue << 9) color16bit = color16bit | (bakebit.Blue << 12) if color16bit != old_color: old_color = color16bit lowBits = color16bit & 255 highBits = (color16bit & (255 << 8)) >> 8 bakebit.bakeBitLedBar_Show(ledbar, highBits, lowBits) elif sensor_value < lowThreshold: # turn off ledbar bakebit.bakeBitLedBar_Show(ledbar, 0, 0) print("sensor_value = %d light_count =%d" %(sensor_value, light_count)) time.sleep(.5) except KeyboardInterrupt: bakebit.bakeBitLedBar_Release(ledbar) time.sleep(.2) break except IOError: print ("Error")
Run Code Sample
Before you run the code sample you need to follow the steps in bakebit tutorial to install the BakeBit package.
Enter the "BakeBit/Software/Python" directory and run the "bakebit_prj_SmartLighting.py" program:
cd ~/BakeBit/Software/Python sudo python bakebit_prj_SmartLighting.py
When you cover the smart lighting’s photo sensor or make the surrounding environment brighter the LEDs will be on or off.
The LEDs on the LED Bar module will be turned on or off according to surrounding environment’s lightness. When the the surrounding environment becomes darker more LEDs will be turned on otherwise the LEDs will be off.
- [Schematic](BakeBit - Light Sensor.pdf)
- [BakeBit Github Project Page](https://github.com/friendlyarm/BakeBit)
- [BakeBit Starter Kit User's Manual](http://wiki.friendlyarm.com/bakebit/bakebit_starter_kit_manual_en.pdf)
- Released English version
- Renamed "NEO-Hub" to "NanoHat-Hub"
- Renamed "NanoHat-Hub" to "NanoHat Hub"