user53738: LED is not turning on with the following code. Have tried multiple LED's and double checked wiring. What's wrong? Using an uno.
int ldr = A1;
int  ldrVal = ldr;
int led = 6;
int lvalue = 900;





void setup() {
  pinMode(led, OUTPUT);

  Serial.begin(9600);     

delay(1000);                               

}




void loop() {

Serial.println(analogRead(ldrVal));
if (ldrVal > lvalue) {

digitalWrite(led, HIGH);
}
delay (50);

if (ldrVal < lvalue)
{
  digitalWrite(led, LOW);
}
delay (1000);

}


user19867: Apart from the bad indentation and the bad variable naming, which makes your code not only look ugly, but messy and poorly readable, you have multiple problems in your few lines of code.
One problem is the variable lvalue never gets set, meaning its value remains 900 no matter what's the value you are reading through analogRead().
A second mistake is your ldrVal, which should represent the boundary between lit and powered off, is set to A1, which in turn is a macro define for a valid integer, but a very small value (less than 20).
In other words the code that should decide to turn on/off the LED continously compare 900 and 20 with no opportunity for those values to change: not surprising the LED won't change state, do you agree?
BTW, 50ms is a very short time interval: if you want to be able to see the LED turn on and then off, increase the delay to 200 or more.

user2967: Your code is wrong. analogRead(ldrVal) does not read the analog pin's value and store it into ldrVal, it is a function who's result is the analog pin value.
Try this edit:
void loop() {

int newValue = analogRead(ldrVal);
Serial.println(newValue);
if (newValue > lvalue) {  //Check newValue, not ldrVal
    digitalWrite(led, HIGH);
}
delay (50);

if (newValue < lvalue)
{
    digitalWrite(led, LOW);
}
delay (1000);
}


53738: <p>LED is not turning on with the following code. Have tried multiple LED's and double checked wiring. What's wrong? Using an uno.</p>

<pre><code>int ldr = A1;
int  ldrVal = ldr;
int led = 6;
int lvalue = 900;





void setup() {
  pinMode(led, OUTPUT);

  Serial.begin(9600);     

delay(1000);                               

}




void loop() {

Serial.println(analogRead(ldrVal));
if (ldrVal &gt; lvalue) {

digitalWrite(led, HIGH);
}
delay (50);

if (ldrVal &lt; lvalue)
{
  digitalWrite(led, LOW);
}
delay (1000);

}
</code></pre>
 19867: <p>Apart from the bad indentation and the bad variable naming, which makes your code not only look ugly, but messy and poorly readable, you have multiple problems in your few lines of code.</p>

<p>One problem is the variable <code>lvalue</code> never gets set, meaning its value remains <code>900</code> no matter what's the value you are reading through <code>analogRead()</code>.</p>

<p>A second mistake is your <code>ldrVal</code>, which should represent the boundary between <em>lit</em> and <em>powered off</em>, is set to <code>A1</code>, which in turn is a <em>macro define</em> for a valid integer, but a very small value (less than <code>20</code>).</p>

<p>In other words the code that should decide to turn on/off the LED continously compare 900 and 20 with no opportunity for those values to change: not surprising the LED won't change state, do you agree?</p>

<p>BTW, <code>50ms</code> is a very short time interval: if you want to be able to see the LED turn on and then off, increase the delay to 200 or more.</p>
 2967: <p>Your code is wrong. <code>analogRead(ldrVal)</code> does not read the analog pin's value and store it into ldrVal, it is a function who's result is the analog pin value.</p>

<p>Try this edit:</p>

<pre><code>void loop() {

int newValue = analogRead(ldrVal);
Serial.println(newValue);
if (newValue &gt; lvalue) {  //Check newValue, not ldrVal
    digitalWrite(led, HIGH);
}
delay (50);

if (newValue &lt; lvalue)
{
    digitalWrite(led, LOW);
}
delay (1000);
}
</code></pre>
