Tuesday, 4 October 2016

Automatic Room Temperature Controlled System

Source Code:

/****************************************************/

#include<AT89x51.h>
#define MYDATA  P3
#define ldata P1

/* here using macros that defines the temperature limits */

#define FL3i 35  /*Defining set of constants for the temperature limits*/
#define FL2ii 35  /*This approach makes changing the temperature limits very easy*/
#define FL2i 30  /*This prevents from going deeper into the code.*/
#define FL1ii 30
#define FL1i 25
#define NLii 25
#define NLi 20
#define HL1i 20
#define HL1ii 10
#define HL2i 10
#define HL2ii 00

sbit rd=P2^5;  /*Configuring P2.5 with identifier rd,Function:To send read command to ADC*/
sbit wr=P2^4;  /*Configuring P2.4 with identifier wr,Function:To send write command to ADC*/
sbit INTR=P2^3;  /*Configuring P2.3 with identifier INTR,Function:To detect start and end of conversion by ADC*/
sbit rs=P2^0;  /*Configuring P2.0 to give a value to RS register of LCD*/
sbit rw=P2^1;  /*Configuring P2.1 to give a value to RW register of LCD*/
sbit en=P2^2;  /*Configuring P2.2 to give a value to EN register of LCD*/
sbit MTR=P2^6;  /*Configuring P2.6 to give a Pulse width modulated signal to Motor Control Circuitry*/
sbit HTR1=P0^0;  /*Configuring P0.0 as a output line for led which is used as prototype model for heater*/
sbit HTR2=P0^1;  /*Configuring P0.0 as a output line for led which is used as prototype model for heater*/
sbit busy=P1^7;  /*Configuring P1.7,8th bit of ldata or P1 with identifier busy,Function:To know whether */

/*Following are set of functions required by the main routine.
  It is to be noted that function protoype are not used.
  Instead functions are directly implemented along with their definitions.
  While doing so proper function ordering should be made otherwise compiler
  will generate error.For example:Most of the functions in program calls msDelay() function
  ,and if msDealy() function is kept below the one calling it,compiler will generate error.*/

void msDelay(unsigned int value){ /*Provides delay in Miliseconds equal to the argument provided.Note that the choice of loop parameter 1275 is
                                   completely determined by the inernal design of Compiler and may vary from Compiler to Compiler.*/
unsigned int x,y;
for(x=0;x<value;x++)
    for(y=0;y<1275;y++);  /*; is kept because second for loop is written as a single line statement*/
}

void lcdReady(){  /*Checks if LCD controller is busy or not and waits till not busy if it is busy*/
busy=1;
rs=0;
rw=1;
while(busy==1)
{
en=0;
en=1;
}
return;
}

void lcdCmd(unsigned char value){ /*Gives command to LCD*/
lcdReady();/*Calls to check for busy flag*/
ldata=value;
rs=0;
rw=0;/*To appreciate why these values are enforced,one needs to have basic understanding*/
en=1;/*of LCD controller internal operations for read,write etc.*/
en=0;
return;
}


void lcdInit(){ /*Initializes LCD.Whenever initialization is necessary this function is called.*/
lcdCmd(0x38);
lcdCmd(0x0c);
lcdCmd(0x01);
lcdCmd(0x80);
return;
}

void lcdData(char value){ /*To give data to LCD controller for display.*/
ldata=value;
rs=1;
rw=0;
en=1;
en=0;
return;
}

void display(char d1,char d2){
  lcdData(d2);
msDelay(30);
msDelay(30);
lcdData(d1);
msDelay(30);
msDelay(' ');
msDelay(30);
lcdData('C');
}



void convert(char value){/*Converts data from binary to ASCII code.*/
    char y,d1,d2,d3;
y=value/10;
d1=value%10;
d2=y%10;
d3=y/10;
d1=d1|0x30;
d2=d2|0x30;
d3=d3|0x30;
display(d1,d2);/*d3 will be needed only if temperature exceeds 100 degree celcius.
                         If needed it can be added in this call and in function definition
                         as well as body of display().Here it is not included so as to
                         eliminate redundant digit in the display.*/
 }

 void update(char value){/*Updates the data in lcd if data is changed and is within the range.*/
 char y,d1,d2,d3;     /*Other method would also apply to update data*/
y=value/10;      /*But I thought this to be the easy and elegant approach.*/
d1=value%10;
d2=y%10;
d3=y/10;
d1=d1|0x30;
d2=d2|0x30;
d3=d3|0x30;
lcdData(d2);
msDelay(30);
msDelay(30);
lcdData(d1);
msDelay(30);
lcdCmd(0xc0);
 }

char adcRead()
{
/*Reads data from ADC and returns a value in binary format.*/
char value;
wr=0;/*Gives LO-HI pulse to ADC to Start the conversion process.*/
wr=1;
while(INTR==1);/*Waits till data has been converted by ADC.*/
rd=0;/*Gives LO-HI pulse to ADC to read the data converted by ADC*/
value=MYDATA;/*Receiving the converted data into the port 3 of uC*/
rd=1;/*End of LO-HI transition.*/
return value;
  }

void motorcontrol(){
         unsigned char i;
unsigned char value;
unsigned char x[6]="TEMPR:";/*This Section consists Set of Strings defined for purpose of display in LCD*/
unsigned char x1[5]="FANON";/*TEMPR: means Temperature,HTRON means Heater On*/
unsigned char x2[5]="HTRON";/*HTRON meansHeater on.*/
unsigned char y[12]="SPEED:LEVEL";
unsigned char z[11]="HEAT:LEVEL";
unsigned char u1[5]="NORM.";/*NORM. means Normal.*/
unsigned char u2[11]="FAN,HTR OFF";/*FAN,HTR OFF means FAN and Heater both off.*/

while(1){  /*Infinite loop is made because of the absence of Operating System.
            Because there is no operating system to return to*/
value=adcRead(); /*read data from adc*/
    if(value<20){ /*Heater on logic ,confirms to turn on the heater*/
     lcdCmd(0x01);   /*clear display*/
for(i=0;i<6;i++) /*display string TEMPR: */
     {
     msDelay(50);
     lcdData(x[i]);
     }
convert(value); /*convert data and display*/
lcdCmd(0x8b);
for(i=0;i<5;i++){ /*display HTRON message*/
msDelay(30);
lcdData(x2[i]);
}

     while(value>HL1ii && value<HL1i){ /*level 1 heat for heater*/
       MTR=1;
  HTR2=1;
  HTR1=0;
  msDelay(1);
  z[10]='1';
  lcdCmd(0xc0);
  for(i=0;i<11;i++){
   msDelay(30);
   lcdData(z[i]);
   }
  bkl5:
  value=adcRead();
  if(value>HL1ii && value<HL1i){
   lcdCmd(0x86);
   update(value);
  goto bkl5;
  }
  else
  break;
  } /*While closed*/

    while(value>=HL2ii && value<=HL2i){ /*level 2 heat for heater*/
      MTR=1;
 HTR1=0;
 msDelay(30);
 HTR2=0;
 msDelay(1);
 lcdCmd(0xc0);
 z[10]='2';
 for(i=0;i<11;i++){
   msDelay(30);
   lcdData(z[i]);
   }
 bkl6:
 value=adcRead();
 if(value>=HL2ii && value<=HL2i){
   lcdCmd(0x86);
   update(value);
   goto bkl6;
  }
 else
 break;
 } /*While closed*/


   } /*Heater on logic closed*/
 
 
   while(value>=NLi&&value<NLii){ /*Normal state logic*/
     HTR1=1;
HTR2=1;
MTR=1;
lcdCmd(0x01); /*clear display*/
for(i=0;i<6;i++){ /*display TEMPR:*/
     msDelay(50);
     lcdData(x[i]);
      }
convert(value); /*convert data and display*/
for(i=0;i<5;i++){
msDelay(30);
lcdData(u1[i]);
}
     lcdCmd(0xc0);
for(i=0;i<11;i++){
msDelay(30);
lcdData(u2[i]);
}
bklbkl:
value=adcRead();
if(value>=NLi&&value<NLii){
 lcdCmd(0x86);
 update(value);
 goto bklbkl;
 }
     else
break;
   }
 
 

if(value>=25) /*fan on logic,first confirms the situation to turn on fan*/
{
HTR1=1;
HTR2=1;
lcdCmd(0x01); /*clear display*/
for(i=0;i<6;i++) /*display TEMPR:*/
     {
     msDelay(50);
     lcdData(x[i]);
     }
convert(value); /*convert data and display*/
lcdCmd(0x8b);
for(i=0;i<5;i++)
{
msDelay(30);
lcdData(x1[i]);
}




     while(value>=FL1i && value<FL1ii){ /*level 1 speed for fan*/
 lcdCmd(0xc0);
 y[11]='1';
 for(i=0;i<12;i++){
   msDelay(30);
   lcdData(y[i]);
  }
 bkl1:
 MTR=0;
      msDelay(50);
      MTR=1;
      msDelay(50);
 value=adcRead();
 if(value>=FL1i && value<FL1ii){
 lcdCmd(0x86);
 update(value);
 goto bkl1;
 }
 else
 break;

 } /*level 1 speed logic closed*/



     while(value>=FL2i && value<FL2ii){ /*level 2 speed for fan*/
 y[11]='2';
 lcdCmd(0xc0);
 for(i=0;i<12;i++){
   msDelay(30);
   lcdData(y[i]);
  }
 bkl2:
 MTR=0;
      msDelay(75);
      MTR=1;
      msDelay(25);
      value=adcRead();
 if(value>=FL2i && value<FL2ii){
   lcdCmd(0x86);
   update(value);
   goto bkl2;
  }
 else
 break;
 } /*level 2 speed logic closed*/



while(value>=FL3i){ /*level 3 speed for fan*/
 y[11]='3';
 lcdCmd(0xc0);
 for(i=0;i<12;i++){
   msDelay(30);
   lcdData(y[i]);
  }
 bkl3:
 MTR=0;
 value=adcRead();
 if(value>=FL3i){
   lcdCmd(0x86);
   update(value);
   goto bkl3;
  }
 else
 break;
 } /*level 3 speed logic closed*/



     } /*if statement closed i.e fan on logic closed*/
   }
}

  void main(){ /*Main function starts.Execution begins from here.*/
   P0=0xff; /*Setting all pins of P0 to 1s to make it as output port in negative logic*/
   MYDATA=0xff; /*Setting all pins of P3 to 1s to make it as input port in positive logic*/
   INTR=1;/*Active low signal therefore initialized as high.*/
   rd=1;/*Active low signal therefore initialized as high.*/
   wr=1;/*Active low signal therefore initialized as high.*/
   MTR=1;/*Active low is required to drive optocoupler,so initialized as high.*/
   HTR1=0;/*To give a blink effect during a startup to show they are functioning and*/
   HTR2=0;/*leds are used as prototype for heater and are connected in active low configuration.*/
   msDelay(50);
   HTR1=1;/*After 50ms of delay Leds are turned off by high output.*/
   HTR2=1;
   lcdInit();/*Initializes LCD with appropriate Display Setting*/
   motorcontrol();/*Calls motorcontrol() subroutine*/
   } /*main function closed*/

