User Tools

Site Tools


project:laser_light_sensor

Laser/light sensor

Aim of the project is to build lightweight laser/light sensor that can be mounted on quadcopter and used for gaming purposes. Sensor reads environmental light level via LDR, and sets the threshold below it. Any significant change in the light level will trigger the LED-s. Sensor will be used for the Dronosphere workshop and performance.

List of components

  • 1 Arduino Uno (or Duemilanove with an ATmega328)
  • 1 ATtiny45 or ATtiny85
  • 3 LDRs
  • 1 1KΩ resistor
  • 1 ultra bright LED
  • 220 to 330 ohm resistor for LED
  • 1 CR20 battery holder
  • 1 3V CR2032 battery
  • protoboard
  • jumper wires
  • stripboard

Arduino

It's recommended to test the circuit on Arduino first. You will have serial monitor available and will be able to see LDR values and further fine-tune the code or components.

Arduino schematic

Arduino code

laser_light_sensor_Arduino.ino
const int LDR = A0;         // analog pin to which LDR is connected
const int LED = 13;         // pin to which LED is connected
const int sensitivity = 50; // setting the light sensitivity
 
int LDRValue = 0;           // variable to store LDR values
int threshold;              // light sensitivity threshold
float voltage;              // variable to store voltage
 
void setup()
{
  Serial.begin(9600);                         // start the serial monitor with 9600 baud
  pinMode(LED, OUTPUT);                       // configure LED pin to behave as output
  threshold = analogRead(LDR) - sensitivity;  // set light sensitivity threshold
}
 
void loop()
{
  LDRValue = analogRead(LDR);                 // read LDR value
  Serial.print("Raw Rate: ");                 // print text
  Serial.println(LDRValue);                   // print value to serial monitor
  float voltage = LDRValue * (5.0 / 1023.0);  // convert analog reading (which goes from 0-1023) to a voltage (0-5V)
  Serial.print("Voltage: ");
  Serial.println(voltage);
  Serial.println();
 
  if (LDRValue <= threshold)                  // if the LDR reading is lower than the threshold
  {
    for (int i = 0; i <= 50; i++) {           // blink LEDs
      digitalWrite(LED, HIGH);
      delay(50);
      digitalWrite(LED, LOW);
      delay(50);
    }
    delay(1000);
    threshold = analogRead(LDR) - sensitivity; // set light sensitivity threshold
    delay(1000);
  }
  else
  {
    digitalWrite(LED, LOW);
  }
}

ATtiny (shrinking the sensor)

Now that we have tested everything, we can port it to ATtiny microcontroller (tested with ATtiny45, ATtiny85), which has significantly smaller profile, its cheaper and works on 3V.

Programming an ATtiny with Arduino

Follow this instructions:

Connect LDR, LED and power

ATTiny code

laser_light_sensor_ATtiny.ino
#define LDR A1              // analog pin to which LDR is connected
#define LED 1               // pin to which LED is connected
const int sensitivity = 40; // setting the light sensitivity
 
int LDRValue = 0;           // variable to store LDR values
int threshold;              // light sensitivity threshold
 
void setup()
{
  pinMode(LED, OUTPUT);                       // configure LED pin to behave as output
  threshold = analogRead(LDR) - sensitivity;  // set light sensitivity threshold
}
 
void loop()
{
  LDRValue = analogRead(LDR);                 // read LDR value
 
  if (LDRValue <= threshold)                  // if the LDR reading is lower than the threshold
  {
    for (int i = 0; i <= 50; i++) {           // blink LEDs
      digitalWrite(LED, HIGH);
      delay(50);
      digitalWrite(LED, LOW);
      delay(50);
    }
    delay(1000);
    threshold = analogRead(LDR) - sensitivity; // set light sensitivity threshold
    delay(1000);
  }
  else
  {
    digitalWrite(LED, LOW);
  }
}

Putting everything together

Stripboard

Cut the these lines on the stripboard (this is underside view).

… and soldier all other components

Light diffuser

Cover the LDRs with semi-transparent material to act as light diffuser. Doing this will make sensor sensitive over bigger area. Also leave enough space between LDRs and diffuser for light to spread. You can use ping pong ball, or ball from vending machine.

Tips

  • Sensor works best in low-light conditions
  • Recalibrate the sensor on every ambient light change
  • Recalibrate by triggering it or by removing battery
project/laser_light_sensor.txt · Last modified: 2015/07/14 13:17 by dp