Sie sind auf Seite 1von 73

CALIFORNIA STATE UNIVERSITY, NORTHRIDGE

IMPLEMENTATION OF AUTOMATED

PARKING GATE CONTROLLER

USING RASPBERRY PI

A graduate project submitted in partial fulfillment of the requirements

For the Degree of Masters of Science in Electrical Engineering

By

Sai Anirudh Govindu

December 2017
The graduate project of Sai Anirudh Govindu is approved:

Dr. Somnath Chattopadhyay, ECE Date

Prof. Benjamin Mallard, ECE Date

Dr. Nagi El Naga. ECE, Chair Date

California State University, Northridge

ii
Acknowledgment

I thank my graduate project committee chair Dr. Nagi El Naga for providing his valuable
knowledge and guidance throughout the course of the project, his valuable experience
and support that was essential towards the completion of the project.

I also thank Dr. Somnath Chattopadhyay and Prof. Benjamin Mallard for their
suggestions on the project and accepting to be a part of my graduate project committee

Lastly, I express my gratitude towards my parents and sister for encouraging and
providing moral support throughout the course.

iii
Table of Contents
Signature Page…………………………………………….…………………... ii
Acknowledgement………………………………….…………………………. iii
List Of Figures……………………………..……….…………………………. vi
Abstract………………………………………………………………………... viii

Chapter 1…………………….....……………………………………………… 1
1.1 Introduction….….……………………………………………………... 1
1.2 Objectives of Project…………………….……………………………. 4
1.3 Outline Of Project…………………….……………………………….. 4
Chapter 2………………………………………………………………………. 6
2.1 Parking Gate Control System……………….………………………… 6
2.2 Components……………………………….…………………………... 5
2.3 Input Components……………………………………………………… 7
Chapter 3……………………………………...………………………………. 8
3.1 Raspberry Pi….………………………………………………….......... 8
3.1.1 Raspberry Pi 3...…………………………………………. 9
3.1.2 Hardware……………………...…………………………. 10
3.1.3 On Board Features………………………………………. 14
3.1.4 GPIO Pins Specifications.……………………………… 18
3.1.5 Programming……….…………………………………… 18
3.1.6 Raspberry Pi Specifications….…………………………. 21
3.2 Ultrasonic Sensor……….……………………………………………... 22
3.2.1 Working Principle and Structure…………………………. 23
3.2.2 Features of Ultrasonic Sound Waves…….……………… 25
3.2.3 Application………………………………………………... 26
3.2.4 HC-SR04 Ultrasonic Sensor Module……………………… 26
3.2.5 Distance Calculation………………………….…………. 27
3.2.6 Operation of HC-SR04……………………………………. 27
3.2.7 Specifications……………………………………………... 27
3.3 Infrared Sensor………………………………………………………… 28

iv
3.3.1 Working of the Infrared Sensor…….……………………… 29
3.3.2 Application……………….………………………………. 30
3.3.3 RB-DFR-49 Adjustable Infrared Sensor and Operation…... 30
3.3.4 Specifications……………………………………. 31
3.4 L293D Motor Driver…………………………………………………… 31
3.4.1 Pin Diagram………………….…………………………… 32
3.5 12 Volts DC Electric Motor……………………………………………. 33
3.6 Limit Switch…….……………………………………………………... 33
3.6.1 Applications……………………………...………………... 34
3.6.2 Micro Limit Switch………………………………………. 34
Chapter 4………………………………………….…………………………... 36
4.1 The Design……………………………………………………………. 36
4.2 Pin Map………………………………………………………………. 41
4.3 Schematic Design……………….…………….……………………… 44
4.4 Operation of the Design……………….………………………………. 45
4.5 Advantages……………………………………………………………. 50
Chapter 5: Software Design...…………………………………………………. 51
5.1 Flow Cart……………………………………………………………… 51
Chapter 6: Conclusion…………………………………………………………. 58
References……….……………………………………………………………. 59
Appendix A……………………………………………………………………. 60

v
List of figures

Figure 1 V-track sliding gate …………………………………………........ 2


Figure 2 Cantilever Slid gates ………………………………........................ 2
Figure 3 Swing gate ………………………………………………............... 3
Figure 4 Barrier and lifting gates ……………………………....................... 4
Figure 5 Family of Raspberry Pi …………………………………………… 9
Figure 6 Raspberry Pi 3…………………………………………………...... 10
Figure 7 The Pi camera …………………………………….......................... 11
Figure 8 The pi camera attachment ………………………………………… 12
Figure 9 The Pi display …………………………………………………….. 13
Figure 10 Pi display connected to the board………………………………… 13
Figure 11 Raspberry Pi on board features …………………………………… 14
Figure 12 3.5mm audio jack ………………………………………………… 15
Figure 13 40 pin GPIO port………………………………………………….. 16
Figure 14 GPIO pin numbering……………………………………………… 17
Figure 15 Python sample code……………………………………………….. 20
Figure 16 Ultrasonic sensor ……………………………………………......... 22
Figure 17 High frequency ultrasonic sensor ………………………………… 23
Figure 18 Inner view of enclosed ultrasonic sensor………………………...... 24
Figure 19 Enclosed ultrasonic sensor………………………………………... 24
Figure 20 HC-SR04 ultrasonic sensor……………………………………….. 26
Figure 21 Operation of Infrared sensor………………………………………. 28
Figure 22 Property of Infrared sensor……………………………………….. 29
Figure 23 RB-DFR-49 adjustable Infrared sensor…………………………… 30
Figure 24 L293D motor driver………………………………………………. 31
Figure 25 L293D Pin Diagram………………………………………………. 32
Figure 26 DC motor………………………………………………………….. 33
Figure 27 Micro Limit Switch……………………………………………….. 34
Figure 28 The design and working model……………………………………. 36
Figure 29 Design of Wheels…………………………………………………. 37

vi
Figure 30 Supporting pillars…..…………………………………………….. 38
Figure 31 Motor and Gear setup…………………………………………….. 38
Figure 32 Ultrasonic sensors….…………………………………………….. 39
Figure 33 Infrared Sensor……………………………………………………. 40
Figure 34 Limit Switches……………………………………………………. 40
Figure 35 Pin Map……………..…………………………………………….. 41
Figure 36 Schematic Design….…………………………………………….. 44
Figure 37 Vehicle Entering the parking……………………………………… 46
Figure 38 Web page Design…………………………………………………. 47
Figure 39 User Operating the gate…………………………………………… 47
Figure 40 Vehicle exiting the parking……………………………………….. 49
Figure 41 Fail Switch………………………………………………………... 50
Figure 42 Flowchart Design…………………………………………………. 51
Figure 43 Libraries imported………………………………………………… 52
Figure 44 GPIO setup………………………………………………………... 52
Figure 45 Ultrasonic function………………………………………………... 53
Figure 46 Reading ultrasonic sensor and Wi-Fi package………………….... 54
Figure 47 Mobile operation…………………………………………………. 54
Figure 48 Detection by ultrasonic sensor……………………………………. 55
Figure 49 Opened limit switch active……………………………………...... 55
Figure 50 Closing gate………………………………………………………. 56
Figure 51 Obstacle detection………………………………………………… 56
Figure 52 Closed limit switch active...………………………………………. 57
Figure 52 Motor functions…………………………………………………… 57

