Anda di halaman 1dari 15

ASSIGNMENT 7

Software Implmentation
➢ Introduction
This chapter discusses the implementation of the system. Section 7.2 provides the technical
information
about the database system, System 7.3 outlines the modular structure of the system, showing the
various
Modules Implemented to form coplete System. Section 7.4 provides an actual code which implement
in
coding phase of software development life cycle.

➢ Database used
Parallax Data Acquisition tool (PLX-DAQ) software add-in for Microsoft Excel acquires up to 26
channels of data from any Parallax microcontrollers and drops the numbers into columns as they
arrive. PLX-DAQ provides easy spreadsheet analysis of data collected in the field, laboratory analysis
of sensors and real-time equipment monitoring.
There are several ways to save data from a sensor attached to an Arduino. If you’re connected to
a personal computer, you can simply send the data from the Arduino to the personal computer
serially, and save it to a file. If you’ve got an SD card attached to the microcontroller, you can
save the data to the card. Or, if you have access to the internet and a device that can connect to
a server, you can save the data to a server. In the tutorial below, you’ll read a DHT11
temperature and humidity sensor and log data
It features calculation, graphing tools, pivot tables, and a macro programming language
called Visual Basic for Applications. It has been a very widely applied spreadsheet for these
platforms
➢ Important Modules And Algorithm
The important module and algorithm used in project are as follows.
Registration Module
This module is usedfor registration of customer. Admin user is allready present in the system. For
more secure login MD-5 hash algorithm is used to calculated hash value for password. Using these
hash values login authentication is provided.

➢ Algorithm Used
MD5 Hash algorithm:
The MD5 message-digest algorithm is a widely used hash function producing a 128-bit hash value.
Although MD5 was initially designed to be used as a cryptographic hash function, it has been found
to suffer from extensive vulnerabilities. It can still be used as a checksum to verify data integrity, but
only against unintentional corruption. It remains suitable for other non-cryptographic purposes, for
example for determining the partition for a particular key in a partitioned database.

One basic requirement of any cryptographic hash function is that it should be computationally
infeasible to find two distinct messages which hash to the same value. MD5 fails this requirement
catastrophically; such collisions can be found in seconds on an ordinary home computer.
Input: Arbitrary Length Message(Password)
Output: 128 bit Message Digest for input.
Steps - It operates as follows
1. Take User password as input to calculate Message Digest for it.
2. Input Message is broken up into chunks of 512 bits blocks (16 - 32 bits words).
3.Append Padding bits. (Message is padded , so that its length (in bits) become compatible to 448 ,
module 512 bits.) Padding A single 1 is appended, and then 0 bits are appended , and then 0 bits are
appended, so that the length in bits of padded message becomes to 448, modulo 512.
4.Append Length: A 64 bit representation of b(Message length) is appended to the result of previous
step.
At this point the resulting Message has a length exact multiple of 512 bits.
5.Initialize MD Buffers: A four word buffers (A,B,C,D) are used to compute the message digest.
(A,B,C,D
6.Process Message in sixteen word blocks.
(F,G,H,I). There are 4 round , each involve 16 basic operation.
7.Message Digest is generated.

➢ Major Code
The major code of project is given below.
A. INTEGRATED CODE
int led = 13; // the pin that the LED is atteched to
int PIRsensor = 2; // the pin that the sensor is atteched to
int MOTION; // variable to store the sensor status (value)
int sensorPin1_OUTSIDE = A5; // select the input pin for LDR
int sensorPin2_INSIDE = A1;
int In1 = 7;
int In2 = 8;
int ENA = 5;
int SPEED = 255;
int MQ_PIN=A0;
int voltagef=0;
int voltage1=0;

//--------FAN VARIABLES

int In1f =11;


int In2f = 10;
int ENAf = 12;
int SPEEDf = 255;

int temp=A3;
int temperature=0;
int MQCalibration(MQ_PIN);

int sensorValue1_OUTSIDE = 0; // variable to store the value coming from the sensor
int sensorValue2_INSIDE = 0;
int voltage=0;

//-----------------------------------------------------------------------------
void setup() {
pinMode(led, OUTPUT); // initalize LED as an output
pinMode(PIRsensor, INPUT); // initialize sensor as an input
pinMode(In1, OUTPUT);
pinMode(In2, OUTPUT);
pinMode(ENA, OUTPUT);
pinMode(In1f, OUTPUT);
pinMode(In2f, OUTPUT);
pinMode(ENA, OUTPUT);
Serial.begin(9600);
Serial.println("CLEARDATA");
Serial.println("LABEL,Date,Computer Time,MOTION SENSED,BULB
VOLTAGE(mv),TEMPRETURE VALUE,FAN VOLTAGE(mv),MOTION STATUS");
delay(2000);
//Serial.begin(9600); //UART setup, baudrate = 9600bps

//-----------------------------------------------------------------------------

void loop() {
MOTION=0;
sensorValue1_OUTSIDE = analogRead(sensorPin1_OUTSIDE); // read the value from the sensor
LDR
sensorValue2_INSIDE = analogRead(sensorPin2_INSIDE); // read the value from the sensor LDR
MOTION = digitalRead(PIRsensor); // read sensor valueU
//------------------------------------------

if (MOTION == HIGH) // check if the sensor is HIGH PIR SENSOR


{
Serial.print("Motion Detected");

if (sensorValue1_OUTSIDE > sensorValue2_INSIDE)


{
//CURTAINS OPEN
//Serial.print(MOTION);
//Serial.print(sensorValue1_OUTSIDE);

//motor code

digitalWrite(In1, HIGH);
digitalWrite(In2,LOW);
analogWrite(ENA, SPEED);
delay(1000);
// Serial.println("Outside light is High");

digitalWrite(led, LOW);
delay(2000);

digitalWrite(In1, LOW);
digitalWrite(In2,LOW);
}
else if (sensorValue1_OUTSIDE < sensorValue2_INSIDE)

{
// Serial.print(sensorValue2_INSIDE);
// Serial.println("Inside light is High");
digitalWrite(led, LOW);

delay(3000);
digitalWrite(In1, LOW);
digitalWrite(In2,LOW);

if ((sensorValue1_OUTSIDE < 400) && (sensorValue2_INSIDE < 400))


{
digitalWrite(led, HIGH);
//delay(8000);
digitalWrite(In1, LOW);
digitalWrite(In2,LOW);

// VOLTAGE CALCULATION

int sensorValue = analogRead(13);


// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
//Serial.print("ON");

// Serial.println(voltage);
}

//----------------------------------------FAN OPERATION---------------------------------------------

temperature=analogRead(temp);
temperature=(5.0 * temperature * 100.0) / 1024;
// Serial.print("hiiiii");

//Serial.print("temperature");

//Serial.println(temperature);
if (temperature > 38)
{

digitalWrite(In1f, HIGH);
digitalWrite(In2f, LOW);
analogWrite(ENAf, SPEEDf);
int sensorValue = analogRead(In1f);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltagef = sensorValue * (5.0 / 1023.0);
int voltage1=voltagef/10;
// Serial.println(voltage);
}
else
{
digitalWrite(In1f, LOW);
digitalWrite(In2f, LOW);
analogWrite(ENAf, 0);

}
//-----------------------MQ2 SENSOR CODE-----------------------------------//
/*
else if(gas detected)
Buzzer on
*/

}
//------------------------------------MOTION NOT DETECTED--------------------------------------
if(MOTION==LOW)
{

//LIGHT OFF
digitalWrite(led, LOW);
Serial.print("Motion NOT Detected");

//FAN OFF

digitalWrite(In1f, LOW);
digitalWrite(In2f, LOW);
//analogWrite(ENAf, 0);

}
int sensorValue = analogRead(13);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltagef = sensorValue * (5.0 / 1023.0);
//Serial.print("ON");

// Serial.println(voltagef);

Serial.println("--------------------");
Serial.print("DATA,DATE,TIME," + String(MOTION) +","+ int(sensorValue2_INSIDE) +","+
int(sensorValue1_OUTSIDE) +","+ float(temperature) +","+ int(voltage1));

delay(1000);

B. MQ2 Sensor code

#define MQ_PIN (0) //define which analog input channel you are going to use
#define RL_VALUE (.01) //define the load resistance on the board, in kilo ohms
#define RO_CLEAN_AIR_FACTOR (.083) //RO_CLEAR_AIR_FACTOR=(Sensor
resistance in clean air)/RO,
//which is derived from the chart in datasheet

/**********************Software Related Macros***********************************/


#define CALIBARAION_SAMPLE_TIMES (50) //define how many samples you are going
to take in the calibration phase
#define CALIBRATION_SAMPLE_INTERVAL (500) //define the time interal(in milisecond)
between each samples in the
//cablibration phase
#define READ_SAMPLE_INTERVAL (50) //define how many samples you are going to
take in normal operation
#define READ_SAMPLE_TIMES (5) //define the time interal(in milisecond) between
each samples in
#include <LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;


LiquidCrystal lcd(rs, en, d4, d5, d6, d7); //normal operation

/*********************Application Related Macros*********************************/


#define GAS_LPG (0)
#define GAS_CO (1)
#define GAS_SMOKE (2)

/****************************Globals**********************************************/
float LPGCurve[3] = {2.3,0.21,-0.47}; //two points are taken from the curve.

//with these two points, a line is formed which is "approximately


equivalent"
//to the original curve.
//data format:{ x, y, slope}; point1: (lg200, 0.21), point2: (lg10000, -
0.59)
float COCurve[3] = {2.3,0.72,-0.34}; //two points are taken from the curve.
//with these two points, a line is formed which is "approximately
equivalent"
//to the original curve.
//data format:{ x, y, slope}; point1: (lg200, 0.72), point2: (lg10000,
0.15)
float SmokeCurve[3] ={2.3,0.53,-0.44}; //two points are taken from the curve.
//with these two points, a line is formed which is "approximately
equivalent"
//to the original curve.
//data format:{ x, y, slope}; point1: (lg200, 0.53), point2: (lg10000, -
0.22)
float Ro = 10; //Ro is initialized to 10 kilo ohms
int val = 0;
void setup()
{
Serial.begin(9600);
Serial.println("CLEARDATA");//clear excel sheet
Serial.println("LABEL,current time,TEMPRATURE");
//UART setup, baudrate = 9600bps
Serial.print("Calibrating...\n");
Ro = MQCalibration(MQ_PIN); //Calibrating the sensor. Please make sure the sensor
is in clean air
lcd.begin(16, 2); //when you perform the calibration
Serial.print("Calibration is done...\n");
Serial.print("Ro=");
Serial.print(Ro);
Serial.print("kohm");
Serial.print("\n");

void loop(){

Serial.print("DATA,TIME,");
Serial.print(",");
Serial.print("LPG:");
Serial.print(MQGetGasPercentage(MQRead(MQ_PIN)/Ro,GAS_LPG) );
Serial.print( "ppm" );
Serial.print(" ");

Serial.print(" ");
Serial.print("SMOKE:");
Serial.print(MQGetGasPercentage(MQRead(MQ_PIN)/Ro,GAS_SMOKE) );
Serial.print( "ppm" );
Serial.print("\n");

/**************** MQResistanceCalculation **************************************


Input: raw_adc - raw value read from adc, which represents the voltage
Output: the calculated sensor resistance
Remarks: The sensor and the load resistor forms a voltage divider. Given the voltage
across the load resistor and its resistance, the resistance of the sensor
could be derived.
**********************************************************************************
/
float MQResistanceCalculation(int raw_adc)
{
return ( ((float)RL_VALUE*(1023-raw_adc)/raw_adc));
}

/*************************** MQCalibration **************************************


Input: mq_pin - analog channel
Output: Ro of the sensor
Remarks: This function assumes that the sensor is in clean air. It use
MQResistanceCalculation to calculates the sensor resistance in clean air
and then divides it with RO_CLEAN_AIR_FACTOR. RO_CLEAN_AIR_FACTOR is about
10, which differs slightly between different sensors.
**********************************************************************************
/
float MQCalibration(int mq_pin)
{
int i;
float val=0;

for (i=0;i<CALIBARAION_SAMPLE_TIMES;i++) { //take multiple samples


val += MQResistanceCalculation(analogRead(mq_pin));
delay(CALIBRATION_SAMPLE_INTERVAL);
}
val = val/CALIBARAION_SAMPLE_TIMES; //calculate the average value

val = val/RO_CLEAN_AIR_FACTOR; //divided by RO_CLEAN_AIR_FACTOR


yields the Ro
//according to the chart in the datasheet

return val;
}
/*************************** MQRead *******************************************
Input: mq_pin - analog channel
Output: Rs of the sensor
Remarks: This function use MQResistanceCalculation to caculate the sensor resistenc (Rs).
The Rs changes as the sensor is in the different consentration of the target
gas. The sample times and the time interval between samples could be configured
by changing the definition of the macros.
**********************************************************************************
/
float MQRead(int mq_pin)
{
int i;
float rs=0;
for (i=0;i<READ_SAMPLE_TIMES;i++) {
rs += MQResistanceCalculation(analogRead(mq_pin));
delay(READ_SAMPLE_INTERVAL);
}

rs = rs/READ_SAMPLE_TIMES;

return rs;
}

/*************************** MQGetGasPercentage ********************************


Input: rs_ro_ratio - Rs divided by Ro
gas_id - target gas type
Output: ppm of the target gas
Remarks: This function passes different curves to the MQGetPercentage function which
calculates the ppm (parts per million) of the target gas.
**********************************************************************************
/
int MQGetGasPercentage(float rs_ro_ratio, int gas_id)
{
if ( gas_id == GAS_LPG ) {
return MQGetPercentage(rs_ro_ratio,LPGCurve);
} else if ( gas_id == GAS_CO ) {
return MQGetPercentage(rs_ro_ratio,COCurve);
} else if ( gas_id == GAS_SMOKE ) {
return MQGetPercentage(rs_ro_ratio,SmokeCurve);
}

return 0;
}

/*************************** MQGetPercentage ********************************


Input: rs_ro_ratio - Rs divided by Ro
pcurve - pointer to the curve of the target gas
Output: ppm of the target gas
Remarks: By using the slope and a point of the line. The x(logarithmic value of ppm)
of the line could be derived if y(rs_ro_ratio) is provided. As it is a
logarithmic coordinate, power of 10 is used to convert the result to non-logarithmic
value.
**********************************************************************************
/
int MQGetPercentage(float rs_ro_ratio, float *pcurve)
{
return (pow(10,( ((log(rs_ro_ratio)-pcurve[1])/pcurve[2]) + pcurve[0])));

Anda mungkin juga menyukai