Simple Arduino light meter




This Arduino project is a simple light meter using a photo-transistor. An LDR would be more appropriate but the photo-transistor is what I has spare at the time. On the other hand the photo-transistor is sensitive to infrared, so its handy for testing remote controls.

The project consists of 10 red LEDs driven by 10 BC547 transistors although any general purpose transistor will do. The base of each transistor is connected to the Arduino board digital pins D0 through to D7 via a 2.2K resistor. The LEDs are connected to a 12 volt source with current limiting resistors of 560 ohms.

Simple Arduino light meter




The input is provided by a photo-transistor connect to the Arduiono’s analogue input on analogue pin 0. The range of the input for the photo-transistor is 0 (full light) to 1023 (full dark), 1024 in total. This output is divided by 128, that is the full range (1024) divided by the number of LEDs (8). As the result is cast as a floating point, we round it up to the nearest integer. So 7.5 become 8. Finally we subtract this result from the total number of LEDs.

A simple for loop is used to enumerate the result and light/extinguish the appropriate number of LEDs. The source below:

int sensorPin = A0;
float sensorValue = 0;
int leds = 8;
int result = 0;
int divisor = 128;

void setup()
{
  PORTD = B00000000;
  pinMode(0,OUTPUT);
  pinMode(1,OUTPUT);
}

void loop() {
  sensorValue = analogRead(sensorPin);
  result = leds - round(sensorValue / divisor);
  for(int i = 0;i < leds;i++) {
    if(i < result) {
      digitalWrite(i,HIGH);
    } else {
      digitalWrite(i,LOW);
    }
  }
}

The results can be seen in this quick video showing how the LEDs react when a torch is brought near the photo-transistor:

 

For more detail: Simple Arduino light meter




Clip to Evernote

Leave a Comment

(Spamcheck Enabled)

Read previous post:
Arduino Automated Lighting Control
Arduino Based Automated Lighting Control

This is my second instructable. i want to share some of the basic things i made using the arduino i...

Close
Scroll to top