Hi,
I'm working on IR sensors stair projeck and now I trapped with programing.
what I want to build looks like this: SEQUA® Automatische LED-Treppenbeleuchtung (Sensorgesteuert) - Automatic LED stair-light controller - YouTube
but I want better with all posible ways.
I use 4 IR sensor like this: http://www.ebay.com/itm/Smart-Car-E18-D50NK-Infrared-Obstacle-Avoidance-Sensor-Proximity-Switch-3-50cm-/121320028394?pt=LH_DefaultDomain_0&hash=item1c3f3cb8ea
why 4 sensors? Because with 2 sensors I cant use all posible ways.
my vision about all posible ways:
1, 2, 3, 4 are sensors
red line is IR radius
brown line is how man cross IR radius
1 man cross nr1 radius
2 man cross both nr1 and nr2 radius
3 man cross only nr2 radius
4 man cross nr3 radius
5 man cross both nr3 and nr2 radius
6 man cross only nr2 radius
http://postimg.org/image/ay29uq3m5/
the same way is if man start using stairs from other side
http://postimg.org/image/7ys5g06ov/
I need 4 IR sensors to count people
http://postimg.org/image/7h1ldw6hr/
One man change his mind and turn back
http://postimg.org/image/kkb8c1wg1/
Both change minds and turn back
http://postimg.org/image/oocfe9lhf/
the same goes if they start using stairs whith other side
Next thing why I need to know how many people using staris and began to climb side is turn on LED's
If first man start using stairs from left:
Led1...Led2...Led3...Led4...ON
if first man start using staris from right:
Led4...Led3...Led2...Led1...ON
If last man finish using stairs to right:
Led1...Led2...Led3....Led4...OFF
If last man finish using staris to left:
Led4...Led3...Led2...Led1...OFF
here is my code:
//#include "Tlc5940.h"
const int s1=5; //Sensor NR1
const int s2=4; //Sensor NR2
const int s3=3; //Sensor NR3
const int s4=2; //Sensor NR4
int s1State=0; //Sensor NR1 no active
int s2State=0; //Sensor NR2 no active
int s3State=0; //Sensor NR3 no active
int s4State=0; //Sensor NR4 no active
int led1 = 50;
int led2 = 51;
int led3 = 52;
int led4 = 53;
int a=0; //Sensor NR1 was activated
int b=0; //Sensor NR2 was activated
int c=0; //Sensor NR3 was activated
int d=0; //Sensor NR4 was activated
int z=0; //People count
int ledON=0; //LED's are off
void setup() {
// Tlc.init();
pinMode(s1, INPUT);
pinMode(s2, INPUT);
pinMode(s3, INPUT);
pinMode(s4, INPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
}
void loop(){
s1State = digitalRead(s1);
s2State = digitalRead(s2);
s3State = digitalRead(s3);
s4State = digitalRead(s4);
//=====================================Vieno sensoriaus palietimas
//=====================================First sensor active
if(s1State==LOW && s2State==HIGH){
a=1;
}
if(s2State==LOW && s1State==HIGH){
b=1;
}
if(s3State==LOW && s4State==HIGH){
c=1;
}
if(s4State==LOW && s3State==HIGH){
d=1;
}
//=====================================Dveju sensoriu palietimas pradedant lipti
//=====================================Two sensor active then start using stairs
if(s1State==LOW && s2State==LOW && a==1){
z=z+1;
a=a+1;
}
if(s4State==LOW && s3State==LOW && d==1){
z=z+1;
d=d+1;
}
//=====================================Dveju sensoriu palietimas baigiant lipti
//=====================================Two sensors active then finish using stairs
if(s2State==LOW && s1State==LOW && b==1){
z=z-1;
b=b+1;
}
if(s3State==LOW && s4State==LOW && c==1){
z=z-1;
c=c+1;
}
//=====================================SAUGIKLIS
//=====================================Fuse
if(a==2 && b==1){
a=0;
}
if(b==2 && a==1){
b=0;
}
if(c==2 && d==1){
c=0;
}
if(d==2 && c==1){
d=0;
}
if(z<0){
z=0;
}
//=============================================================================================================
//=====================================Sviesa isijungia
//=====================================LED's ON
if(z==1 && ledON==0 && a==2){
digitalWrite(led1, HIGH);
delay(500);
digitalWrite(led2, HIGH);
delay(500);
digitalWrite(led3, HIGH);
delay(500);
digitalWrite(led4, HIGH);
delay(500);
ledON = 1;
}
if(z==1 && ledON==0 && d==2){
digitalWrite(led4, HIGH);
delay(500);
digitalWrite(led3, HIGH);
delay(500);
digitalWrite(led2, HIGH);
delay(500);
digitalWrite(led1, HIGH);
delay(500);
ledON = 1;
}
//=====================================Sviesa issijungia
//=====================================LED's OFF
if(z==0 && ledON==1 && c==2){
digitalWrite(led1, LOW);
delay(500);
digitalWrite(led2, LOW);
delay(500);
digitalWrite(led3, LOW);
delay(500);
digitalWrite(led4, LOW);
delay(500);
ledON=0;
}
if(z==0 && ledON==1 && b==2){
digitalWrite(led4, LOW);
delay(500);
digitalWrite(led3, LOW);
delay(500);
digitalWrite(led2, LOW);
delay(500);
digitalWrite(led1, LOW);
delay(500);
ledON=0;
}
}
I dont know there is problem in code.
Dont know why but sensors LOW means that someone corss IR radius and HIGH means that no one corss IR radius