Arduino and coding doubt on LED and resistor

When I place my palm over the photoresistor, the light entering the diode decreases and the LED must turn ON, the LED on Arduino responds as expected, but the LED connected on the breadboard does not.

int sensorPin = A0; int ledPin = 13; int sensorValue = 0;

void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}

void loop() {
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
if( sensorValue <= 50 )
{
digitalWrite(ledPin, HIGH);
delay(1000);
}
if( sensorValue >= 70 )
{
digitalWrite(ledPin, LOW);
delay(1000);
}
}

The analog voltage appears on anode of LED and cathode of LED is wired to ground through 220ohm resistor, also the cathode is connected to pin 13 on the Arduino.

That circuit is not expected to work. You won't get enough current through / voltage across the LDR to light the LED. What do you expect pin 13 to do? What ever it is I think you are mistaken.

Why is this in the Programming section of the forum? It seems pure hardware to me.

Pin 13 LED must light up when there is sufficient darkness in the room ( i.e when I place my palm over it ). The LED on Arduino responds as expected but the LED on bread board doesn't work? How can I make it work?

Just connect the external LED and resistor to another pin, and then switch it on in the software at the same time as you switch on the pin 13 LED.

I connected the LED to pin 7, and corrected the code accordingly, but it didn't work?

Connect the photoresistor to the base of a transistor which controls current to the external LED.

Can you suggest anything else, I don't have a transistor with me

Why not use the processing power of the microcontroller to do what you want?

What exactly are you trying to do? If you want to use an arduino to control the LED, there should be no connection between the photoresistor circuit and the LED circuit, they should be connected to different pins on the arduino. If you are trying to turn the LED ON and OFF solely using the photoresistor, there is no need for the arduino or any code.

I want to turn the LED (the one connected to 13 on the breadboard) to turn ON when I place my palm over the photoresistor, we actually have an inbuilt LED on the Arduino, right, near pin 13, this one glows when I place my palm over the LDR but at the same time, I need the LED on breadboard also to glow, which is not happening.

Why is it that the inbuilt LED responds and the red LED on the breadboard doesn't?

How can you make it happen without a code?

Why do you suggest that the photoresistor circuit and LED circuit must be independent of each other?

That is not a programming question then, is it? Try the electronics board instead.

Then you didn't do it right. Please post the code you "corrected".

As the light comes on in response to a reading you have to duplicate that with hardware. You will need a comparator, and as you haven't even got a transistor, I doubt you will have a comparator.

Because we know about electronics and you don't.

Look at this youtube example of your project.

I meant to say what is the reason behind you saying the photo resistor circuit and LED circuit must be isolated, I don't know why, looking forward to hearing from you

sir, I isolated both the circuits, and it worked perfectly. I think the problem was that when the light intensity on LDR decreases, its resistance increases, so the current flow through the circuit decreases, eventually, the current reaching the LED on the breadboard was not enough to light the LED.
Now, the LED is not connected to the same pin as in my schematic.

Thank you for time

Not only the current but the voltage. As the LDR increases in resistance, the potential at A0 drops. If this drops below the turn on voltage of the LED, then it can never light the LED.

This turn on voltage is determined by the LED’s colour but it is at least 1.7V and could be up to 3V.

So the criteria to turn on the onboard LED is determined by software and this is not the same as the criteria needed to turn on the external LED which is determined by what voltage is available to turn on the external LED.

Seeing as the signal to turn on the onboard LED appears on pin 13, then you could just connect the external LED and resistor to that and you wouldn’t need any extra software, other than making sure pin 13 is set to be an output in the setup function.