vii
Abstract

IMPLEMENTATION OF AUTOMATED

PARKING GATE CONTROLLER

USING RASPBERRY PI

By

Sai Anirudh Govindu

Masters of Science in Electrical Engineering

In this project a new design for an automated parking gate system is presented. A
Broadcom based SOC (system on chip) is the brain of this system. This configuration
reduces the human effort to open and to close the parking gate and eliminates
conventional physical devices such as knobs, button, and clicker.

Raspberry Pi is the system on chip used in this design with an Integrated Development
Environment and Python programming language. Ultrasonic and Infrared sensors are
used to detect the presence of an object and movement which help the SOC processor in
making a decision. As a security measure, the Wi-Fi enabled communication is used in
the design and utilized in the operation of the controller.

The implementation of the design is adaptable to different controllers and is not limited to
a particular type of controller. Implementing this model in the real life situation is simple.

viii
Chapter 1
Introduction

1.1 Introduction

The modern-day technology has seen a surge in urbanization; it has changed the way of
living by slowly taking an essential part people’s day to day living to complete a specific
task or interest. The technology boom has increased the human capability to work
efficiently which has resulted in technology evaluation for years to come.

There is a drastic improvement in communication techniques, manufacturing methods,


transportation, healthcare, production of goods and much more. The infrastructure we
live in has also developed which has led to home automation. Smart home includes
control of heating, lighting, air conditioning, security, even home appliances like ovens,
washers, dryers, etc. All these are monitored and controlled over Wi-Fi and via the
internet for controlled access.

This project focuses on the parking gate, based on a microcontroller, which engineers
have researched and developed. The modern parking gate minimizes the human effort to
open and close the gate; electronic circuits simplify it.

The different types of gates are listed below.

1. Sliding Gates

The name says it all, sliding gate slides on wheels. It needs a significant
amount of space and is universally used. There are 3 types of sliding gates.

a) V-Track Sliding Gate: The V-Track gate is very reliable and most
commonly used, but it’s not a good option in the areas of heavy snowfall
or ice buildup.

1
Figure 1: V-track sliding gate

b) Rear Pipe Track Sliding Gate: This gate is similar to V-track with a rear
pipe option and the opening of the gate needs to be 3 inches wide.
c) Cantilever Sliding Gate: This gate slides on a driveway without any
wheels. As a result, it’s used in areas of heavy snowfall.

Figure 2: Cantilever Slid gates

2
2. Swing Gates

This gate utilizes hydraulics or electro-mechanical operators to open inward or


outward position and is used in limited places.

Figure 3: Swing gate

3. Barrier or Lifting Gates

The gate is installed in industries and commercial areas. They are operated using
belt drivers and pulley to lift the barriers which result in giving way to exit the
building.

3
Figure 4: Barrier and lifting gates

1.2 Objective of the Project.

The primary purpose of the project is to design a secured cost-effective automated gate
controller for a sliding parking gate. A different type of gates can be implemented by
changing the gear system.

This design uses a smartphone to operate the gate when a vehicle is entering the parking
lot, and when the vehicle is exiting the parking lot, the system detects the presence of the
vehicle and operates the gate. The presence of the vehicle can be detected while exiting
parking such as a car, motorbike, truck, etc. regardless of the type, make and model.

The system is designed to operate only for the vehicle to exit the parking and not for any
other obstacle like animals, people, kids or any other foreign object. As a safety feature
while the gate is closing if the system detects any obstacle be it a person, vehicle, animal,
etc. the gate stops and opens up.

4
The salient features of the system are: -

a) Simple in installation
b) Sensors can be positioned as required by the user or by the length and height
of the vehicle.
c) The electronic components and parts are easily available to the user if
damaged over the long run.
d) The user can install the system without any help from a technician.

1.3 Outline of Project

Chapter 1: The Introduction of the project, objectives of project and outline.

Chapter 2: The Parking Gate Control System, Illustrates the present gate controllers,

design, and components

Chapter 3: Component Illustration, the description of the electrical parts used in the

project.

Chapter 4: Gate Controller Design, Implementation of the working design, operation,

The hardware pin map, operating scenarios.

Chapter 5: Software Design

Chapter 6: Conclusion

5
Chapter 2

Parking Gate Control System

2.1 Parking Gate Control System

A gate controller system is primarily used to open the gate, close the gate and keep the
gate open if an obstruction is detected. The modern-day gate controllers can be connected
to various devices and are very flexible.

Previously scenario behind the parking gate was that the person who is in the vehicle has
to get down, unlock the gate and slid or push it. After the vehicle is parked, the person
has to close the gate and lock it. It is basically secured with a lock and key but nowadays
breaking in by tampering the lock is very common and may not raise any alarm.

The parking system design can eliminate most of the effort put in to open and close the
gate and also has security built in to access the gate from outside the building or parking
structure, with identification procedure. Alarm systems can also be installed to alert the
specific operator, and necessary actions can be taken.

There are many companies which provide a smart solution to suit the desired application,
some of the leading firms are Honeywell, Doorking, Liftmaster, Gatepod, etc. The gate
controllers are mainly used in villas, independent houses, apartments.

The system designed has an improved design and tried to eliminate the complications of
opening and to close the gate physically and to make it a simple operation. It also helps
the physically challenged to use the system.

2.2 Components

The parking gate system consists of the components listed below.

1. Controller

The user can program the controller for the required specifications upon receiving
the input from various input devices connected to a system. As a result, the output
is sent to perform the necessary action. Different scenarios can be programmed
and can function at the same time.

6
2. Input

There are many types of input devices available to generate a signal when a
vehicle is detected. These sensors can also detect any obstacle when the gate is
moving and send a signal to the controller to perform necessary actions.

3. Output

The output is the motion of the gate which is connected to a motor. The motor
should be capable to handle the movement of the gate.

2.3 Input Component


1. Intercom
A mobile phone or a landline is a typical device which is used to operate the gate.
A specific phone number has to be registered in the system so that when the call is
made from the gate, and the user has the control to open it by keying in a number.
This system is conveniently used in apartment buildings or gated communities
due to a large number of users.
2. RF transmitter
Radio Frequency transmitter system is used to operate the gate with a remote
provided. When the button is pressed on the remote an RF signal is sent out from
the transmitter, at the receiver if the frequency of the signal matches then the gate
is operated.
Different companies use different frequencies to avoid mismatch; the frequencies
have to be registered with the governing body before they can use it in the system.
3. Keypad
A key combination of 4 digits or higher can be used as a code to operate the gate
which is stored in the system. As the code is keyed in the keypad, the gate opens
up. This input method can be used as a primary or secondary input depending
upon the type of entry or as per user specifications.

