Difference between revisions of "Light Indicator"
From Microduino Wiki
Line 28: | Line 28: | ||
==Preparation== | ==Preparation== | ||
− | *Setup | + | *Setup 1: Use a USB cable to connect the CoreUSB and the PC/Mac, the open Arduino IDE. [[File:CoreUSB_Ble_pc.jpg|600px|center]] |
− | *Setup | + | *Setup 2: Download the program: |
[https://github.com/Microduino/Microduino_Tutorials/blob/master/MCookie_Tutorial/light_led/light_led.ino light_led] | [https://github.com/Microduino/Microduino_Tutorials/blob/master/MCookie_Tutorial/light_led/light_led.ino light_led] | ||
[[File: light_indicator-load.jpg|600px|center]] | [[File: light_indicator-load.jpg|600px|center]] | ||
− | * Setup | + | * Setup 3: Load the code, choose the right board and COM port for program download after compiling. |
==Program Description== | ==Program Description== | ||
*Pin Definition of the sensor: The Color LED connects to D6 and the Light sensor connects to A0. | *Pin Definition of the sensor: The Color LED connects to D6 and the Light sensor connects to A0. | ||
Line 61: | Line 61: | ||
colorWipe(strip.Color(map(sensorValue, 800, 960, 0, 255), 0, 0)); | colorWipe(strip.Color(map(sensorValue, 800, 960, 0, 255), 0, 0)); | ||
</source> | </source> | ||
− | * | + | *"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== | ==Hardware Buildup== | ||
− | *Setup | + | *Setup 1: Connect the photosensitive resistor to the A0 pin of the Sensorhub and the Color LED to D6. |
[[file: light_indicator _A0_6.JPG|800px|center]] | [[file: light_indicator _A0_6.JPG|800px|center]] | ||
− | *Setup | + | *Setup 2: Connect the activated battery box and the BM module. |
[[File:CoreUSB_Ble_steup2.jpg|600px|center]] | [[File:CoreUSB_Ble_steup2.jpg|600px|center]] | ||
− | *Setup | + | *Setup 3: Then, stack all modules together without considering order. Congratulations! You've finished the circuit buildup. |
[[File: ight_indicator_steup-all.jpg|600px|center]] | [[File: ight_indicator_steup-all.jpg|600px|center]] | ||
==Result== | ==Result== |
Latest revision as of 06:57, 30 September 2016
Language: | English • 中文 |
---|
ContentsObjectiveHere we make a simple light indicator, which divides light value into three levels, that is, green, blue and red.PrincipleWe 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. Equipment
Preparation
Program Description
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800);
#define Light_PIN A0
#define Light_value1 400
#define Light_value2 800
sensorValue = analogRead(Light_PIN);
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));
Hardware Buildup
ResultBy 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 |