Night Lamp

From Microduino Wiki
Jump to: navigation, search


Anywhere colorled-light.jpg

Make a night lamp which can adjust the brightness automatically according to the surroundings. When the environment is bright, the night lamp is off. When the environment is dark, the lamp is on.
Suitable kits: mCookie302, IBC

Module Bill


Module Number Function
mCookie-Core 1 Core board
Battery box 1 Program download and power supply
mCookie-Hub 1 Sensor adapter plate
Light sensor 1 Detect the strength of light
Color LED 1 Color LED.

Other Equipment

  • USB cable*1
  • Sensor cable*2
  • Sensor shell*1
  • Lego or other fixation structure
Anywhere colorled-light-module.jpg

Module Setup

Learn about the New Sensor

Light Sensor
The light sensor can induce the change of the surroundings, and convert light signal into electric signal. When used, the photosensitive device should be exposed. Light sensor is analog input sensor.


Anywhere colorled-light-step.jpg
  • Assemble the modules and sensors:
    • Stick the red core module, battery base and green extension module together;
    • Connect the color LED to pin 6/7 of Hub;
    • Connect the light sensor to pin 4/5 of Hub;
    • Insert one end of USB cable into the battery base, and connect the other to computer;


Required Program Blocks

Programming Thought

When the light sensor detects the darker environment, the color LED will emit light; when detects bright environment, the color LED will go off. In this way, the function of night light has been implemented.


The color LED goes on without light, and off with light.
LED prepare, set the LED number to 1, and pin to 6. Use "if-do" program block. If the light sensor detects the light, it will execute color LED off program, and set the RGB value to 0. If the light sensor detects no light, the color LED will be turned on, and the RGB value will be set randomly and the color of the color LED will change.


Test the result
After upload, when the light is strong, the color LED will be off. Cover the light sensor with your hand( the light is weaker), the color LED will be on. In this way, the night lamp is completed!

Anywhere colorled-light.jpg

Technical Specification

  • Product number of the light sensor: MSDT42
  • Analog sensor
  • For details, please refer to Sensor-Light-A1.

Related Cases


  • Q: Is the light sensor a digital signal sensor? Can it only be connected to the digital port?
  • A: No, it is an analog sensor, and it can convert the strength of the light into that of electric signal of which the range is 0-5V. If connected to digital port and the converted voltage is larger than 2.5V(strong light), the range is 1(true). Otherwise(weak light), it is 0(false).