Help with calibrating LDRs

I have this simple project where I am using two LDRs to detect whether two respective light sources are switched on. They are connected to digital pins as I am only interested in whether the signal is On or Off.

The project above works fine.

The issue I'm having is figuring out how to calibrate the circuit so that the LDRs become less sensitive to light in case of ambient light. I would like the option of raising the threshold of light required to trigger the ~3V required for an On signal on the digital pins. I can of course change the resistance of the resistors. But I would instead like to find a way to adjust both LDRs simultaneously using some universal control like a single potentiometer.

Is there a way to achieve this? My experiments with potentiometers have led to the LDRs being MORE sensitive to light and also leading the LDRs to no longer act independently; causing light to trigger an ON signal for both digital pins despite light only shining on one LDR.

Start with reading the pinned post re how to get the most of the forum.

1 Like

Please post the code, using code tags. Since according to the drawing, the LDRs are connected to pins capable of analog input, you could use analogRead() and have any threshold you like between 0 and 1023 (on an Uno R3).

Hello televators1988

Welcome to the best Aruino forum ever :smile:

Take a view to this small example to adjust the LDR readings.

//https://forum.arduino.cc/t/help-with-calibrating-ldrs/1338385
#define ProjectName "Help with calibrating LDRs"
#define NotesOnRelease "Arduino MEGA tested"
//-----------------------------------------
// make names
enum AnalogIn {LDR1, LDR2, Adjust};
//-----------------------------------------
// make variables
constexpr uint8_t AnalogPins[] {A0, A1, A2};
//-----------------------------------------
// make support
void heartBeat(const uint8_t LedPin, uint32_t currentMillis)
{
  static bool setUp = false;
  if (setUp == false) pinMode (LedPin, OUTPUT), setUp = true;
  digitalWrite(LedPin, (currentMillis / 500) % 2);
}
// make application
void setup()
{
  Serial.begin(115200);
  for (uint8_t n = 0; n < 32; n++) Serial.println("");
  Serial.print("Source: "), Serial.println(__FILE__);
  Serial.print(ProjectName), Serial.print(" - "), Serial.println(NotesOnRelease);

  delay(2000);
  Serial.println(" =-> and off we go\n");
}
void loop()
{
  uint16_t analogAdjust = analogRead(AnalogPins[Adjust]);
  uint16_t analogLDR1 = analogRead(AnalogPins[LDR1]);
  uint16_t analogLDR2 = analogRead(AnalogPins[LDR2]);

  Serial.print ("LDR 1 = "), Serial.println ((analogLDR1 + analogAdjust) / 2);
  Serial.print ("LDR 2 = "), Serial.println ((analogLDR2 + analogAdjust) / 2);

  delay(1000); // for testing only
}
//------
1 Like

Sorry I had the LDRs connected to the wrong pins. They were meant to be connected to the digital inputs. Have corrected the post.

and here's the code

void setup() {
  Serial.begin(9600);

  pinMode(3, INPUT);
  pinMode(4, INPUT);
}

void loop() {
  int ldr1 = digitalRead(3);
  int ldr2 = digitalRead(4);

  Serial.print("LDR1: ");
  Serial.print(ldr1 == HIGH ? "ON" : "OFF");
  Serial.print(" | LDR2: ");
  Serial.println(ldr2 == HIGH ? "ON" : "OFF");

  delay(500);
}

LDR's are resistors. Take them off your breadboard and measure the resistance under various levels of light. Once you know what the resistance is at given light levels, you can select the right resistors for your voltage dividers.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.