Simulation Result


Thursday, 3 March 2016

Internet of Things Enabled Liquid Level Monitoring System

Introduction

This project IOT Liquid Level Monitoring system is a very innovative system which will inform the users about the level of liquid and will prevent it from overflowing. To demonstrate this the system makes use of 4 containers. For this the system uses ultrasonic sensors placed over the containers to detect the liquid level and compare it with the container’s depth. The system makes use of AVR family microcontroller, LCD screen, Wifi modem for sending data and a buzzer. The system is powered by a 12V transformer. The LCD screen is used to display the status of the level of liquid in the containers. Whereas a web page is built to show the status to the user monitoring it. The web page gives a graphical view of the containers and highlights the liquid level in color in order to show the level of liquid. The LCD screen shows the status of the liquid level. The system puts on the buzzer when the level of liquid collected crosses the set limit. Thus this system helps to prevent the wastage of water by informing about the liquid levels of the containers by providing graphical image of the containers via a web page.

Hardware Specifications                                                  Software Specification
  • Atmega 328 microcontroller                                   * Arduino Compiler
  • Wifi Modem                                                            * Embedded C Programming Language
  • Resistors
  • Capacitors
  • 12V transformer
  • Ultrasonic sensors
  • Diodes
  • LED’s
  • LCD Display
Project Block Diagram
  



                  


Internet of Things ( IoT ) and it's Architecture

What is Internet of Things (IoT)

The Internet of Things (IoT) is a system of interrelated computing devices, mechanical and digital machines, objects, animals or people that are provided with unique identifiers and the ability to transfer data over a network without requiring human-to-human or human-to-computer interaction. 
A thing, in the Internet of Things, can be a person with a heart monitor implant, a farm animal with a biochip transponder, an automobile that has built-in sensors to alert the driver when tire pressure is low -- or any other natural or man-made object that can be assigned an IP address and provided with the ability to transfer data over a network. 

IoT has evolved from the convergence of wireless technologies, micro-electromechanical systems (MEMS), microservices and the Internet. The convergence has helped tear down the silo walls between operational technology (OT) and information technology (IT), allowing unstructured machine-generated data to be analyzed for insights that will drive improvements.
Kevin Ashton, cofounder and executive director of the Auto-ID Center at MIT, first mentioned the Internet of Things in a presentation he made to Procter & Gamble in 1999. Here’s how Ashton explains the potential of the Internet of Things:

“Today computers -- and, therefore, the Internet -- are almost wholly dependent on human beings for information. Nearly all of the roughly 50 petabytes (a petabyte is 1,024 terabytes) of data available on the Internet were first captured and created by human beings by typing, pressing a record button, taking a digital picture or scanning a bar code. 
The problem is, people have limited time, attention and accuracy -- all of which means they are not very good at capturing data about things in the real world. If we had computers that knew everything there was to know about things -- using data they gathered without any help from us -- we would be able to track and count everything and greatly reduce waste, loss and cost. We would know when things needed replacing, repairing or recalling and whether they were fresh or past their best.”

IPv6’s huge increase in address space is an important factor in the development of the Internet of Things. According to Steve Leibson, who identifies himself as “occasional docent at the Computer History Museum,” the address space expansion means that we could “assign an IPV6 address to every atom on the surface of the earth, and still have enough addresses left to do another 100+ earths.” In other words, humans could easily assign an IP address to every "thing" on the planet. An increase in the number of smart nodes, as well as the amount of upstream data the nodes generate, is expected to raise new concerns about data privacydata sovereignty and security. 
Practical applications of IoT technology can be found in many industries today, including precision agriculturebuilding management, healthcare, energy and transportation
Although the concept wasn't named until 1999, the Internet of Things has been in development for decades. The first Internet appliance, for example, was a Coke machine at Carnegie Melon University in the early 1980s. The programmers could connect to the machine over the Internet, check the status of the machine and determine whether or not there would be a cold drink awaiting them, should they decide to make the trip down to the machine.

A Basic Architecture of IoT