Ldr sensor problem with my project

Hello I have a problem in my project while I using ldr sensor firstly I used the ldr to detect the sun light then from this reading it should make the motor run and if there is no sun the motor should stop , now while I use the ldr sensor it’s readings vary with no cause and varies randomly even when I cover the ldr sensor it give me reading then when I in cover it suddenly give me 0 and make the motor stop suddenly and I don’t know where is the problem here is my code and even I used different resistors for my installing such as 8,2 and 15 ,18, 220, 10k ohms and nothing changed
Here is my code

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
 
}

void loop() {
  // put your main code here, to run repeatedly:
  light=analogRead(A0);
  Serial.println(light);
  delay(500);
}*emphasised text*

Welcome to the forum

Please post a schematic showing how the LDR is connected to the Arduino

Probable failures:
Poor jumper contact;
faulty jumpers
Bad contact on the breadboard;
Problem with LDR (Change LDR).

I have checked all of these probably problems and the same problem exists

  • Show us good images of your ‘actual’ wiring.

  • Do you have access to a voltmeter ?


No for now I don’t have an access to voltmeter

image
Your breadboard has a break in the power rails along the edge

Doesn’t affect any thing it still in the same node

Where does other other end of the red jumper connected to the LDR go to ?

Where does the orange jumper connected to the resistor go to ?

The red one to the 5volt from the arduino
And the orange one to the grd from the arduino

image
I assume that the top red jumper comes from 5V on the Arduino. If so, then it is the other side of the break in the power rails so it is not connected to the red wire from the LDR

I now take a wire from the 5 volt direct to the ldr still this problem exit

Did you also fix the same problem with the GND wire from the Arduino to the LDR ?

Yes still the same problem

Please post a clear 'photo showing how all of your components are wired now

  • In the future, leave these jumper installed (i.e. unless you really cannot use them in an experiment).

2024-05-03_10-58-56

Here's an LDR test program with smoothing, I used a 33k resistor.

uint32_t
  tStart, // timer start
  tEnd = 2000; // update time in mS
int
  total,  // sum of samples
  current,
  avg; // average
 
const byte
  numSamples = 8, // number of samples for smoothing
  aInPin = A0;
           
void setup()
{
  Serial.begin(9600);
  for(int i = 0;i < numSamples;i++) // for smoothing, fill total with 
    total += analogRead(aInPin);    // numSamples * current reading
  avg = total / numSamples;                               
}

void loop()
{
    if(millis() - tStart > tEnd)
  {
    tStart = millis(); // reset timer 
    total -= avg; // make room for new reading
    current = analogRead(aInPin);
    Serial.print(current); Serial.print("\t");
    total += current; // add new reading
    avg = total / numSamples; ;
    Serial.println(avg);
  }  
}

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