Grove - Light Sensor

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.




Features

Specifications

Getting Started

Standalone

Follow these steps to build a sample circuit using this module but without using any microcontroller:

  1. Connect the light sensor module to the input side of your circuit (to the left of the power module). On the output side of the circuit, you may use a range of User Interface modules (Grove - Red LED, Grove - LED String Light, Grove - Mini Fan, Grove - Buzzer, Grove - Recorder etc.)
  2. Power up the circuit when complete.
  3. The light sensor module can now be used to trigger an output. For example:
  • When used in conjunction with a Grove - Red LED output module, observe that the LED turns ON when the light sensor detects bright light and turns off in the dark. To simulate the dark, just cover the light sensor module with your hand and see what happens. The same behavior can be seen when the light sensor is used with the Grove - LED String Light module.
  • Add a Grove - NOT module between the light sensor and the power module to reverse the logic that triggers the LEDs on the Grove - Red LED or Grove - LED String Light modules. With the addition of the Logical NOT gate on the input side, you should see that the LEDs remain OFF in bright light and turn ON in the dark.

You can use either the Grove - USB Power module or the Grove - DC Jack Power module for the Grove circuit.

With Arduino

Follow these simple steps to build a Grove circuit using the light sensor:

  1. When using the module in conjunction with an Arduino or a Seeeduino, use the Grove - Base Shield and connect the Grove - Light Sensor module to the shield using a designated Grove Interface. Also attach an output module such as a Grove - Red LED which will get triggered based on input received from the light sensor (shown below).
  2. Upload the following sample sketch to make the LED turn ON and OFF based on input from 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.

With LinkIt ONE

Follow these simple steps to build a Grove circuit with LinkIt ONE using the light sensor:

  1. This Demo is for LinkIt ONE, So we need a LinkIt ONE, and also use the Grove - Base Shield and connect the Grove - Light Sensor module to the shield using a designated Grove Interface. Also attach an output module such as a Grove - Green LED which will get triggered based on input received from the light sensor (shown below).
  2. Upload the following sample sketch to make the LED turn ON and OFF based on input from 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);
}

With Mbed

With TI LaunchPad

Sensing the Light (Light Sensor)

This example reads the amount of light incident on the Grove-light-sensor and displays the reading on the Grove 4-digital display. This is similar to the previous example except we are now using the ambient light sensor instead of the potentiometer rotary angle knob.

/*
  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 */
    }
}



With BeagleBone

With Intel Galileo

With Raspberry Pi

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"

Run the program

   cd GrovePi/Software/Python/
   sudo python grove_light_sensor.py

Availability

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.


Resources


Related Projects

If you want to make some awesome projects by LinkIt ONE, here's some projects for reference.

LinkIt ONE IoT Demo

This is an IoT demo make by LinkIt ONE and Grove.

With this demo, we can:


Halloween Pumpkin

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.


Light Pouring Cup

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.


Night Clothing Collection Balcony

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.


Fan control by light sensor

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.


Help us to make it better

Copyright (c) 2008-2016 Seeed Development Limited (www.seeedstudio.com / www.seeed.cc)
This static html page was created from http://www.seeedstudio.com/wiki