• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomepcDuinoUse Light sensor on pcduino
Previous Next

Use Light sensor on pcduino

Posted by: Alvin Jin , February 25, 2014

[vc_row][vc_column width=”1/1″][vc_tour][vc_tab title=” Module Introduction” tab_id=”1393392270-1-79″][vc_column_text]QQ图片20140225235444

Light sensor is a module, which can sense the environment light intensity, its core component is a photosensitive resistance. The resistance of the device will change as the environment light intensity changes, so that this signal can be turned into electrical signals. We only use pcduino ADC function can know the change of light intensity.[/vc_column_text][/vc_tab][vc_tab title=”Wiring Diagram” tab_id=”1393392270-2-63″][vc_column_text]QQ图片20140225235447

Wiring Diagram:Power supply (VCC) is connected to 3.3v of pcduino , wire(GND) is connected to GND of pcduino. Signal output (SIG) is connected to analog signal input port (A0 – A5), A0-A5 any one is ok.( recommend connect to the port above A2, because of A0, A1 ADC precision only six, we may not see obvious change.But it must be defined as same as the routine code.[/vc_column_text][/vc_tab][vc_tab title=”Demo Code” tab_id=”1393393253804-2-2″][vc_column_text]

#include <core.h>
int adc_id = 2;
int delay_us = 100000;
int HistoryValue = 0;
void setup()
{
}
void loop()
{
    int value = analogRead(adc_id); // get adc value
    if(((HistoryValue>=value) && ((HistoryValue - value) > 10)) || ((HistoryValue<value) && ((value - HistoryValue) > 10)))
       printf("ADC%d level is %d\n",adc_id, value);
    HistoryValue = value;
    delayMicroseconds(delay_us); 
}

[/vc_column_text][/vc_tab][vc_tab title=”Operating Results” tab_id=”1393393700644-3-8″][vc_column_text]when our hand pass by the module, we can see output changes.

QQ图片20140225235454[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]

Tags: pcDuino

Share!
Tweet

Alvin Jin

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors