How to sum current duration in next duration

I am new to Arduino please anyone help me, i am doing IN= entered in room & OUT: came out from room, Event counter, also i am counting time spent in room, in the day time so many times person entered in the room and came out i want to get total time spent in room,entered_cameout_object_lcd.ino (2.2 KB)

Please edit your post to add the code in line (using code tags), so more people can see it. See the "How to get the best out of the forum" post for instructions.

Also, explain what the code should do, but does instead.

thank you sir

how do you know which direction a person enter/exits the room? don't you need 2 detectors?

for a single detector, consider

#define MyHW
#ifdef MyHW
# include "LiquidCrystal.h"     // local copy
int doorPin = A1;

#else
# include <Debouncer.h>
#include <LiquidCrystal.h>
int doorPin = 2;
#endif

enum { Off = HIGH, On = LOW };

// -----------------------------------------------------------------------------
LiquidCrystal lcd(12, 11, 5, 4, 10, 7);
int Contrast=108;

int ledPin = 13;
int rise_count = 0;
int fall_count = 0;
int buttonState = 0;
int doorLst = 0;

unsigned long startTime;
unsigned long endTime;

unsigned long duration;
unsigned long total;

char s [80];

// -----------------------------------------------------------------------------
void setup() {
    Serial.begin(115200);

    analogWrite(6,Contrast);
    lcd.begin(16, 2);

    pinMode(ledPin, OUTPUT);
    pinMode(doorPin, INPUT_PULLUP);
    doorLst = digitalRead (doorPin);

    Serial.println("start");
}

// -----------------------------------------------------------------------------
void loop() {
    byte door = digitalRead (doorPin);

    if (doorLst != door)  {
        doorLst = door;

        if (On == door)  {
            digitalWrite(ledPin, On);
            fall_count++;

            startTime = millis ();
        }
        else {
            digitalWrite(ledPin, Off);
            rise_count++;

            endTime  = millis();
            duration = endTime - startTime;
            total   += duration;
        }

        delay (10);
    }

    sprintf (s, " IN : %4d, OUT: %4d, duration %4ld, total %4ld",
        fall_count, rise_count, (duration+500)/1000, total/1000);
    lcd.print (s);
}

I am new to Arduino please anyone help me, i am doing IN= entered in room & OUT: came out from room, Event counter, also i am counting time spent in room, in the day time so many times person entered in the room and came out i want to get total time spent in room

Dear Sir,
I am using one button when i press it IN: 1 Event, Then when I release OUT: 1 and IN of right side shows time spent between since person Entered in to the room to came out from room, when person Entered 2 nd time IN : 2 & wen person came out 2 time OUT Shows: 2 & another IN shows: ! time spent + next (second time spent means total time spent



here i want TN = (1st time spent: 1.83+ 2nd time spent: 1.57+ 3rd time spent: 0.83)

?? ?

Dear sir,
in my project previously every thing is , i am confusing to calculate last duration + current duration + n No. of time he spent time in the room. (I want to count total spent spent in the room from start).

Sir,
Now count shows IN:1, OUT:1 and directly jump to IN:3, OUT:3, and IN: 5, OUT:5, i required
1st in 1st out, 2nd in 2nd out , 3rd in 3rd out,

i required both 1 st in 1st out, 2nd in 2nd out & 3rd in 3rd out

Thank you sir,

Without your guidance i can't had completed this project, i am going to donate this project to covid-19 vaccination center, i will mention there that i have completed this project with the help of your name and arduino forum.

1


Dear Sir,
can you suggest piece of code to save counter++ & duration in EEPROM, if it will be in internal memory then good but ok with external, i.e.: counter:1=01.83 Sec. 2,=1.57, 3= 0.82,
Counter No & it's duration, & Recall on LCD using buttons