Pages: [1]   Go Down
Author Topic: 1 photoresistor 2 leds (sorry for my english)  (Read 1424 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I am making a school project until the 14th, but i am new with programming.
A photoresistor controlls the leds. If i place my hand over the photoresistor, led2 goes on.
If I cover it, but then remove my hand, led1 goes on.

PLEASE HELP ME!

task:
1.read the photoresistor
2.wait 0,5 seconds
3.read the photoresistor again

a)if the light that reaches the photoresistor is interrupted for a short time, set led1 high
b)if the light that reaches the photoresistor is interrupted for a long time, set led2 high

=>that means: a)if i move my hand once over it, set led 1 high
b)if i cover it, set led 2 high

I need a programm that looks like this:

Quote
int photoIn = 1;
int led1 = 11;
int led2 = 12;
int setPoint = 350;

void setup()
{
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
}
void loop() {
  Value = analogRead(photoIn);
  
  if (Value < setPoint;
       delay(500);
      Value > setPoint;)
  {
    digitalWrite(led1, HIGH);
     delay(1000)
    digitalWrite(led1, LOW);
  }

  if (Value < setPoint;
       delay(500);
      Value < setPoint;)
  {
    digitalWrite(led2, HIGH);
     delay(1000)
    digitalWrite(led2, LOW);
  }


« Last Edit: March 05, 2011, 11:11:30 am by kevindorner » Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 176
Posts: 12285
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Two things...

1. Please do not multi-post.

2. Do you have a question about robotics?
Logged

The netherlands, Zeeland
Offline Offline
Newbie
*
Karma: 0
Posts: 30
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Nice to see that they are doing Arduino projects on your school smiley-razz
The code would be something like this:
Quote
int photoIn = 1;
int led1 = 11;
int led2 = 12;
int value = 0;
byte last_value = false;
/*
Change this value to the point where it works, 
 it depends on how light the area is.
 */
int setPoint = 350;

void setup()
{
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
}
void loop() {
  value = analogRead(photoIn);

  if (value < setPoint){
    if (last_value==true){
      digitalWrite(led1,HIGH);
      digitalWrite(led2,LOW);
    }  
    last_value = false;
  }
  else{
    if (last_value==true){
      digitalWrite(led1,LOW);
      digitalWrite(led2,HIGH);
    }
    last_value = true;
  }
  delay(500);
}
But if you hold your hand for 0.1 seconds this script won't work. This only works if you hold your hand for 0.5 seconds. Success with your project.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I need somethig like this:


Code:
int photoIn = 1;
int led1 = 11;
int led2 = 12;
int value = 0;
int setPoint = 350;

void setup()
{
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
}
void loop() {
  value = analogRead(photoIn);

  if (value < setPoint){
    delay(500);
    if (value < setPoint){
      digitalWrite(led1,HIGH);
      digitalWrite(led2,LOW);
      delay(1000);
      digitalWrite(led1,LOW);} 
   
    else{digitalWrite(led2,HIGH);
      digitalWrite(led1,LOW);
      delay(1000);
      digitalWrite(led2,LOW);}
 
     }
else{
      digitalWrite(led1,LOW);
      digitalWrite(led2,LOW);
       }
   
}
Logged

Pages: [1]   Go Up
Jump to: