csit.selu.educsit.selu.edu/~csit/seniorprojects/seniorprojects... · web viewwith addition of a...
TRANSCRIPT
Wireless Gate System
ET 494
Fall 2018
By: Kyle Rudolph, Brandon Gonlag, and Channing Maher
Advisor: Dr.Mohammad
Professor: Dr.Koutsougeras
Abstract:
This project requires that we build a gate system that wirelessly interfaces with a device
that can control the gate’s operations (opening and closing). For this project we will use two
microcontrollers. The Nano programmed to control a stepper motor, this motor will be used to
open and close the gate. And the Yun, this will manage and handle request from the HTTP. The
Yun will also manage inputs sent to the Nano. Inputs for the gate system will also be handled by
an Android based application, this application will require an initial password to gain full access
to the app. With addition of a iPhone compatible app, access can be granted to the system via
iPhone.
Introduction and Goals:
This project uses a HTTP client request system with an Arduino Yun and MIT’s App
Inventor to control the gate’s functions. This is our plans from the beginning of the semester:
● Program the Arduino to communicate through the internet
● Figure out how to implement our module to the gate
● Program an app to function with the HTTP request needed
Design and Materials:
Parts List:
● Arduino Nano ▪ Microcontroller
▪ Manages Stepper Motor
● Arduino Yun ▪ Microcontroller
▪ Manages HTTP request
▪ Manages the Nano
Accomplishments:
1. Deciding on a Microcontroller and Bluetooth Module:
Microcontrollers like the Arduino Uno and Raspberry Pi 3 were all options for this
project, but we felt these were a bit over the top. We concluded that the Arduino Nano was
perfect for the task. It features RX and TX I/Os that will allow us to communication between our
Bluetooth Module and the user’s device. The Bluetooth device will be used to communicate with
the Nano’s RX and TX I/Os.
2. Ordered the Parts for Constructing the Lock:
Stepper Motor Used to move through rails
Functions as the muscle of the
project
RFID Scanner Quick access via microchip
Specific to a certain frequency
Short ranged
H-Bridge Used to supply higher current
and voltage
Helps control motor
We worked closely with our advisor to figure out a setup for the lock hardware itself.
After some ideas from our advisor, we started off with a gear rack and pinion as the main drive
component for our lock. After researching, we decided to use a drawer slide for the rack to glide
along. We ended up scrapping the rack and pinion idea and simply fastened the servo motor
itself to the locking mechanism on the deadbolt.
3. Deciding the Combination Implementation:
We originally had planned to use an EPROM and create a logic gate system to act as a
combination lock. This became too complex to complete. The idea has now shifted to the use of
the Arduino Nano. We will program the Nano to act as a combination lock.
4. Developed a Functioning Lock System with Arduino:
Making use of the EEPROM on the Arduino. We have been capable of setting a
password and saving it. Users can reset the password and implementing their own. This is
currently functional with the physical keypad, implementation with Bluetooth is currently in the
works.
5. Created a Functional Deadbolt Prototype:
An Arduino and power supply has been attached to a servo. The servo is fastened on to the
deadbolt lock. Both of which are mounted in a box that will act as temporary housing for the
setup. When a correct password is typed into the keypad, the Arduino tells the servo to rotate to
its zero-degree position. The zero-degree position unlocks the door from its standard ninety-
degree locked position.
6. App Created with App Inventor 2:
An application for Android devices has been developed. The current app is not functional
with the Arduino just yet. Further research into Bluetooth communication is needed to properly
send signals through the HC-06 to Arduino.
7. Redesigning our Project to Work for Gate System
Redesigning our project to work with another system. Since both systems were fairly alike,
this change will not affect our estimated finish date. Thought new scope for the project will be
needed.
8. Replaced the Bluetooth connectivity with Internet
Our project scope has changed slightly, instead of using Bluetooth for app access. We are
now using HTTP request from over the internet. This change was made to make accessing the
gate easier over any distance.
9. Implemented a Yun while keeping a Nano
This change was made to allow access to the internet with a Arduino capable of doing so. We
choose to keep the Nano to control the stepper motor since that will cause delay in the HTTP
request.
Individual Progress:
● Channing - Researched how to use and implement Bluetooth connectivity. Researching
app development. Deciding on a microcontroller. Now working on programming
functions via Microcontrollers and setting up Internet access to App and Yun via url
command lines.
○ A simple construction of the microcontroller to the Bluetooth device has been
built. (Has been changed)
○ Developing an application with App Inventor 2 has made progress. Improvement
for the app is currently planned for next semester. (No longer working on)
○ Using block code to program the app to function and deliver wireless signals via
Bluetooth.(No longer working on)
○ Code to properly have the app and the Arduino communicating is currently being
developed to work with the already created lock system code. (No longer working
on)
○ Port Forwarded connection to the Yun via local home network.
○ Programming the Yun to handle logic and HTTP request to control the motor.
○ Programming the Nano to work the motor when the Master controller(YUN)
request.
○ Start developing scaled down prototype of project
○ Development of a prototype was completed but found to be difficult due to skill
sets.
● Brandon – Created a working deadbolt prototype by fastening a servo motor to the
locking mechanism of a deadbolt lock. Worked with Kyle to get the servo running with
the keypad program. Completed a functional locking mechanism that works with a
microcontroller.
○ Developed a small prototype box to simulate as the inside of the door lock.
○ Helped wire the Arduino to the servo controlling the deadbolts locking system.
○ Working with team to finish goals and improve the project.
(With new project scope)
○ Working on the app
○ Researched ways to automatically activate the gate if a car is exiting. The most
effective way is to use a vehicle exit sensor buried underground which detects the
car via electromagnetic waves as it’s approaching the gate.
○ Developing an iOS app that will universally run on Apple mobile products. The
application features a email and password login system. The application is set to
remember the user’s information so the user will only need to log in once and be
able to immediately access the gate operations. The email and password
registration is linked to an online database called Firebase. This database can be
used to monitor the accounts and users that are accessing the application.
● Kyle – Building the circuit for the wireless door lock and getting the EEPROM to interact
with the keypad. Doing research on the best way to save passwords to EEPROM.
○ Built 3x4 keypad using buttons and OR gates connected to LEDs to be able to
read if the zero to nine is being read. We did this to see what values are being read
to the EPROM. (No longer working on)
○ When trying to get the EEPROM working we came across with problems of how
to store the new 4-digit passwords to the EEPROM without programming it. (No
longer working on)
○ When working on the EEPROM we decide it was taking up too much time and
went to Arduino. When working on the Arduino first task was to make LED
blink. When typing in the four-digit password it would make a green LED blink
three times and pressing the * button to confirm the password. When the four-
digit password was wrong it would make the red LED blink four times.
○ The next task was to be able to change the current password to a new password
and by pressing the # button to change the password. When changing the
password both LED will blink back and forth with each other three time to let the
user know the password was changed. The problem we encounter was when
changing to the new password when turning off the Arduino and turning it back
on it wouldn’t save the new password and when turning it back on it would rest to
the original password that we put into the code.
○ The task now was to find a way to be able to save the new current password to the
Arduino when it turns off. When working on the code we decide to use the
EEPROM library to write the current password word we have and when we
changed the current password. It will store it in the memory of the Arduino so
when it turns off it will turn off and turns back on it will keep the user password.
○ The next thing we did was combine the keypad part and the servo part to see if the
project works together and to see if the servo and lock work together.
(Current task with new project scope) (No longer working on)
○ Device integration with gate
○ The new task is to make an Android app to be able to control it over the internet
using MIT APP Inverter 2. When logging into the app for the first time it will tell
the user to register. Once the new user register and log into the app it will keep the
user logged in.
○ The next task assigned was to use RFID scanner and writer to be able to open and
close the gate. When coming to the gate the RFID scanner will pick up the RFID
tags that are given to the people assigned to open the gate. They can assign new
users to the account when they use the master key to scan first and scan their tag
after, so it will give it permission to open the gate.
○ RFID scanner was successfully implemented to the project.
Project Timeline:
Project Plans:
Old Plans
1. Further development of the app and combination system.
2. Add a sensor to detected when the door is closed, this will allow for the door to set a lock
timer after a delay.
3. Store user’s information for later access.
Current Plans
1. Develop an app to work with the gate
2. Implement our project with the gate
3. Research longer range wireless connection
4. Development of prototype
Conclusion:
The initial plans for this project is to create a locking system and have it controlled
through Bluetooth connections, but with a new plan presented, our new plans are to control a
gate automatically through wireless application designed for a phone. The project will challenge
us to use our collective thoughts on different methods to achieve this goal. Ideas that fail will
only push us to build new and creative ways of achieving our desired goals. The time we have
spent this semester researching has improved our overall idea of how this project can be created
and improved upon.
Code/Images/Examples Section:
Section 1:
Button to turn on and off LED and turn on and off the servo motor.
Section 2:
● This current version of the app uses a simple line of block code to connect to HTTP.
This is to make the sure be able to use their username and password to login to.
This current version of the app uses a simple line of block code to send HTTP
request though any wirelessly connect access to send a request to the YUN
Section 3:
#include <SPI.h>#include <MFRC522.h>#define SS_PIN 10#define RST_PIN 9MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.int LED_G = 6;int LED_R = 7;
void setup() { Serial.begin(9600); // Initiate a serial communication SPI.begin(); // Initiate SPI bus mfrc522.PCD_Init(); // Initiate MFRC522 pinMode(LED_G,OUTPUT); pinMode(LED_R,OUTPUT); Serial.println("Put your card to the reader..."); Serial.println();
}void loop() { // Look for new cards if ( ! mfrc522.PICC_IsNewCardPresent()) { return; } // Select one of the cards if ( ! mfrc522.PICC_ReadCardSerial()) { return; } //Show UID on serial monitor Serial.print("UID tag :"); String content= ""; byte letter; for (byte i = 0; i < mfrc522.uid.size; i++) { Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); Serial.print(mfrc522.uid.uidByte[i], HEX); content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); content.concat(String(mfrc522.uid.uidByte[i], HEX)); } Serial.println(); Serial.print("Message : "); content.toUpperCase(); if (content.substring(1) == "C3 86 47 31") //change here the UID of the card/cards that you want to give access { Serial.println("Authorized access"); Serial.println(); digitalWrite(LED_G,HIGH); delay(2000); digitalWrite(LED_G,LOW); } else { Serial.println(" Access denied"); digitalWrite(LED_R,HIGH); delay(1000); digitalWrite(LED_R,LOW);
}}
Section 4:
Section 5:
//Nano Code\\int oPin = 6;int cPin = 7;int a = 8;int b = 9;int c = 10;int d = 11;int speedX = 10; //speedX * 8 = realtime(240+100)340ms
void setup() { Serial.begin(9600); pinMode(oPin,INPUT); pinMode(cPin,INPUT); pinMode(a,OUTPUT); pinMode(b,OUTPUT); pinMode(c,OUTPUT); pinMode(d,OUTPUT);}
void loop() { int rCC = openPin(7); int rOC = openPin(6); Serial.print("rCC: "); Serial.println(rCC); Serial.print("rOC: "); Serial.println(rOC); motorF(rCC); motorR(rOC); defualtM();}
void motorF (int openPin){ if(openPin == 1){ digitalWrite(a,HIGH); //1000 start delay(speedX); digitalWrite(b,HIGH); //1100 delay(speedX); digitalWrite(a,LOW); //0100 delay(speedX); digitalWrite(c,HIGH); //0110 delay(speedX); digitalWrite(b,LOW); //0010 delay(speedX); digitalWrite(d,HIGH); //0011 delay(speedX);
digitalWrite(c,LOW); //0001 delay(speedX); digitalWrite(a,HIGH); //1001 delay(speedX); digitalWrite(d,LOW); //1000 end }}
void motorR (int openPin){ if(openPin == 1){ digitalWrite(d,HIGH); //0001 start delay(speedX); digitalWrite(c,HIGH); //0011 delay(speedX); digitalWrite(d,LOW); //0010 delay(speedX); digitalWrite(b,HIGH); //0110 delay(speedX); digitalWrite(c,LOW); //0100 delay(speedX); digitalWrite(a,HIGH); //1100 delay(speedX); digitalWrite(b,LOW); //1000 delay(speedX); digitalWrite(d,HIGH); //1001 delay(speedX); digitalWrite(a,LOW); //0001 end }}
void defualtM(){ digitalWrite(a,LOW); digitalWrite(b,LOW); digitalWrite(c,LOW); digitalWrite(d,LOW);}
int openPin(int pinNum){ int iTimer = 0; float addCheck = 0; int pin = 0; for(iTimer = 0; iTimer <= 9; iTimer +=1){ pin = digitalRead(pinNum); addCheck = addCheck + pin; delay(1); }
Serial.print("addCheck: "); Serial.println(addCheck); addCheck = addCheck / 10; if(addCheck < 1){ return 0; } else{ return 1; }}
//Yun Code\\#include <Bridge.h>#include <BridgeServer.h>#include <BridgeClient.h>
BridgeServer server;//(Note all time values are dependent of the Nano's time values, syncing is VERY important)int counterV = 100; //Default counter value 1/10 secondint maxC = 17000; //Value set for gate max close and open|||||| maxC/counterV = realtime
int oPin = 2; //Digital Pin for Yun (open)int rOPin = 0; //Read from (open)int cPos = counterV; //How the system counts while openingint posMax = maxC; //Gate opens for, should be equal to |negMax|int countOpen = 0; //Stores the temp value count for openMaxint numOpen = counterV; //How the system counts hold openint openMax = maxC/3; //Gate stays up forint gateOpen = 0; //Flag that detects and communicates when the gate needs to stay open
int cPin = 4; //Digital Pin for Yun (close)int rCPin = 0; //Read from (close)int cNeg = -counterV; //How the system counts while closing(always -)int negMax = -maxC; //Max value of close position(always -)
int countTot = negMax; //Default value to stay at if no processes are going on
int testNum = 0; //Test
void setup() { // Bridge startup pinMode(oPin, OUTPUT); pinMode(cPin, OUTPUT); Bridge.begin();
server.listenOnLocalhost();
server.begin(); Serial.begin(9600);}
void loop() { BridgeClient client = server.accept(); if (client) { process(client); client.stop(); } rOPin = digitalRead(oPin); rCPin = digitalRead(cPin); OpenOrClose(rOPin,rCPin); countO(); countC(); defaultGate(); delay(counterV); // Poll every 100ms}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void countO() { //(X) if(rOPin == 1 && rCPin == 0){ if(countTot < posMax){ countTot = countTot + cPos; } else{ gateOpen = 1; digitalWrite(oPin,LOW); } } if(gateOpen == 1 && countTot == posMax){ if(countOpen < openMax){ countOpen = countOpen + numOpen; } else{ digitalWrite(cPin,HIGH); gateOpen = 0; } }}
void countC() { //Motor will still rotate if input is sent again(?)
if(rOPin == 0 && rCPin == 1){ if(countTot > negMax){ //negMax countTot = countTot + cNeg; //cNeg } else{ digitalWrite(cPin,LOW); countOpen = 0; } }}
void OpenOrClose(int rOPin, int rCPin) { //(X) if(rOPin == 1 && rCPin == 1){ digitalWrite(oPin,0); digitalWrite(cPin,0); }}
void defaultGate(){ //(X) if(countTot != negMax && rOPin == 0 && rCPin == 0 && gateOpen == 0){ digitalWrite(cPin,HIGH); countC(); }}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void process(BridgeClient client) { // read the command String command = client.readStringUntil('/');
// is "digital" command? if (command == "digital") { digitalCommand(client); }
// is "analog" command? if (command == "analog") { analogCommand(client); }
// is "mode" command? if (command == "mode") { modeCommand(client); }
}
void digitalCommand(BridgeClient client) { int pin, value;
// Read pin number pin = client.parseInt();
// If the next character is a '/' it means we have an URL // with a value like: "/digital/13/1" if (client.read() == '/') { value = client.parseInt(); digitalWrite(pin, value); } else { value = digitalRead(pin); }
// Send feedback to client client.print(F("Pin D")); client.print(pin); client.print(F(" set to ")); client.println(value);
// Update datastore key with the current pin value String key = "D"; key += pin; Bridge.put(key, String(value));}
void analogCommand(BridgeClient client) { int pin, value;
// Read pin number pin = client.parseInt();
// If the next character is a '/' it means we have an URL // with a value like: "/analog/5/120" if (client.read() == '/') { // Read value and execute command value = client.parseInt(); analogWrite(pin, value);
// Send feedback to client client.print(F("Pin D")); client.print(pin); client.print(F(" set to analog "));
client.println(value);
// Update datastore key with the current pin value String key = "D"; key += pin; Bridge.put(key, String(value)); } else { // Read analog pin value = analogRead(pin);
// Send feedback to client client.print(F("Pin A")); client.print(pin); client.print(F(" reads analog ")); client.println(value);
// Update datastore key with the current pin value String key = "A"; key += pin; Bridge.put(key, String(value)); }}
void modeCommand(BridgeClient client) { int pin;
// Read pin number pin = client.parseInt();
// If the next character is not a '/' we have a malformed URL if (client.read() != '/') { client.println(F("error")); return; }
String mode = client.readStringUntil('\r');
if (mode == "input") { pinMode(pin, INPUT); // Send feedback to client client.print(F("Pin D")); client.print(pin); client.print(F(" configured as INPUT!")); return; }
if (mode == "output") { pinMode(pin, OUTPUT); // Send feedback to client client.print(F("Pin D")); client.print(pin); client.print(F(" configured as OUTPUT!")); return; }
client.print(F("error: invalid mode ")); client.print(mode);}