simple LED on and off. can't make it correct. [solved]

I have a question, I just got an arduino duemilanove.
here is the code,

int val;
void setup() {
pinMode(13, OUTPUT);
pinMode(A0, INPUT);
}

void loop() {
val = analogRead(A0);
if(val = HIGH) {
digitalWrite(13, HIGH);
delay(10);
} else {
digitalWrite(13, LOW);
delay(10);
}
}

:slight_smile:
after applied this code, my LED is always on. even if A0 touches ground, LED is still on.
my plan is to read A1 if it's high the led should on. if not, off.
:smiley:
Thanks in advance.

if(val = HIGH) {

You mean:

if(val == HIGH) {

Also, you might want to use digitalRead instead of analogRead as the latter gives you a number in the range of 0 to 1024. Or compare analogeRead to a fix value like (f.e.) 512 instead of HIGH.

The other suggestions are correct but the other thing you are missing is:-

if A0 touches ground, LED is still on.

There is no pull up resistor so your input is floating. This is bad, see:-
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

Thank you :smiley: for all the answer.