Hi, I've been working on a count to track cars entering a carpark, and I'm having some monir trouble.
What I need, is for ir beam 1 to be triggered, then IR beam 2 to be triggered, whilst the first is still active, before I get a counter+1 event.
and the opposite for exiting the carpark, IR 2, then IR 1 whilst the first is active, before I get a counter-1 event.
i have 3 LEDs to light one to replicate IR 1, one to replicate IR2 and one to indicate that the counter has changed.
I thought I had it figured out, as the sketch compiled, but I'm not getting any results or not what I am expecting,anyway.
Sorry if its a bit messy, I have been chopping and changing it to try and get it to work. it was a lot neater than this to begin with
Eventually I will be relaying the output to a web page, but first I need to get the data acquisition right.
Any help is very much appreciated.
cheers
Jason
const int IRTrigger1 = 1; // the number of the pin used to read IR beam status
const int IRTrigger2 = 2;
const int CounterChange = 13; // the number of the LED pin
// variables will change:
int IRState1 = 0; // variable for reading the pushbutton status
int IRState2 = 0;
int totalcars =0;
int value = 0;
int entering = 0;
int leaving = 0;
void setup() {
const int IRTrigger1 = 1; // the number of the pin used to rear IR beam status
const int IRTrigger2 = 2;
const int CounterChange = 13; // the number of the LED pin
// variables will change:
int IRState1 = 0; // variable for reading the pushbutton status
int IRState2 = 0;
int totalcars =0;
int value = 0;
int entering = 0;
int leaving = 0;
// initialize the LED pin as an output:
pinMode(CounterChange, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(IRTrigger1, INPUT);
pinMode(IRTrigger2, INPUT);
Serial.begin(9600);
}
void loop(){
// read the state of the pushbutton value:
IRState1 = digitalRead(IRTrigger1);
IRState2 = digitalRead(IRTrigger2);
if (IRTrigger1 < 1){
IRState1=1; digitalWrite(CounterChange, HIGH);
}
if (IRTrigger2 < 1){
IRState2=1;
}
if(IRState1 > IRState2){
entering = 1;
} else if (IRState2 > IRState1){
leaving=1;
}
if ((IRState1 + IRState2) ==2){
if (entering == 1){
totalcars = totalcars + 1;
digitalWrite(CounterChange, HIGH);
delay(200);
digitalWrite(CounterChange, LOW);
} else if (leaving == 1){
totalcars = totalcars - 1;
}
entering=0; // reset everything
leaving=0;
IRState1=0;
IRState2=0;
}
}