Light Indicator

From Microduino Wiki
Jump to: navigation, search
Language: English  • 中文

Objective

Here we make a simple light indicator, which divides light value into three levels, that is, green, blue and red.

Principle

We adopt the Light sensor to detect the light intensity. The system can judge which range the light intensity lies and let the LED present the corresponding color. In the same range, the color gets brighter along with the light intensity increases.

Light indicator-sch.jpg

Equipment

Module Number Function
Microduino-CoreUSB 1 Core board
SMicroduino-Sensorhub 1 Sensor pinboard
Microduino-Light 1 light-sensitive sensor
Microduino-Color LED 1 Colored led light
Microduino-BM 1 Battery management

Preparation

  • Setup 1: Use a USB cable to connect the CoreUSB and the PC/Mac, the open Arduino IDE.
    CoreUSB Ble pc.jpg
  • Setup 2: Download the program:

light_led

  • Setup 3: Load the code, choose the right board and COM port for program download after compiling.

Program Description

  • Pin Definition of the sensor: The Color LED connects to D6 and the Light sensor connects to A0.
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800);

#define Light_PIN A0
  • Light intensity pre-set values: You can classify the light into three levels.
#define Light_value1 400
#define Light_value2 800
  • Light detection
sensorValue = analogRead(Light_PIN);
  • The Color LED can adjust color and brightness according to light intensity.
if (sensorValue < Light_value1)
    colorWipe(strip.Color(0, map(sensorValue, 10, 400, 0, 255), 0));
  else if (sensorValue >= Light_value1 && sensorValue < Light_value2)
    colorWipe(strip.Color(0, 0, map(sensorValue, 400, 800, 0, 255)));
  else if (Light_value2 >= 800)
    colorWipe(strip.Color(map(sensorValue, 800, 960, 0, 255), 0, 0));
  • "map(val,x,y,m,n)"is the reflection function, which can reflect the (x-y) value of a certain range to (m-n). "val" is the data that you need to reflect.

Hardware Buildup

  • Setup 1: Connect the photosensitive resistor to the A0 pin of the Sensorhub and the Color LED to D6.
  • Setup 2: Connect the activated battery box and the BM module.
CoreUSB Ble steup2.jpg
  • Setup 3: Then, stack all modules together without considering order. Congratulations! You've finished the circuit buildup.

Result

By changing the light environment, the light from dark to bright colors are changed to green - blue - red, and the weaker the light is, the lower the brightness becomes. You can also build a beautiful look for this project through Lego boards.

Video