The Grove - Light Sensor module incorporates a Light Dependent Resistor (LDR). Typically, the resistance of the LDR or Photoresistor will decrease when the ambient light intensity increases. This means that the output signal from this module will be HIGH in bright light, and LOW in the dark.
Follow these steps to build a sample circuit using this module but without using any microcontroller:
LED stays OFF in bright light
LED turns ON in the dark
You can use either the Grove - USB Power module or the Grove - DC Jack Power module for the Grove circuit.
Follow these simple steps to build a Grove circuit using the light sensor:
/* /* Grove - Light Sensor demo v1.0 * * signal wire to A0. * By: http://www.seeedstudio.com */ #include <math.h> const int ledPin=12; //Connect the LED Grove module to Pin12, Digital 12 const int thresholdvalue=10; //The threshold for which the LED should turn on. float Rsensor; //Resistance of sensor in K void setup() { Serial.begin(9600); //Start the Serial connection pinMode(ledPin,OUTPUT); //Set the LED on Digital 12 as an OUTPUT } void loop() { int sensorValue = analogRead(0); Rsensor=(float)(1023-sensorValue)*10/sensorValue; if(Rsensor>thresholdvalue) { digitalWrite(ledPin,HIGH); } else { digitalWrite(ledPin,LOW); } Serial.println("the analog read data is "); Serial.println(sensorValue); Serial.println("the sensor resistance is "); Serial.println(Rsensor,DEC);//show the light intensity on the serial monitor; delay(1000); }
For further information on the illuminance-resistance characteristics of the LDR used by this Grove module, refer to the GL5528 datasheet.
Follow these simple steps to build a Grove circuit with LinkIt ONE using the light sensor:
/* /* Grove - Light Sensor demo v1.0 * * signal wire to A0. * By: http://www.seeedstudio.com */ #include <math.h> const int ledPin=12; //Connect the LED Grove module to Pin8, Digital 8 const int thresholdvalue=10; //The threshold for which the LED should turn on. float Rsensor; //Resistance of sensor in K void setup() { Serial.begin(9600); //Start the Serial connection pinMode(ledPin,OUTPUT); //Set the LED on Digital 8 as an OUTPUT } void loop() { int sensorValue = analogRead(0); Rsensor=(float)(1023-sensorValue)*10/sensorValue; if(Rsensor>thresholdvalue) { digitalWrite(ledPin,HIGH); } else { digitalWrite(ledPin,LOW); } Serial.println("the analog read data is "); Serial.println(sensorValue); Serial.println("the sensor resistance is "); Serial.println(Rsensor,DEC);//show the light intensity on the serial monitor; delay(1000); }
Sensing the Light (Light Sensor)
/* Light Sensor A simple program that display the value of light incident on the grove-light-sensor by grove-4-digital-display, this example is definitely similar to grove-rotary-angle-sensor The circuit: * grove-4-digital-display attached to dio9&dio10 (IIC plug on Grove Base BoosterPack) * sig pin of the light sensor to the analog pin * one side pin (either one) to ground * the other side pin to VCC * Note: Created by Oliver Wang This example code is in the public domain. http://www.seeedstudio.com/depot/Grove-Light-Sensor-p-746.html?cPath=25_27 */ #include "TM1637.h" /* Macro Define */ #define CLK 39 /* 4-digital display clock pin */ #define DIO 38 /* 4-digital display data pin */ #define LIGHT_SENSOR 24 /* pin of grove light sensor */ /* Global Variables */ TM1637 tm1637(CLK, DIO); /* 4-digital display object */ int analog_value = 0; /* variable to store the value coming from rotary angle sensor */ int8_t bits[4] = {0}; /* array to store the single bits of the value */ /* the setup() method runs once, when the sketch starts */ void setup() { /* Initialize 4-digital display */ tm1637.init(); tm1637.set(BRIGHT_TYPICAL); } /* the loop() method runs over and over again */ void loop() { analog_value = analogRead(LIGHT_SENSOR); /* read the value from the sensor */ memset(bits, 0, 4); /* reset array when we use it */ for(int i = 3; i >= 0; i--) { /* get single bits of the analog value */ bits[i] = analog_value % 10; analog_value = analog_value / 10; tm1637.display(i, bits[i]); /* display by 4-digital display */ } }
First step, you should connect to Raspberry Pi+ with Grove - Light Sensor and Grove - Green LED. Such as the following picture. Then run the program on your Raspberry Pi, and it will print brightness information on the terminal. When brightness is less than a certain value, the LED will turn on.
# GrovePi+ & Grove Light Sensor & LED import time import grovepi # Connect the Grove Light Sensor to analog port A0 # SIG,NC,VCC,GND light_sensor = 0 # Connect the LED to digital port D4 # SIG,NC,VCC,GND led = 4 # Turn on LED once sensor exceeds threshold resistance threshold = 10 grovepi.pinMode(light_sensor,"INPUT") grovepi.pinMode(led,"OUTPUT") while True: try: # Get sensor value sensor_value = grovepi.analogRead(light_sensor) # Calculate resistance of sensor in K resistance = (float)(1023 - sensor_value) * 10 / sensor_value if resistance > threshold: # Send HIGH to switch on LED grovepi.digitalWrite(led,1) else: # Send LOW to switch off LED grovepi.digitalWrite(led,0) print "sensor_value =", sensor_value, " resistance =", resistance time.sleep(.5) except IOError: print "Error"
cd GrovePi/Software/Python/
sudo python grove_light_sensor.py
This Grove module is available as part of the following Grove Kit Series:
Alternatively, it can be bought stand-alone here at the Seeed Studio Bazaar.
Note that there is another variant of this module available - the Grove - Light Sensor (Panel Mount). This module is identical to the Grove - Light Sensor except that the Grove connector is moved to the back of the PCB. This way, the on-board LDR is not obstructed by any wires and can be placed neatly for optimal use.
If you want to make some awesome projects by LinkIt ONE, here's some projects for reference.
This is an IoT demo make by LinkIt ONE and Grove.
With this demo, we can:
Halloween is an autumn holiday that celebrate every year. In the “holy evening”, lovely children pick large orange pumpkins and carry bags from house to house saying “Trick or treat! Money or eat”. The grown-ups put treat-money or candy in their bags with a smile. However, the burning candle inside the pumpkins is always a danger. Don’t worry. Our cool play makers have made a Halloween Pumpkin with Techbox Tricks. There is a light-control switch in the Halloween Pumpkin, which can check light in the circumstance. The colorful lights can be turned on automatically in the dark and turned off when there is a light source.
Catching the idea of “Light Pouring Cup” the evening I poured water from one cup into another. It would be cool if you can play with light in the dark. Then I found some interesting module to complete it.
Maybe you have trouble in bringing in your clothes when you are out in the evening. So do I. Then I made a model to solve the problem just for fun. But the making process is interesting and I want to share with you.
Do you want to make a fan ? I will show how to make a beautiful fan.which is base on Grove - Mini Fan,This module is to drive DC motor,The soft-leaved fan also included in the pack can be attached to the motor to make a fun project with kids. Being soft-leaved, the fan is completely safe and there is no chance of any injury even if it is moving at a high speed.Mini fan is control by light sensor in this project.Mini fan will run when light sensor in bright light,and it will stop when light sensor in the dark.
Copyright (c) 2008-2016 Seeed Development Limited (www.seeedstudio.com / www.seeed.cc)