7
Chapter 3

Component Illustration

3.1 Raspberry Pi

Raspberry Pi is an advanced credit card sized computer which can be connected to any
display. Many different operating systems can be installed on this and can run various
programming compiler such as python, C, C++, Java, etc. These boards are manufactured
at reasonable prices so that students can use multiple electronic projects, robotics and so
on.

These devices are straightforward to use; the bootable OS can be downloaded from the
raspberry pi website, there are two OS images provided by the raspberry pi organization
and eight third-party OS images which work flawlessly, and they are user-friendly. The
image needs to be loaded on an SD card which has to be interested in the raspberry pi.
After setting up the SC card, the raspberry pi can be connected to a keyboard, mouse via
USB and the display via HDMI port.

Raspberry Pi is a series of computers which has been developed in the United Kingdom
by the raspberry pi foundation to encourage learning of basic computer science in schools
and colleges. The first generation model became very popular than expected, people
started using it for robotics and other purposes.

Many generations of raspberry pi have been developed and released. The 1st generations
Raspberry Pi Model B was released in February 2012; then Raspberry Pi Model A was
out with a more straightforward simpler design and cheaper cost. In 2014 Raspberry Pi 1
Model B+ was released with an improved design. In April 2014 the Raspberry Pi 2 with a
higher RAM and upgraded specifications were released. The newest mainline model the
raspberry pi B with an onboard Wi-Fi, Bluetooth and USB boot capabilities was released
in January 2017.

8
Figure 5: Family of Raspberry Pi

The Raspberry Pi foundation has estimated to have sold over five million raspberry pi’s
by February 2015 and became the bestselling British computer. They sold 11 million
units by November 2016 and 12.5 million units by March 2017, making it the 3rd
bestselling general purpose computer.

3.1.1 Raspberry Pi 3

Raspberry Pi 3 is the latest and the best general purpose computer admired out of the
family. It is a single board computer which has a Broadcom system on chip (SOC) that
includes ARM (Advanced RISC Machine) capable central processing unit (CPU) and a
graphics processing unit (GPU). It has a group of GPIO (General Purpose Input Output)
pins for connecting different devices or sensors to suit various applications.

9
Figure 6: Raspberry Pi 3

All the components on the Raspberry Pi are ready to use and are pre-assembled, its OS’s
are available to download free of cost, the schematics, data sheets are readily available.
The Raspberry Pi forum has many startup examples for the initial setup, and there is a
vast collection of YouTube videos explaining the process.

3.1.2 Hardware

Raspberry Pi 3, model B is constructed with the Broadcom BCM2837 SOC, 1.2 GHz 64-
bit quad-core ARM Cortex-A53 processor, it has an L2 cache of 512KB. One of the main
advantages of the raspberry pi is its capability to combine with various accessories to
extend its features. These additional add-ons are known as HATs (Hardware Attached on
Top) which can be connected to the board.

10
Some of Raspberry Pi’s add-on are

1. The Pi Camera: It is an 8-megapixel Pi camera which comes with a standard


visible light camera and an infrared-sensitive camera also known as Pi NoIR. It is
capable of capturing pictures in 3280 x 2464 resolution and the video in 1080p at
30fps.

Figure 7: The Pi camera

The camera is attached to the board using a CSI flat ribbon cable which is
included with the camera.

11
Figure 8: The pi camera attachment

2. The Sense HAT: This module is a package full of sensors, including the following
a) Gyroscope, to measure the orientation
b) Accelerometer to measure the acceleration
c) Magnetometer to measure the magnetic field of earth
d) Temperature sensor to measure the temperature
e) Barometric pressure sensor to measure the atmospheric pressure
f) A Humidity sensor to measure the water saturation percentage in the
air.

3. The Pi Display: This is a 7-inch touch display, which has a multi-touch capacitive
touchscreen, supports up to 10 finger touches. The display resolution is 800x480-
pixels at 60fps. It has a 700 viewing angle with a 24-bit RGB color.

12
Figure 9: The Pi display

The DSI ribbon cable is connected to the board on the back of the screen and then
mounted to raspberry pi with screws. The display is powered from the raspberry pi 5v
output which is connected via jumper cables.

Figure 10: Pi display connected to the board

13
3.1.3 On Board Features

The pin map for raspberry pi is as follows:

Figure 11: Raspberry Pi on board features

1. Micro USB Power Port

The Raspberry Pi’s power source is a micro USB +5.1 Volts supply. The current
requirement depends on how many peripherals are connected to the device,
typically it uses between 700-1000mA, but it can handle up to 2.5 Amps of
current. Any power supply above +5.1v volts DC will burn the board.

2. DSI Display Port

The DSI display port is used to connect the HAT add-on 7-inch display to the pi.

3. Bluetooth 4.1 and Wi-Fi

The newest pi comes with both the Wi-Fi and Bluetooth built in. This makes the
pi not only a desktop for the user but a hub for the internet of things (IoT). The
Wi-Fi supports 802.11b/g/n 2.4GHz and Bluetooth 4.0.

14
4. Broadcom BCM2837

This architecture is similar to the BCM2836; the only difference is the ARMv7
quad core cluster. This is a 64-bit quad-core, 1GB RAM CPU, which runs at 1.2
GHz making the device 50% faster than the previous versions.

5. USB 2.0 Port

The model is equipped with 4 USB 2.0 ports. This enables to connect different
peripherals such as keyboards, mice, webcams to obtain additional functionality.
The port is an On-The-Go USB which supports communication for all types of
USB devices

6. LAN port

This is a regular Ethernet port which is used for a wired internet connection

7. 3.5mm Audio Jack

The audio-jack is a 4-pole socket which carries both audio and composite video
signals. This is mostly found in multimedia devices. The style of connectors is
TRRS(Tip-Ring-Ring-Sleeve).

Figure 12: 3.5mm audio-jack

8. CSI Camera Port

This port is used to connect the HAT Pi camera.

15
9. HDMI Port

The Pi has an HDMI port which is used to connect a monitor or display as many
modern video devices come with an HDMI port, but there are other options as
well.

10. 40 Pin GPIO Port

One of the best and compelling features of the Pi is the row of GPIO (General
Purpose Input Output) pins on the top edge of the board.

Figure 13: 40 pin GPIO port

The GPIO pins are a visible interface between the outside world and the raspberry
pi. Alternatively, they are the switches which can be turned on and off as an input
or the raspberry pi can turn on and off as output. Twenty-six pins are for GPIO,
eight pins for ground, two pins each for +5 v supply and +3.3 v supply and two
pins for ID EEPROM. The ID EEPROM (Electrically Erasable Programmable
Read-Only Memory) is a non-volatile memory which contains data that identifies
the board and instructs Pi on how the GPIOs needs to be set up and which add-ons
are connected. It helps the Pi to locate and set up the add-on to boot and load the
required drivers.

16
Figure 14: GPIO pin numbering

The pins can be programmed to interact with the real world. Inputs need not be in
the form of a switch, but it could come from a sensor or a signal from another
device. The output can turn on a LED, or it can send a signal to a sensor. IF the Pi
is in a network, it can control multiple devices connected to it. The Pi is an ideal
device for the connectivity and control of physical devices over the internet.

17
3.1.4 GPIO Pins Specification

GPIO Function Pin Pin Function GPIO


No. No. No. NO
3.3 V 1 2 5V
2 SDA (I²C) 3 4 5V
3 SCL (I²C) 5 6 Gnd
4 7 8 TxD0 (UART) 14
Gnd 9 10 RxD0 (UART) 15
17 11 12 18
27 13 14 Gnd
22 15 16 23
3.3 V 17 18 24
10 MOSI (SPI) 19 20 Gnd
9 MISO (SPI) 21 22 25
11 SCLK (SPI) 23 24 CE0 (SPI) 8
Gnd 25 26 CE1 (SPI) 7
EEPROM ID_SD 27 28 ID SC EEPROM
5 29 30 Gnd
6 31 32 12
13 33 34 Gnd
19 35 36 N/A 16
26 37 38 DIN 20
Gnd 39 40 DOUT 21

3.1.5 Programming

The raspberry pi is very versatile in the aspect of programming as different compilers can
be installed as required by the user and can program the device in the programming
language that is convenient. Python programming language is one of the widely used
high-level general purpose programming languages that’s is easy to use, and the

18
Raspberry Pi helps it to interface the project to the real world. Python interpreters are
available to many operating systems; it is an open source software which has a
community-based development model.

The syntax of python is clean; it uses standard English keywords and readability is
emphasized. The clean syntax allows the programmers to showcase concepts in fewer
lines of code when compared to other languages such as C++ or Java. The design is
uncluttered by the layout, does not use brackets to start or end programs, semicolons after
statements are not necessary. It also has fewer syntax expectation than other languages.

Python library offers a wide range of features and facilities. It contains built-in modules
which give system functionality access to files such as input and output. Some of the
modules are specifically designed to enhance and encourage the portability of python

A simple code like turning on a LED when is connected to raspberry pi can be written in
4 lines. The GPIO library can be imported with the import command

import RPi.GPIO as GPIO # Import GPIO library

There are two different ways to number GPIO pins, and this is mainly for the user
flexibility and convenience. The board number system refers to pin numbers on the
Raspberry Pi; the hardware will always work regardless of the board version and
rewriting the code is avoided.
GPIO.setmode(GPIO.BOARD) # Uses board pin numbers

The BCM number system refers to the channel number on the Broadcom SOC, and a
diagram of the channel number is always needed to refer the pin to the board. The code
may need changes if the version of the Pi changes

GPIO.setmode(GPIO.BCM) ## Uses BCM pin numbers

The “GPIO.setup” is used to set up the channel as input or output for the particular pin.
GPIO.setup(7, GPIO.OUT) # Setup GPIO Pin 7 as an OUT

The “GPIO.output” is used to assign the output to the pin which is set up as an output,
and in this case, it is set to True or 1.
GPIO.output(7, True) ## Turn on GPIO pin 7

19
Below is a sample code which blinks a LED on and off. In this code, the user is asked to
enter how many times the LED has to blink

Figure 15: A python sample code

In python, indentation is very important and the TAB key is used to match the formatting.
The program will not execute if there are errors in the indentation.

20
3.1.6 Raspberry Pi 3 Specifications

Processor BCM2387 Broadcom chipset, 1.2GHz Quad-Core ARM


Cortex-A53 802.11 b/g/n Wi-Fi and Bluetooth 4.1.

GPU VideoCore IV® Dual core multimedia Processor. Offers


open GL ES 2.0, hardware-accelerated and 1080p30 H.264
decode.

Memory 1GB DDR2.

Operating System Linux OS, boots from Micro SD card.

Dimensions 85 x 56 x 17mm.

Power Micro USB socket 5V.

Connectors:

Ethernet 10/100 Base-T Ethernet port.

Video Output HDMI.

Audio Output Audio Output 3.5mm jack, HDMI, USB 4.

GPIO Connector 40-pin 2.54 mm expansion header: 2x20 strip.

Camera Connector 15-pin MIPI Camera Serial Interface (CSI-2).

Display Connector Display Serial Interface (DSI) 15-way flat flex cable
connector.

Memory Card Slot Push/pull Micro SD

21
3.2 Ultrasonic Sensor

The Ultrasonic sensors are one of the devices where there is a swift growth which has led
to an increasing demand for new areas of application. The growth in turn, has helped in
innovating various small eco-friendly components and devices.

The Ultrasonic sensor is a device which can measure the distance of an object with the
help of sound waves. It sends out waves at a particular frequency and listens for that
wave to return. The time elapsed between the waves helps in calculating the distance
between the sensor and the object.

Figure 16: Ultrasonic sensor

22
3.2.1 Working Principle and Structure
a) High Frequency Ultrasonic Sensor

This sensor is typically used where high-speed computations are usually


required in high-end components. Piezoelectric ceramics are used to
obtain speeds which range from hundreds of kilohertz. Particular material
is used to match the impedances between the open air space and the
piezoelectric ceramics.

Figure 17: High-frequency ultrasonic sensor

b) Ultrasonic Sensor Enclosed

To protect the sensor from exposure to electric circuits, heat, rain or


atmospheric constraints it must be enclosed. This type of sensor has a
metal case on the outside and immediately inside layer has a coating of
piezoelectric ceramics. At the beginning of the sensor, resin is coated.

23
Figure 18: The Inner view of closed Ultrasonic sensor

Figure 19: enclosed ultrasonic sensor

24
3.2.2 Features of Ultrasonic Sound Waves

The frequency range of ultrasonic waves range above 20 KHz, and the velocity of
sound is 344m/s.

a) Reflection

Opaque objects such as metal, wood can reflect waves which are sent by the
ultrasonic sensor, these reflected waves are detected, and this is one of the
leading features of the sensor.

b) Radiation and Wavelength of the Sensor

High resolutions can be obtained as the wavelength is shorter which is


inversely proportional to the speed of sound, i.e., 344 miles/second, this is the
precise computation the distance

c) Attenuation

As the distance of the objects to be detected gets longer, the waves get
weaker. It is an inversely proportional relation, shorter the distance higher the
frequency of the sensor.

Primarily, the ultrasonic sensor consists of two parts.

Transmitter: The waves are transmitted by the transmitter into the open air in the
frequency range of 20 KHz. These waves cannot be detected by human ears.

Receiver: The receiver detects the transmitted waves which are reflected back when
an obstacle is present in the propagation path.

Time and distance are inversely proportional, the longer it takes for the reflected
wave to reach the receiver the father the distance of the object and vice versa.
Attenuation plays a factor if the distance of the object is far away as the waves cannot
reach the receiver and the signal is lost.

25
3.2.3 Application

There are many different applications in which these sensors can be used; few
are listed below

a) They can be used for counting on a belt or as switches for approximation. The
circuit structure is straightforward.
b) It can be used as a level measure as the sensor detect almost all liquid
materials like milk, water, chemicals, etc.
c) Aerial work platforms use ultrasonic sensors for anti-collision detection as the
platforms are used to work on higher platforms and increase convenience.

3.2.4 HC-SR04 Ultrasonic Sensor Module

One of the cheapest and best-suited sensors available for a breadboard design. This
sensor can detect up to 4 meters.

Figure 20: HC-SR04 ultrasonic sensor

The pins of the sensor are as follows

Pin 1: Power supply

Pin 2: Trig, Transmitter

Pin 3: Echo, Receiver

Pin 4: GND, Ground

26
3.2.5 Distance Calculation

The fundamental principle is to start the timer when the trigger signal is sent and to
stop the timer when the signal is received by the receiver. The speed of sound and the
time taken is used in calculating the distance.

The following expression can be used to calculate the distance from the sensor to the
obstacle. The product is to be divided by two as the signal has traveled twice.

D = (340 × t) ÷ 2

D = distance in meter

T = Time in seconds

3.2.6 Operation of HC-SR04


a) A 5v power supply is given to the VCC port. The ground is connected to GND
b) The TRIG and ECHO pins are connected to the GPIO pins of the raspberry pi
and the output and the input signal are detected by the board.
c) The TRIG pin is set to high every 10 microseconds to transmit the wave.
d) The ECHO pin is enabled to detect the positive and negative edge of the
received signal, and the timer is stopped.

3.2.7 Specifications

Voltage: DC 5 volts

Current: 15 MA

Frequency: 40Hz

Minimum Distance: 2 meters

Maximum Distance: 4 meters

Dimension: 44x20x15 millimeters

27
3.3 Infrared Sensor

The Infrared sensor uses a specific light sensor to detect a signal at a wavelength in the
infrared region. The detector and the LED which transmits the wavelength should be
operating on the same wavelength. When there is an obstacle, the IR wave is reflected,
and the light is received by the detector. The detector mainly works on the principle of
change in light intensity, and this can be detected by using a threshold.

Figure 21: Operation of Infrared sensor

The unique property of the detector is that it can return the value or intensity of the
reflected light, this is used to measure how bright the object is.

28
Figure 22: Property of Infrared Sensor

3.3.1 Working of the Infrared Sensor

The emitter LED emits continues light in the infrared region which is
approximately from 300 GHz to 430 THz.

The receiver is placed below the transmitter so that it can detect any light
in the infrared region which is reflected

29
3.3.2 Applications
a) This sensor can detect movement when the light is reflected off the object.
b) It can be used to open or close doors on detection or when there is no
reflection from an object.
c) This sensor can also be used for counting the objects on belt conveyors.

3.3.3 RB-Dfr-49 Adjustable Infrared Sensor and Operation.

The sensor is a photoelectric switch which is a set of transmitter and


receiver in one device. The range of detection is adjustable depending on
the application from 3 - 80cm. The sensor is one of the cheapest and easy
to install infrared sensor available.

Figure 23: RB-DFE-49 adjustable Infrared sensor

30
A 5volt DC input is given to the sensor, the ground is connected, and the
third wire is connected to the GPIO pin as an input. The output from the
sensor remains high when the object is not detected and goes low when
there is an obstacle, and a red LED glows on the back of the sensor
indicates the sensor is active.

3.3.4 Specifications

Range: 3cm -80 cm

Power: 5volts DC, red wire

Yellow wire: output signal

Green wire: ground

3.4 L293D Motor Driver

Figure 24: L293D motor driver

L293D integrated Circuit (IC) is a dual H-bridge motor driver. The IC acts as an
amplifier as it takes in a lower current signal and provides a higher current signal which
is used to drive the motor connected.

31
The IC in its standard mode of operation can drive two DC motors both in forward,
reverse, one forward and one reverse direction as it has two inbuilt H-bridge driver
circuits. The logic input 00 or 11 will stop the motor, and logic input 10 or 01 will rotate
the motor in a clockwise or anti-clockwise direction respectively.

3.4.1 Pin Diagram

Figure 25: L293D Pin Description

The input logic is given to control the motor on pins 2 and 7 or 10 and 15
from the raspberry pi. Pins 1 and 9 are enable pins which will either enable the
left or the right side of the H-bridge. Pins 3 and 6 or 14 and 11 are connected
to the motor as an output. Pin 8 ‘Vcc2’ is connected to a power supply which
will drive the motor connected; this can range from 9 volts to 36 volts. The
pin 16 ‘Vcc1’ is given 5volts supply to activate the IC from the Raspberry Pi

32
3.5 12Volts DC Electric Motor

Figure 26: The DC motor

The DC motor is a high torque and low noise 12V, 60 RPM geared electric motor. The
two leads behind the motor connect to a 12volt power supply, which either rotates in a
clockwise or an anti-clockwise direction depending on the polarity.

3.6 Limit Switch

A limit switch is an electro-mechanic switch which is operated by the motion of an object


or a machine part. Limit switches are mainly used in control systems as a safety device or
to count the number of objects passing at a given time.

The switch consists of an actuator which is physically connected to electrical contacts


when the actuator come in contact with any object the contact or an electrical connection
is broken.

Limit switches are used in numerous applications as it’s easy to install, reliable, and
rugged.
33
3.6.1 Application
a) Limit switches are used in the garage door opener to stop the motor when
the door is fully closed or opened.
b) It is also used in lathe machines to know the maximum and minimum
limits.
c) Miniature versions of the limit switch are called micro limit switches, used
in photocopiers, microwave ovens, computer printers, convertible tops,
etc.

3.6.2 Micro Limit Switch

1 2
3

Figure 27: Micro Limit Switch

The Micro limit switch is a three-terminal quick action switch, it can


either be a normally open or a normally closed switch. This type of switch
is usually used in automated machines, printers and electronics devices.

34
The actuator of the switch usually has a hinged wheel above the button to
be pushed. In the above figure 27, we have a micro limit switch which has
three output contacts. If the positive and the negative leads of a battery are
connected to the leads one and three, this is a typically closed connection.
If the positive and the negative leads of the cell are connected to two and
either one or three, then this is an open connection and when the switch is
pressed it becomes a closed connection. This feature is mainly used in the
garage door to stop the motor when the door has reached the limit.

35
Chapter 4

Gate Controller Design

4.1 The Design

The purpose of this project is to create a modern design which is low cost, easy to
install and automated which required less human effort to open, to close and also to
secure the gate.

To achieve the above result, two ultrasonic sensors are used to detect the vehicle.
Additional sensors can be used to modify the design.

Limit
Switches
12V DC Motor

Ultrasonic Sensors
Raspberry Pi

Figure 28: The design and working model

36
The above figure 28 shows the setup of the working gate controller design with
the placement of the components scaled to the model and peripherals connected to
the controller.

a) The raspberry pi controller is placed at the bottom of the design to


accommodate space for the input and output components.

b) The gate is mounted on two sets of four wheels to attain better stability
and balance as shown in figure 29.

Figure 29: Design of Wheels

c) The pillars with wheels are placed on both sides of the gate to support
opening and closing without deviating from the desired path as shown in
figure 30.

37
Figure 30: Supporting pillars

d) The motor is fixed to a rotatory gear, and the gate with a linear gear as
shown in the below figure 31, which gives us the circular to linear
transfer motion and in turn slides the gate to open or to close.

Figure 31: Motor and Gear setup

38
e) Ultrasonic sensors are placed side by side to detect the length of a small
car as it is a scaled model, in the real life situation the sensors can be
placed according to the desired needs of the user depending on the length
of the vehicle which has to be detected upon arrival. The position can be
changed and only if both then sensors detect an object the gate will
operate.

Figure 32: Ultrasonic sensors

f) The Infrared sensor is placed before the gate to detect any obstacle while
the gate is in motion. IR sensor is to avoid any misshape while the vehicle
is entering the parking or exiting the parking. The detection is not
restricted to only a vehicle, but it can also be an animal or a person.

39
Figure 33: Infrared Sensor

g) Limit switches are the gate limiting devices, which controls when to stop
the motor when the gate is in motion. As shown in figure 34, the gate is
completely closed the when the 1st limit switch is closed, and the gate is
completely open when the 2nd limit switch is closed.

Figure 34: Limit Switches

40
4.2 Pin Map

1.5v

1.5v

Figure 35: Pin Map

The above figure 35 portrays the pin map of different components connected to the
Raspberry Pi.

The devices used are as follows

a) Raspberry Pi 3
b) Ultrasonic Sensor
c) L293D Motor driver
d) 12V DC motor

41
e) Limit Switches
f) Infrared sensor
g) 12V battery for the motor

These devices are connected, placed and programmed to work as specified

a) The Raspberry Pi has to be connected to the AC mains with a 5v adapter.


b) The ultrasonic 1 GND pin is connected to GND of the raspberry pi.
c) 5v power output from the controller is given to the VCC of the sensor. The circuit
is complete for the sensor and it is powered up.
d) The GPIO 4 pin of the raspberry pi which is set up as an output pin is linked to
the TRIG pin of the ultrasonic sensor.
e) The pin GPIO 17 of the raspberry pi is configured as an input and coupled to the
ECHO pin of the ultrasonic sensor with the help of a 470Ω resistance in between
to protect the raspberry pi from any input feedback from the sensor which can
damage the controller
f) The ultrasonic 2 GND pin is connected to GND of the raspberry pi.
g) 5v power output from the controller is attached to the VCC of the sensor. The
circuit is complete for the sensor and is powered up.
h) The GPIO 13 pin of the raspberry pi which is set up as an output pin is linked to
the TRIG pin of the ultrasonic sensor.
i) The pin GPIO 26 of the raspberry pi is configured as an input and connected to
the ECHO pin of the sensor with the help of a 470Ω resistance in between to
protect the raspberry pi from any input feedback from the sensor which can
damage the controller
j) The L293D motor driver pin 1 is connected to the GPIO 25 pin of the raspberry pi
as an output which actives the left side of the driver.
k) Pin 2 and pin 7 are connected to GPIO 24 and GPIO 25. If the input to the pins
are “10” the motor connected will rotate clockwise and if the input to the pins are
“01” the motor connected will turn anticlockwise.
l) Pin 3 and pin 6 are connected to the leads of the motor for operation.

42
m) Pin 4 and pin 5 are the ground pins of the driver which is connected to the ground
of the raspberry pi.
n) Pin 8 is connected to the positive terminal of a 12-volt supply that powers the DC
motor for its operation. The negative terminal of the supply is grounded.
o) The Infrared sensor has three terminals, one is coupled to the 5v, second is
attached to the ground pin, and the third is linked GPIO 12 as an input with the
help of a 220 Ω resistor as to avoid any input feedback.
p) One of the terminals of the button is connected to GPIO 16 as an input with the
help of a 330 Ω resistor to avoid input feedback. The 2nd terminal is connected to
a 3.3volt input.
q) The limit switch has three terminals, the first lead is connected to a 3.3volts
supply pin of the raspberry pi and the last terminal to the ground with the help of
a 330 Ω resistor to avoid input feedback.
r) The center terminal of the switch is connected to GPIO 17 and GPIO 27 as input
with the help of 330 Ω to prevent any input feedback.

43
4.3 Schematic Design

9v
>

Figure 36: Schematic Design

44
The above figure 36 exhibits the working schematic setup which is similar to the pin map
in the previous section. The components are programmed and placed to suit the design as
per specifications.

The components mentioned are placed on the breadboard and physically connected to
make the design work. The Raspberry Pi is set at the bottom of the board to
accommodate space for other devices. The breadboard is placed perpendicular to the
raspberry pi so that the GPIO pin connector can be mapped on to the breadboard.
Ultrasonic sensors are placed in parallel to the raspberry and breadboard, as they can
detect the vehicle during entry and exit of the parking.

The motor and limit switches are side by side, driving and controlling the gate together.

4.4 Operation of the Design

The Raspberry is connected to the AC power supply, and the system is powered up. The
python code created on the raspberry pi and the server to access the webpage will run on-
boot of the Raspberry Pi. The system is all set up to work independently without any
outside control.

a) Situation #1

Vehicle Entering the parking when the gate is closed.

The below figure 37 shows the placement of the devices. The entrance is closed if
a vehicle comes near the gate.

The Raspberry Pi 3 equipped with Wi-Fi built in and requires an initial setup. It
has to be connected to a router available to the user that is easily accessible. The
router is a conventional device that is available at home which provides internet
access. Upon arrival, to the gate, a connection is established to the router with the
mobile phone available to the user. The IP address of the raspberry pi with the
port “:8080” is keyed in a web browser that brings up the webpage to operate the
gate. The program running on the raspberry pi creates a server which the user can
access at any time.

45
Figure 37: Vehicle Entering the parking

