Difference between revisions of "Light Indicator"

From Microduino Wiki
Jump to: navigation, search
 
Line 28: Line 28:
  
 
==Preparation==
 
==Preparation==
*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 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 2:Download the program:  
+
*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 3:Load the code, choose the right board and COM port for program download after compiling.  
+
* 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.  
+
*"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 1:Connect the photosensitive resistor to the A0 pin of the Sensorhub and the Color LED to D6.  
+
*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 2:Connect the activated battery box and the BM module.  
+
*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 3:Then, stack all modules together without considering order. Congratulations! You've finished the circuit buildup.  
+
*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  • 中文

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