hashan_sudeera
Published

Automatic Gate Opener using Arduino

This is my project 4 using Arduino.

BeginnerWork in progress4,998
Automatic Gate Opener using Arduino

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
LED, Blue Green
LED, Blue Green
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit diagram

Code

project_4.ino

C/C++
//Arduino project 4.Automatic open gate.

#define trig 2
#define echo 4
#define led 8

//Servo
#include <Servo.h>

Servo gate;


void setup() {
  Serial.begin(9600);
  
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(led,OUTPUT);
  
  gate.attach(9);
  

}

void loop() {

//ultra sonic sensor

  digitalWrite(trig,LOW);
  delayMicroseconds(2);
  digitalWrite(trig,HIGH);
  delayMicroseconds(10);
  digitalWrite(trig,LOW);

  long t =pulseIn(echo,HIGH);

  long cm = t /29 / 2;

  Serial.print(cm);
  Serial.println("cm");

//led
  if (cm <=19){
    digitalWrite(led, HIGH);
   
  }
  else{
    digitalWrite(led,LOW);
  }

 //Gate

  gate.write(170);

  if (cm<= 19){

    for( int j=170;j>=90;j--){
      gate.write(j);
      delay(50);
    }

    delay(2500);
    
    for( int i=90;i<=170;i++){
    gate.write(i);
    delay(50);
  }
   
  }
  else{
    gate.write(170);
  }

}

Credits

hashan_sudeera

hashan_sudeera

5 projects • 3 followers

Comments