If the web page is accessed as shown in figure 38, the user can find an option to
open the gate and enter the parking lot. The webpage can be obtained on any
device that is connected to the router if the IP address of the raspberry is known.
No internet connection is required to access the webpage as the server is running
locally on the network.

46
Figure 38: Webpage Design

When the open button is pressed the Pi receives a signal to drive the motor
connected to the gate and the gate is opened for the vehicle to enter as shown in
figure 39.

Figure 39: User operating the gate

47
The gate opens until the limit switch is pressed which in turn sends a signal to
stop the motor when the gate is completely open. After waiting for five seconds
so as the vehicle can enter the parking, then the gate closes until another limit
switch sends a signal to stop the motor when the gate is closed completely. If the
infrared sensor detects any obstacle while the gate closes, the gate stops, the gate
opens up, waits for the obstruction to clear and then gate closes if no obstacle is
detected.

During this situation, the ultrasonic sensors are disabled as they may interfere
with the vehicle entering the parking.

b) Situation #2

Car exiting the parking when the gate is closed

Figure 40 illustrates the situation.

The second situation is when the vehicle wants to leave the parking lot. The
vehicle has to stop before the gate so that both the ultrasonic sensors can detect
the vehicle present. If both sensors identify the vehicle, then a signal is sent to the
raspberry pi to open up the gate, and the motor is driven.

The gate is open until the ultrasonic sensors don’t detect the vehicle in their path.
During the exit of the vehicle, if the gate closes and the vehicle is caught in the
way of the gate, the infrared sensor detects the vehicle and stops the gate, opens
up the gate so that the vehicle is clear to exit the parking.

When the infrared sensor is clear from any obstacle, the raspberry pi sends a
signal to the motors to close the gate until the pi receives a signal from the limit
switch to stop the motor.

48
Figure 40: Vehicle exiting the parking

c) Situation #3
Fail Switch to open the gate
Figure 41 shows the fail switch on the breadboard.
The fail switch is a secondary entry option which is located inside the parking on the
breadboard. If either of the ultrasonic sensors fails to detect the vehicle or if the Wi-Fi
connectivity fails upon arrival someone from inside the parking lot can operate the
gate by pressing the button which sends a signal to the raspberry pi to open the gate.
This is a safety feature which is incorporated into the design to avoid being locked
out or locked in the parking lot.

49
Figure 41: Fail Switch

4.5 Advantages
a) This design is cost effective as the hardware can be built under $100 and all the
components are available to the average costumer.
b) The design is also compatible to other microcontrollers and is universal.
c) It can be implemented to any kind of parking system either indoor or outdoor to
an apartment or an independent house.
d) The components can be upgraded to slightly costlier ones which provide better
range and they can use the same controller and program.
e) The same design can be implemented in with easy installation procedure.

50
Chapter 5
Software Design
5.1 Flow Chart

Yes Yes
No

No

Yes

No

Figure 42: Design Flowchart

51
a) Setup web server

Node.js software is used to create the server. Node.js is open source


platform and run by JavaScript on the raspberry pi. The script written on
the raspberry pi is embedded into an HTML webpage which can be
accessed using a web browser.

b) Import libraries

Figure 42: Libraries imported

a. The raspberry pi GPIO pin settings are imported from the python library.
b. Time setting is imported which helps in function of ultrasonic sensor.
c. Sleep setting is imported from time.

c) Component setup

Figure 44: GPIO setup

52
The GPIO pins are defined and set up as an input or an output depending on the
function of the pins based on the devices they are connected.
I. Ultrasonic1_trig and ultrasonic2_trig are set up to pin 7 and 33 as an
output.
II. Ultrasonic1_echo and ultrasonic2_echo are set up to pin 13 and 37 as an
input.
III. All the three pin that connects to the motor driver are set up as an output.
IV. Pin 11 and 15 are the inputs from the limit switches.
V. Pin 36 is the input from the button fail-switch.
VI. Pin 32 is the input from the infrared sensor.

Figure 45: Ultrasonic function


The ultrasonic distance measurement function calculates the distance between
an object. The TRIG pin is active for a duration of 10µs by setting the pin

53
high and then low. When the ECHO pin is low, the time is started and as the
ECHO pin is high the time is stopped. The time elapsed is calculated, and the
distance is measured.

d) Read Ultrasonic sensor and Wi-Fi package

Figure 46: Reading ultrasonic sensor and Wi-Fi package.

The Wi-Fi function is active, and the ultrasonic sensor continuously calculates
the distance of the wave.
e) Operated by mobile

Figure 47: Mobile operation


If the webpage created is accessed by the user and the open function is called,
the gate opens up for the vehicle to proceed into the parking.

54
f) Vehicle detection by ultrasonic sensor

Figure 48: Detection by ultrasonic sensor

A threshold value of 15cm is set for the ultrasonic sensors, if an object is


detected below 15cm in both the sensors, then the gate is operated.

g) Completely open

Figure 49: Opened limit switch active

The movement of the gate is stopped when the raspberry pi detects a high
signal from the open limit.

55
h) Closing gate

Figure 50: Closing gate

All the sensors are checked for any obstacles, i.e., the ultrasonic sensor
distance threshold value is higher than 15cm, the infrared sensor is low, and
the open limit switch is high. If all of the above conditions are satisfied, then
the gate is closed.

i) Obstacle detected

Figure 51: Obstacle detection

The infrared sensor detects any obstacle while closing if a low value is sent,
the gate stops and opens up until the path is clear.

56
j) Stop

Figure 52: Closed limit switch active


The stop function for the motor is called the closed limit switch is high
indicating the gate is completely closed.

k) Function for the motor

Figure 53: Motor functions


The open, close and stop functions of the motor are written as shown in figure
53. Pins “Motor1A” and “Motor1B” are connected to the DC motor which
drives it clockwise and anticlockwise to open and close the gate. All the pins
are set low to stop the motor.
The complete code is provided in Appendix A

57
Chapter 6
Conclusion

The advancement in technology with home automation in today’s world is endless,


additional features can be designed and installed according to user requirements as
many devices are plug and play. The parking gate controller is one of the upcoming
systems which is changing day by day with new methods, design, procedures and
much more.

The scaled model was indigenously designed with the help of household components
like cabinet catcher for wheels, dollhouse fence for the gate, etc. The placement of the
elements on the board is according to the required size and scale of the model; this
can also be implemented in the real life situation. The cost to purchase all the
components was below $100, and they are readily available in the market.

Some of the features which were considered during the design of this system were
cost-effective and easy to install when compared to other existing systems. The
design is flexible, can be modified according to user specifications, and the gate type
can also be changed to a barrier or a swinging gate not restricting it to a sliding gate.
The sliding gate was chosen as it’s easy to implement in a model.

The controller used, Raspberry Pi 3 is very reliable, cost-effective and robust. During
testing, the Raspberry Pi was very stable, the python code and the server were
running continuously for three days without any glitches with a constant power
supply to Raspberry Pi. The hardware connected to the Raspberry Pi also performed
as expected without any failure.

