# People counter keeps counting add LEDs

**URL:** <https://forum.arduino.cc/t/people-counter-keeps-counting-add-leds/862071>\
**Category:** Programming\
**Created:** [May 15, 2021, 12:10pm UTC](https://forum.arduino.cc/t/people-counter-keeps-counting-add-leds/862071 "2021-05-15T12:10:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gokhan811](https://avatars.discourse-cdn.com/v4/letter/g/58f4c7/32.png) [@gokhan811](https://forum.arduino.cc/u/gokhan811)\
**Post date:** [May 15, 2021, 12:10pm UTC](https://forum.arduino.cc/t/people-counter-keeps-counting-add-leds/862071/1 "2021-05-15T12:10:26Z")

</div>

Hi,  
I am working with a visitor counter and how can I add LEDs to my project? For example, I want a green LED to light up when you enter, how can I do it?

```cpp
int trig = 10;
int fan =8;
int echo = 9;
int led = 7;
int buzzer= 6;
int i=0;
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() 
{
   lcd.begin(16, 2);
  Serial.begin(9600);
  pinMode(trig,OUTPUT);
  pinMode(echo,INPUT);
  pinMode(led,7);
  pinMode(fan,8);
  pinMode(buzzer,OUTPUT);
  lcd.setCursor(4,0);
  lcd.print("Welcome");
  delay(2000);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Please wait.");
  delay(200);
  lcd.setCursor(0,0);
  lcd.print("Please wait..");
  delay(200);
  lcd.setCursor(0,0);
  lcd.print("Please wait...");
  delay(200);
  lcd.setCursor(0,0);
  lcd.print("Please wait....");
  delay(200);
  lcd.setCursor(0,0);
  lcd.print("Please wait.....");
  delay(200);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Please wait.");
  delay(200);
  lcd.setCursor(0,0);
  lcd.print("Please wait..");
  delay(200);
  lcd.setCursor(0,0);
  lcd.print("Please wait...");
  delay(200);
  lcd.setCursor(0,0);
  lcd.print("Please wait....");
  delay(200);
  lcd.setCursor(0,0);
  lcd.print("Please wait.....");
  delay(200);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Please wait.");
  delay(200);
  lcd.setCursor(0,0);
  lcd.print("Please wait..");
  delay(200);
  lcd.setCursor(0,0);
  lcd.print("Please wait...");
  delay(200);
  lcd.setCursor(0,0);
  lcd.print("Please wait....");
  delay(200);
  lcd.setCursor(0,0);
  lcd.print("Please wait.....");
  delay(200);
  lcd.setCursor(0,0);
  lcd.print("Please wait.....");
  delay(200);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Visitor Counter");
    lcd.setCursor(1,1);
  lcd.print("By Thunder");
  delay(2500);
  lcd.clear();
}

void loop() {
  lcd.setCursor(0,0);
  lcd.print("People visited:"); 
  digitalWrite(trig,LOW);
  delayMicroseconds(5);
 
  digitalWrite(trig,HIGH);
  delayMicroseconds(10);
 
  
  digitalWrite(trig,LOW);
 
  
  int a = pulseIn(echo,HIGH);
 
  
 int distance = a*0.034/2;
  
  

  if ( distance<40) //in
  {
  i=i+1;
    delay(500);
    digitalWrite(buzzer,HIGH);
    delay(100);
    digitalWrite(buzzer,LOW);
    delay(100);
   
     lcd.clear();
    lcd.setCursor(0,0);
  lcd.print("People visited:"); 
    lcd.setCursor(0,1);
  lcd.print(i);
    delay(400);
  
  }
   if ( distance>60) //out
  {
  i=i-1;
    delay(500);
    digitalWrite(buzzer,HIGH);
    delay(100);
    digitalWrite(buzzer,LOW);
    delay(100);
     lcd.clear();
     lcd.setCursor(0,0);
  lcd.print("People visited:"); 
    lcd.setCursor(0,1);
  lcd.print(i); 
     delay(400);
    
  }
 
}

```

My project is there ;  
 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/c/2/c/c2c394478b72429c765d2d42dd3adc04b7ec34ac.png)

> **[Login | Tinkercad](https://www.tinkercad.com/login?next=%2Fthings%2F8ZwbJmRvNcj)**

---

<div class="post-metadata">

**Author:** ![gcjr](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gcjr/32/314015_2.png) [@gcjr](https://forum.arduino.cc/u/gcjr)\
**Post date:** [May 15, 2021, 12:46pm UTC](https://forum.arduino.cc/t/people-counter-keeps-counting-add-leds/862071/2 "2021-05-15T12:46:54Z")

</div>

> [@gokhan811](#):
>
> ` if ( distance<40) //in`

the above will be true presumably as long as the person is in the room (within range), not just when entering the room.

keeping track of the previous distance would allow recognizing when there is a change in distance indicating a person entering the room, incrementing a count (i++) and turning on an LED.

similar logic can be added to track a person leaving

---

<div class="post-metadata">

**Author:** ![Ballscrewbob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ballscrewbob/32/950458_2.png) [@Ballscrewbob](https://forum.arduino.cc/u/Ballscrewbob)\
**Post date:** [May 15, 2021, 2:52pm UTC](https://forum.arduino.cc/t/people-counter-keeps-counting-add-leds/862071/3 "2021-05-15T14:52:26Z")

</div>

Other post/duplicate DELETED  
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you take a few moments to Learn and Use The Forum

[quote]Hello.

Welcome to the Arduino Forum. This guide explains how to get the best out of this forum. Please read and follow the instructions below. Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is frustrating for you and frustrating for us.

> [@How to get the best out of this forum](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966):
>
> See also [FAQ - Arduino Forum](https://forum.arduino.cc/faq) for general rules on forum behaviour and etiquette. Hello, Welcome to the Arduino Forum. This guide explains how to get the best out of this forum. Please read and follow the instructions below. Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is fru…

[/quote]

It will help you get the best out of the forum in the future.

- Your OS and version can be valuable information, please include it along with extra security you are using.

- Always list the version of the IDE you are using and the board version if applicable.

- Use quote or add error messages as an attachment NOT a picture.

- How to [insert an image](https://forum.arduino.cc/t/a-thread-with-tips-and-tricks-for-the-new-discourse-based-arduino-forum/849827/3) into your post. ( Thanks @sterretje )

- Add your sketch where applicable but please use CODE TAGS ( **\</\>** )

- Add a SCHEMATIC were needed even if it is hand drawn

- Add working links to any specific hardware as needed ( **NOT** links to similar items)

- Remember that the people trying to help cannot see your problem so give as much information as you can

**COMMON ISSUES**

- Ensure you have **FULLY** inserted the USB cables.

- Check you have a [COMMON GROUND](https://forum.arduino.cc/index.php?topic=653831.msg4406618#msg4406618) where required. ( Thanks @Perry)

- Where possible use USB 2.0 ports or a USB 2.0 POWERED HUB to rule out USB 3.0 issues.

- Try other computers where possible.

- Try other USB leads where possible.

- You may not have the correct driver installed. [CH340/341](http://www.wch.cn/download/CH341SER_EXE.html) or [CP2102](https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers) or FT232 [VCP Drivers - FTDI](https://ftdichip.com/drivers/vcp-drivers/)

- There may be a problem with the board check or remove your wiring first.

- Remove any items connected to pins 0 and 1.

**COMPUTER RELATED**

- Close any other serial programs before opening the IDE.

- Ensure you turn off any additional security / antivirus just to test.

- There may be a problem with the PC try RESTARTING it.

- You may be selecting the wrong COM port.

- Avoid cloud/network based installations where possible OR ensure your Network/Cloud software is RUNNING.

- Clear your browsers CACHE.

- Close the IDE before using any other serial programs.

- Preferably install IDE’s as ADMINISTRATOR or your OS equivalent

**ARDUINO SPECIFIC BOARDS**

- CH340/341 based clones do not report useful information to the “get board info” button.

- NANO (Old Types) some require you to use the OLD BOOTLOADER option.

- NANO ( **ALL Types** ) See the [specific sections](https://forum.arduino.cc/index.php?board=135.0) lower in the forum.

- NANO ( **NEW Types** ) [Install your board CORE’s.](https://forum.arduino.cc/index.php?topic=642505.0)

- Unless using EXTERNAL PROGRAMMERS please leave the IDE selection at default “AVRISP mkII”.

- Boards using a MICRO usb connector need a cable that is both DATA and CHARGE. Many are CHARGE ONLY.

**CREATE editor install locations.**

- On macOs ~/Applications/ArduinoCreateAgent-1.1/ArduinoCreateAgent.app/Contents/MacOS/config.ini

- On Linux ~/ArduinoCreateAgent-1.1/config.ini

- On Windows C:\Users[your user]\AppData\Roaming\ArduinoCreateAgent-1.1

_ **Performing the above actions may help resolve your problem without further help.** _

**Language problem ?**

**Try a language closer to your native language:**

- [中文 (Chinese)](https://forum.arduino.cc/index.php?board=99.0)

- [Deutsch - German](https://forum.arduino.cc/index.php?board=31.0)

- [Español - Spanish](https://forum.arduino.cc/index.php?board=32.0)

- [Français - French](https://forum.arduino.cc/index.php?board=33.0)

- [অসমীয়া, বাংলা, बड़ो - India](https://forum.arduino.cc/index.php?board=82.0)

- [Italiano - Italian](https://forum.arduino.cc/index.php?board=34.0)

- [Nederlands - Dutch](https://forum.arduino.cc/index.php?board=77.0)

- [Portugues - Portuguese](https://forum.arduino.cc/index.php?board=35.0)

- [Россия - Russia](https://forum.arduino.cc/index.php?board=120.0)

- [Scandinavia Swedish, Suomi - Finnish, Norsk - Norwegian](https://forum.arduino.cc/index.php?board=36.0)

**Thanks to all those who helped and added to this list.**

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [September 12, 2021, 2:52pm UTC](https://forum.arduino.cc/t/people-counter-keeps-counting-add-leds/862071/4 "2021-09-12T14:52:51Z")

</div>

Closed on September 12, 2021, 2:52pm UTC

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.
