There are a number of different sensors for measuring light available on the market. it is mainly about the brightness of ambient light, sometimes also about invisible infrared light from cheap to expensive.
Today we take a look at the light sensor from the Flying Fish series from MH: Here, a conventional LDR photoresistor is applied to a breakout board and equipped with comfort functions such as resistors and control lights. In addition to the 4 leads, there is also a potentiometer.
So you have the choice between the state measurement: it is light or dark on the D0-lead and an analog measurement of the voltage on the A0-lead.
// 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);
You suspect it already: the code is known from the Arduino IDE example sketches and reads in the different voltage on the A0 PIN of the Arduino.
// 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);
You can view the log via the Arduino IDE's serial monitor:
The following applies to 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.
Update 05.03.2020
And: yes, the photocell can of course perceive the ambient light and, via the analog pin with the help of the blue potentiometer, you can choose which light (or darkness) the LED strip should be switched on at.
The photos show it as an example with an LED, which I briefly controlled with 6V:
If the ambient light is 'dark' via the potentiometer, the green control lamp comes on and the LED lights up.
If I switch on my office lamp, it will be recognized immediately and you can guess it: control lamp and LED go out.
Update 20.03.2020
For the sake of completeness: the LDR sensor can also be used with a 12V consumer.
Comments