Dear Support people,
I have the following problems regarding my arduino uno project:
See the source code, attached in this post.
a ) I have created a simple people counter with the support of infrared leds.
I have 2 doors , and for each door i am using 2 receivers.
The main problem is that the counter is not beggining from 0 , but it begins from the integer value 1.
Is there any correction that i can make in the source code, to solve this sily problem ?
b ) In addition, how i can store the total value from Door A and Door B, to the internal memory of arduino, so that in case i disable and ReEnable the arduino, the previous total variable is Redisplayed in the Arduino's Display screen.
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int a1,a2,a3,a4;
int b1,b2,b3,b4;
int lb1,lb2,lb3,lb4;
int c1,c2,c3,c4;
int CounterA, CounterB;
int mem_a, mem_b;
void setup()
{
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("Entry Counter ");
lcd.setCursor(0,1);
lcd.print(" Panos Iliadis");
delay(3000);
lcd.clear();
a1 = 1000;
a2 = 1000;
a3 = 1000;
a4 = 1000;
b1 = b2 = b3 = b4 = 0;
lb1 = lb2 = lb3 = lb4 = 0;
c1 = c2 = c3 = c4 = 0;
lcd.setCursor(0,0);
lcd.print("A:");
lcd.print( CounterA,10 );
lcd.setCursor(0,1);
lcd.print("B:");
lcd.print( CounterB,10 );
lcd.setCursor(10,0);
lcd.print("Total ");
lcd.setCursor(10,1);
lcd.print( (CounterA+CounterB),10 );
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
//lcd.setCursor(0, 0);
// print the number of seconds since reset:
//lcd.print(millis()/1000);
// lcd.setCursor(6,0);
//lcd.print( ":" );
a1 = analogRead( 4 );
delay(10);
a2 = analogRead( 3 );
delay(10);
a3 = analogRead( 2 );
delay(10);
a4 = analogRead( 1 );
delay(10);
if (a1>500) b1 = 1;
else b1 = 0;
if (a2>500) b2 = 1;
else b2 = 0;
if (a3>500) b3 = 1;
else b3 = 0;
if (a4>500) b4 = 1;
else b4 = 0;
//lcd.setCursor(14,0);
//lcd.print( b1,10 );
//lcd.print( b2,10 );
//lcd.setCursor(14,1);
//lcd.print( b3,10 );
//lcd.print( b4,10 );
//Main Algorithym
if (!b1 && !lb1) c1 = 0;
if (!b2 && !lb2) c2 = 0;
if (!b3 && !lb3) c3 = 0;
if (!b4 && !lb4) c4 = 0;
if (b1 && lb1) c1++;
if (b2 && lb2) c2++;
if (b3 && lb3) c3++;
if (b4 && lb4) c4++;
//lcd.setCursor(0,0);
//lcd.print( c1,10 );
//lcd.setCursor(3,0);
//lcd.print( c2,10 );
//lcd.setCursor(0,1);
//lcd.print( c3,10 );
//lcd.setCursor(3,1);
//lcd.print( c4,10 );
if (b1 && lb1 && b2 && lb2 && (c1>2) & (c2>2)) {
if (mem_a==0) {
mem_a = 1;
CounterA++;
lcd.setCursor(2,0);
lcd.print( CounterA,10 );
lcd.setCursor(10,1);
lcd.print( (CounterA+CounterB),10 );
}
}
if (b3 && lb3 && b4 && lb4 && (c3>2) & (c4>2)) {
if (mem_b==0) {
mem_b = 1;
CounterB++;
lcd.setCursor(2,1);
lcd.print( CounterB,10 );
lcd.setCursor(10,1);
lcd.print( (CounterA+CounterB),10 );
}
}
if (!b1 & !lb1) mem_a = 0;
if (!b3 & !lb3) mem_b = 0;
/*
lcd.setCursor(6,0);
lcd.print( a1,10 );
//lcd.print( "," );
lcd.setCursor(12,0);
lcd.print( a2,10 );
//lcd.print( "," );
lcd.setCursor(6,1);
lcd.print( a3,10 );
lcd.setCursor(12,1);
//lcd.print( "," );
lcd.print( a4,10 );
*/
lb1 = b1;
lb2 = b2;
lb3 = b3;
lb4 = b4;
delay( 50 );
//a1++;
/*
if (a1==10) {
a1 = 0;
a2++;
if (a2==10) {
a2=0;
a3++;
if (a3==10) {
a3=0;
a4++;
}
}
}
*/
}