problem with ldr sensor and relay

hello i have a problem with relay. when i put relay in pin 8 and put this code in arduino is ok

int LDR = 0;       
int relay = 8;   
int val = 0;       

void setup() {
  pinMode(LDR, INPUT);      
  pinMode(relay OUTPUT);  
}

void loop() {
  val = analogRead(LDR);      
  if(val>800)		
  {				
  digitalWrite(relay,HIGH);  
  }	
  if(val<800 )
  {
    digitalWrite(relay,,LOW);
  } 			
  delay(100);                  
}

but i would like when the ldr is off and after the ldr is on , start the relay and dont stop.
and i put this code

int LDR = 0;       
int relay = 8;   
int val = 0;       

void setup() {
  pinMode(LDR, INPUT);      
  pinMode(relay OUTPUT);  
}

void loop() {
  val = analogRead(LDR);      
  if(val>800)		
  {				
  digitalWrite(relay,HIGH);  
  }	
  delay(100);                  
}

and when the ldr is off the relay start and when the ldr is off the relay stop.

sorry for my english but i dont know very good this language. i am from greece.

i would create a car wash and i put ldr and laser. and when the car put in the tunel the ldr is off and start the relay of conveyor for delay 230 sec.

thank you very much.

i create this programm with led and it is ok but with relay is not good.

It's hard to believe that either code even compiles.

  pinMode(relay OUTPUT);

is missing a comma between the arguments.

    digitalWrite(relay,,LOW);

has too many commas.

i would create a car wash and i put ldr and laser. and when the car put in the tunel the ldr is off and start the relay of conveyor for delay 230 sec.

  if(val>800)		
  {				
  digitalWrite(relay,HIGH);  
  }	
  delay(100);

100 milliseconds is nowhere near 230 seconds.

Pins don't automatically change state. If you want to turn the pin off after the delay, you have to write code to do that.

i create this programm with led and it is ok but with relay is not good.

It may also be that your relay requires too much current to turn on. What relay are you using, and how is it wired?

if i put digitalWrite (relay,HIGH); the relay dont start but if i put digitalWrite (relay,LOW); the relay started but if i put
digitalWrite(relay,LOW);
delay (5000);
digitalWrite(relay,HIGH);

the relay started and dont stop after the 5 sec.

What relay are you using, and how is it wired?

i use this relay http://www.ebay.com/itm/8-Channel-5V-Relay-Module-Arduino-PIC-ARM-DSP-AVR-/120769866966?pt=LH_DefaultDomain_0&hash=item1c1e71ecd6

and i connect :
1st cable of motor in - battery
second cable of motor in Normaly open

  • battery cable in common of relay

i connect the pin gnd vcc and i1-i8 in arduino digital pins
but i dont connect the three pins of jd-vcc vcc and gnd the vcc and jd-vcc are connected between their (this pin are up and left in the Module)

do you know this problem?