Ingo Lohs
Published © LGPL

Light sensing with the Flying-Fish series from MH

... or in other words: LDR Photoresistor on a breakout board

BeginnerProtip30 minutes39,927
Light sensing with the Flying-Fish series from MH

Things used in this project

Hardware components

LDR Photoresistor - Flying Fish-series from MH
×1
Arduino Nano R3
Arduino Nano R3
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
3 pieces
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Light Sensor Flying-Fish series from MH

C/C++
// A0:

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1024.0);

  // the lower the voltage, the brighter it is
  if ((voltage >= 0) && (voltage <= 0.4)) {
    Serial.print ("it is light - ");
  } else if ((voltage > 0.4) && (voltage <= 2)) {
    Serial.print ("it is bright - ");
  } else {
    Serial.print ("it is dark - ");
  }
  // print out the value you read:
  Serial.println(voltage);

// D0:

// when sensor pin D0 is connected, the sensor only knows the state light (0.14V) and dark (5.0V).
// The brightness at which the particular state is to be set can be set using the rotary potentiometer.

}

Credits

Ingo Lohs

Ingo Lohs

182 projects • 194 followers
I am well over 50 years and come from the middle of Germany.

Comments