Francisc Camillo
Published © GPL3+

Automatic Door and Counter Prototype

The project acts as an automatic door opener for an establishment then counts up or down the customers that went in and went out.

BeginnerFull instructions provided4 hours20,002
Automatic Door and Counter Prototype

Things used in this project

Hardware components

Arduino Mega 2560
Arduino Mega 2560
×1
Servos (Tower Pro MG996R)
×2
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
Ultrasonic Sensor
×2

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Custom parts and enclosures

Automatic Door and Counter

Schematics

Automatic Door and Counter

Whenever something is detected by the ultrasonic the door will open, the left door counts up while the right door counts down

Code

Automatic Door and Counter

C/C++
//Adds libraries needed for the project
#include <Servo.h>
#include <NewPing.h>
#include <LiquidCrystal.h>

//defines constants for the pin layout
#define trigPin1 19
#define echoPin1 20
#define trigPin2 23
#define echoPin2 24
#define maxd 50
#define doorSensor 2

//lcd as variable for LiquidCrystal function
LiquidCrystal lcd(36,38,40,42,44,46);

//variables for telling time in Ultrasonic Sensing
long duration, distance;
int pinged;

//created variables to hold servo function
Servo myservo;
Servo myOtherServo;

//variable for counting persons
int incoming = 0;
int outgoing = 0;
int inside = 0;

//Newping sonar array containg 2 various ultrasonic sensor pin config
NewPing sonar[doorSensor] = {
  NewPing (trigPin1, echoPin1, maxd), // NewPing setup of pins and maximum distance.
  NewPing (trigPin2, echoPin2, maxd) // NewPing setup of pins and maximum distance .
};

void setup(){
  //Start Serial
  Serial.begin(9600);

  //Initiate LCD
  lcd.begin(16,2);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Hello");

  //attach pins to servos
  myservo.attach(9);
  myservo.write(0);
  myOtherServo.attach(10);
  myOtherServo.write(80);
//  attachInterrupt(digitalPinToInterrupt(20),openEnter,RISING);
//  attachInterrupt(digitalPinToInterrupt(21),openExit,RISING);
}
void loop(){

  printToLCD();
  getPing();
//  derf = incoming;
}

void getPing(){
  delay(50);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  unsigned int uS = sonar[0].ping(); // Send ping, get ping time in microseconds (uS).
//  Serial.print("Ping1: ");
  pinged = uS / US_ROUNDTRIP_CM;
//  Serial.print(pinged); // Convert ping time to distance in cm and print result (0 = outside set distance range)
//  Serial.println("cm");

  if(pinged < 8){
    openEnter();
    outgoing++;
  }
  if(pinged>8){
    closeEnter();
  }

  delay(50);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  uS = sonar[1].ping(); // Send ping, get ping time in microseconds (uS).
//  Serial.print("Ping2: ");
  pinged = uS / US_ROUNDTRIP_CM;
//  Serial.print(pinged); // Convert ping time to distance in cm and print result (0 = outside set distance range)
//  Serial.println("cm");
  if(pinged < 10){
    openExit();
    incoming++;
  }
  if(pinged>10){
    closeExit();
  }

}

void openEnter(){
  myOtherServo.write(0);
  delay(10);
  myOtherServo.write(80);
  delay(100);}
void closeEnter(){
  myOtherServo.write(80);
  delay(10);
  myOtherServo.write(0);
  delay(100);}
void openExit(){
  myservo.write(80);
  delay(10);
  myservo.write(0);
  delay(100);
  }
void closeExit(){
  myservo.write(0);
  delay(10);
  myservo.write(80);
  delay(100);}

void printToLCD(){
  if (inside == 0){
//    delay(100);
    closeEnter();
    
    }  
  inside = incoming - outgoing;

   if(inside < 0){
    closeEnter();
    delay(500);
    outgoing = 0;
    incoming=0;
    myOtherServo.attach(54);
    inside = 0;}
  if(inside == 1){
    myOtherServo.attach(10);}
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Customer Inside: ");
  lcd.setCursor(0,1);
  lcd.print(inside);   
  Serial.println(inside);
}

Credits

Francisc Camillo

Francisc Camillo

10 projects • 17 followers
Computer Engineering Student with Passionate Advocacy in Creating world changing hardware and software applications

Comments