Brick-LightSensor-Analog-Digital

From ArduinoInfo
Jump to navigation Jump to search

Light Sensor: Analog+Digital Electronic BrickLightSensorAnalogDigital-450.jpg(Available HERE:)


This light sensor uses a Cadmium Sulphide Photoresistor as a sensor. It then amplifies the signal and outputs:

  • Analog Data: The VALUE of the light (0 to 1023) with more light giving lower numbers
  • Digital Data: A LOW signal when the light is brighter than the set point.



NOTE: The pinout of this brick is NOT the same as our standard 3-pin cables. Above, you will see the connections are VCC (+5v), GND, DO (Digital Output) and AO (Analog Output). Use separate wires taken from a CableMaker strip). Or a Flat-to-Separate Cable.

This module has a dual personality. It looks at the light level falling on it's sensor and outputs that as a varying analog signal. Then it compares that value with the setting you make with the adjustable blue potentiometer. If the light level is higher than your set point, the digital output goes LOW.
It uses a LM393 Comparator chip for clean outputs.

Here is a sample Software Sketch you can cut and paste to test it. You can use it to set your setpoint:

/* YourDuino Electronic Brick Test: 
 Light Sensor Analog + Digital AB-890202
 terry@yourduino.com */

/*-----( Declare Constants )-----*/
#define ANALOG_SENSOR_PIN  A0
#define DIGITAL_SENSOR_PIN 3
#define LEDPIN    13  // The onboard LED

/*-----( Declare Variables )-----*/
int  switch_state;  /* Holds the last digital value */
int  LightAnalogValue; /* Holds the last analog value */

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  pinMode(LEDPIN, OUTPUT);
  Serial.begin(9600);          // Enable the Serial data output
  Serial.println("YourDuino Light Sensor Test 1.10 ");

}/*--(end setup )---*/


void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/

// This module is ACTIVE LOW when a reflection is seen
{

  switch_state = digitalRead(DIGITAL_SENSOR_PIN);
  if (switch_state == LOW)
  {
    digitalWrite(LEDPIN, HIGH);
    Serial.println("Digital Signal ON ");
  }
  else
  {
    digitalWrite(LEDPIN, LOW);
  }

  LightAnalogValue = analogRead(ANALOG_SENSOR_PIN);  //Read the voltage from sensor
  Serial.print("Analog Value (0 to 1023)");
  Serial.println(LightAnalogValue,DEC);      // Send result to Serial Monitor
  delay(500);

}/* --(end main loop )-- */

/* ( THE END ) */