For any home automation design, there is always a scope for improvement as the
hardware changes almost every year, software are updated on a timely basis, and the
implementation may become more straightforward.

58
References

1. Simon Monk, Programming the Raspberry Pi: Getting Started with Python, 2012.
2. Dave Polka, Motors & Drives: A Practical Technology Guide, 2010.
3. J. David N. Cheeke , Fundamentals and Applications of Ultrasonic Waves, 2016.
4. John Paul Mueller, Beginning Programming with Python for Dummies, 2014.
5. Marc Harter and Mike Cantelon, Node.js in action,2013.
6. Marijn Haverbeke, Eloquent JavaScript: A Modern Introduction to
Programming,2011

59
Appendix A
Python Code
a) Ultrasonic sensor code
import RPi.GPIO as GPIO
from time import sleep
import time

GPIO.setmode(GPIO.BOARD)
Motor1A = 16
Motor1B = 18
Motor1E = 22
Ultrasonic1_trig = 7
Ultrasonic1_echo = 13
Ultrasonic2_trig = 33
Ultrasonic2_echo = 37

k=0
o=0
l=0
m =0

GPIO.setup(Ultrasonic1_trig, GPIO.OUT)
GPIO.setup(Ultrasonic2_trig, GPIO.OUT)
GPIO.setup(Ultrasonic1_echo, GPIO.IN)
GPIO.setup(Ultrasonic2_echo, GPIO.IN)
GPIO.setup(Motor1A,GPIO.OUT)
GPIO.setup(Motor1B,GPIO.OUT)
GPIO.setup(Motor1E,GPIO.OUT)

GPIO.setup(29,GPIO.OUT)

GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)


GPIO.setup(15, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(36, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(32, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

def open():
GPIO.output(Motor1A,GPIO.HIGH)
GPIO.output(Motor1B,GPIO.LOW)
GPIO.output(Motor1E,GPIO.HIGH)
print("Close function called")

60
def close():
GPIO.output(Motor1A,GPIO.LOW)
GPIO.output(Motor1B,GPIO.HIGH)
GPIO.output(Motor1E,GPIO.HIGH)
print("Open function called")

def stop():
GPIO.output(Motor1A,GPIO.LOW)
GPIO.output(Motor1E,GPIO.LOW)
GPIO.output(Motor1B,GPIO.LOW)
print("Open function called")

def dist(GPIO_TRIGGER,GPIO_ECHO):
GPIO.output(GPIO_TRIGGER,True)

time.sleep(0.00001)
GPIO.output(GPIO_TRIGGER,False)

StartTime = time.time()
StopTime = time.time()

while GPIO.input(GPIO_ECHO) == 0:
StartTime = time.time()
while GPIO.input(GPIO_ECHO) == 1:
StopTime = time.time()

TimeElapsed = StopTime -StartTime

dist = (TimeElapsed * 34300) / 2

return dist

try:
GPIO.output(29,GPIO.HIGH)
stop()
n=0
opened_for_limit = 0
opened_for_limit2= 0
limit_open = 0
closed_for_limit = 0
while True:
if(GPIO.input(29) == 0):

61
print("running")
continue
time.sleep(0.3)
direction = dist (Ultrasonic1_trig,Ultrasonic1_echo)
print ("1: "+str(direction))
direction1 = dist (Ultrasonic2_trig,Ultrasonic2_echo)
print ("2: "+str(direction1))
#close()
if (GPIO.input(32)==0 and l==1):
print("IR Blocked")
stop()
time.sleep(3)
print("Opening")
open()
opened_for_limit=1
l=0
if (limit_open==1 and direction >15 and direction1>15 and
GPIO.input(32)==1):
print("Closing")
stop()
time.sleep(3)
close()
limit_open=0
l=1
closed_for_limit=1
opened_for_limit2=0
print("Closed")
continue
if (GPIO.input(36)==1) or (opened_for_limit2==0 and
direction <= 15 and direction1 <= 15):
print("Opening")
stop()
time.sleep(3)
open()
opened_for_limit=1
opened_for_limit2=1
l=0
print("Opened")
continue
if opened_for_limit == 1 and GPIO.input(15) == 1:
stop()
limit_open=1
opened_for_limit=0

62
l=0
print("Limti Open")
continue
if closed_for_limit == 1 and GPIO.input(11) == 1:
stop()
l=0
closed_for_limit=0
opened_for_limit2=0
print("Limti Closed")
continue

except KeyboardInterrupt:
print " Quit"
GPIO.cleanup()

b) Node.js server code


var fs = require('fs');
var sleep = require('sleep');

var express = require('express');


var app = express();
var port = process.env.PORT || 8080;

app.listen(port);
console.log('Server started! At http://localhost:' + port);

app.post('/open', function(req, res) {


console.log("Open");
const exec = require('child_process').exec;
exec('python abc.py', (error, stdout, stderr) => {
if (error) {
console.error('stderr', stderr);
res.send(stderr);
throw error;
}
res.send(''+stdout);
console.log('stdout', stdout);

});
});

app.get('/', function(req, response) {

63
response.writeHeader(200, {"Content-Type": "text/html"});
var readSream = fs.createReadStream('index.html','utf8')
readSream.pipe(response);

});

console.log("server is running on port number ");

c) Gate operated by mobile


import sys
import RPi. GPIO as GPIO
from time import sleep
import time

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(15, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(32, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(29, GPIO.OUT)

Motor1A = 16
Motor1B = 18
Motor1E = 22

GPIO.setup(Motor1A,GPIO.OUT)
GPIO.setup(Motor1B,GPIO.OUT)
GPIO.setup(Motor1E,GPIO.OUT)

def open():
GPIO.output(Motor1A,GPIO.HIGH)
GPIO.output(Motor1B,GPIO.LOW)
GPIO.output(Motor1E,GPIO.HIGH)

def close():
GPIO.output(Motor1A,GPIO.LOW)
GPIO.output(Motor1B,GPIO.HIGH)
GPIO.output(Motor1E,GPIO.HIGH)

def stop():
GPIO.output(Motor1A,GPIO.LOW)

64
GPIO.output(Motor1E,GPIO.LOW)
GPIO.output(Motor1B,GPIO.LOW)

def open():
while True:
open()
if(GPIO.input(15) == 1):
stop()
break
time.sleep(5)
close()

def close():
print("Have a Nice Day")
sys.stdout.flush()
while True:
close()
if(GPIO.input(32) == 0):
stop()
time.sleep(1)
open()
if(GPIO.input(11) == 1):
stop()
break
GPIO.output(29,GPIO.LOW)
open()
time.sleep(2)
GPIO.output(29,GPIO.HIGH)

65

Das könnte Ihnen auch gefallen