Introduction: Smart Door 4.0 (Door.0)

For this instructable we used a Digilent chipKit Max32, a 6.1V zener diode, a vibration sensor, a bluetooth wireless module, a micro servo, and 2 100Ohm resistors. The vibration sensor can have a maximum supply voltage of 70V which is much higher than the allowable amount for the chipKit that we are using. To restrict this voltage to little more than 5V max, we connect the circuit above with a 6.1V zener diode and 200Ohm resistor instead of the 5.1 and 220 in the image. After constructing this circuit, we connected it to the Max32 with the out pin connected to analog pin 1.

We then implemented the following MPIDE code to gather the trigger data from the sensor. The way this code works is that we have a default voltage value, and if the analog pin 1 is above this voltage, we trigger the output to signal high. This output will stay in this high signal for a given amount of time to filter out vibrations from the sensor. The second output is a trigger to signal if the door is open. It is high when it receives one signal, then is low when it receives the signal again.

Step 1: Code to Connect the MAX32 to a Webpage

The first bit of code to connect this circuit to a website is the following python file. This takes the data from a serial input and manipulates the data to output values based on expected conditions. The second bit of code for the website was the javascript code to set up the private webpage. This is in the second image. The result of this code is outputting if the door is open, or closed, how long it has been open, and the maximum time that it has been open. There is also a graph that is outputted with this code. This was a graph of the data from the door sensor over time. This graph does not work properly at the moment as both the code above and the graph code requires the data from the serial input.

Step 2: Issues With Hosting the Server

To properly load the server for your own local space, you need to have a .html file named index in your folder C:\inetpub\wwwroot. This will be the default hosted html file when you look up your ip on a webpage. To allow other users on the same wifi as you to view your webpage, you need to disable the public firewalls on your computer. This can be done by looking up "windows firewall" in the search bar and disabling the public one. Once your index.html is created, find what your ip is by going to windows search bar, typing "cmd", then typing "ipconfig". Your ip will be located after iPV4 and starts with 192.168. When other users on the same router type this address into their search engine it should route them to your webpage which is running your index.html.

Step 3:

Here is the mpide code for the bluetooth-cellphone app interface and data output:

#include
#include

//softserial defines

#define rxPin 15

#define txPin 16

#define ledPin 13

char psw1 = 'O';

char psw2 = 'O';

int stat = 0;

int count = 0;

//servo defines

#define servoPin 9

#define openVal 90

#define closeVal 0

//door sensor defines

#define sensorPin 1

#define threshold 1000

//status led define

#define ledPin 4

//Servo stuff Servo DoorServo;

//door state stuff

boolean lockState = true;

boolean doorState = false;

boolean doorSensor = false;

//door measurement stuff int measurement = 0;

//software serial stuff

SoftwareSerial BT_Serial = SoftwareSerial(rxPin, txPin);

char buffchar = 'A';

void setup()

{ //set software serial pin modes

pinMode(rxPin, INPUT);

pinMode(txPin, OUTPUT);

//setup hardware serial port

Serial1.begin(9600);

Serial.begin(9600);

// set the data rate for the SoftwareSerial port

//servo setup

DoorServo.attach (servoPin);

//door indicator led setup

pinMode(ledPin, OUTPUT); }

void getdata()

{ while (Serial1.available() > 0)

{ buffchar = Serial1.read();

return;

}

}

void loop()

{ //wait for open command

// read from serial port

//Serial.println(buffchar);

while (buffchar!='O')

{

buffchar = Serial1.read();

}

buffchar = 'A';

Serial1.print("Door is unlocked!\n");

lockState = false;

//unlock the door DoorServo.write(openVal);

//wait for door to open

while (doorState == false)

{

measurement = analogRead (sensorPin);

if (measurement > threshold)

{

doorState = true;

digitalWrite (ledPin, HIGH);

}

}

buffchar = 'A';

delay (500);

//wait for door to close

while (doorState == true)

{ stat = '1';

measurement = analogRead (sensorPin);

count++;

if (count == 210000)

{ Serial.write(stat);

count=0;

}

if (measurement > threshold)

{

doorState = false;

Serial1.print("Door is locked!\n");

stat = ('0');

Serial.write(stat);

digitalWrite (ledPin, LOW);

}

}

delay(500);

//lock door

DoorServo.write(closeVal);

buffchar = 'A';

}