Home-automation-project

From skinetwork

Jump to: navigation, search

Contents

[edit] Abstract

Got a PC? Busy with your work and coding the programs? Had to disturb yourself in switching your devices? Needless to say, these are very much annoying. This very moment we Welcome you to the Automation World. Make your home Automated using your PC, a simple Interfacing Circuit and some Sensors.

Our aim is to provide with a module and a software package when installed in a computer, one can remotely monitor and control household devices, provide security to home what we call here as Security System, have devices turn On or Off listening to the voice commands and make home automated.

With the implementation of Electronics and Instrumentation concepts, conditioning a signal effectively from various sensors has become quite an easy task. Now interfacing this signal using an ADC with the parallel port of a computer satisfies the very goal of Automation. The user friendliness and reliability in using a PC further adds to the efficiency of the Automation System.

The basic considerations for our Automation project are:

1. 'Automatic Switching of Lights based on the measurement of Light Intensity.

2. 'Automatic Switching of devices such as AC and Room Heater based on the measurement of the temperature conditions in the house.

3. 'The Security System based on the detection of human presence in some specific regions around the house at night.

4. 'Switching devices listening to the voice commands through a microphone arranged in the house.

This whole Automation System runs in the background once your PC is kept on. This paper gives the blue print of the proceedings in accomplishing and effectuating our project, “PC BASED HOME AUTOMATION SYSTEM”.

HARDWARE SECTION:

This section is further divided into three sections:

1. Instrumentation Section: Different sensors used and sensing circuitry is discussed.

2. Parallel Port Hardware Section: The structure and behavior of the parallel port (LPT1: Line Printer) is discussed.

3. Interface and Digital Circuitry Section: The interfacing circuit and the digital logics for outputting and inputting are discussed.

I. 'INSTRUMENTATION SECTION:'

As the basic requirement for Automation is sensing circuitry, this section starts with the sensors used and the signal conditioning circuitry required. The hardware and circuitry needed for the four Automation tasks mentioned are discussed here:

1. LDR (Light Dependent Resistor):

For Automatic Switching of lights the Intensity of the light should be measured. This can be achieved using LDR, which is a semiconductor device whose resistance decreases as light intensity increases. This is due to the electrons and holes produced in a semiconductor by the photoelectric effect, and the response is therefore quite linear.

Image:Clip image002.jpg

Fig1: The LDR block with equivalent voltage appearing at IN0

Considering the circuit in fig1 a resistance of 10k is placed in parallel to the resistance of the LDR. As the maximum supply voltage is 5v, the IN0 voltage line falls below the Vcc and varies with the variation in the intensity of light.

Typically, the IN0 line results about 4.3V in sunlight and increases to 4.95V in dark. This change in the voltage is measured and the output light is switched when the voltage recorded exceeds the threshold value of 4.9V and is switched off when it falls below this threshold value.

2. LM35 (Precision Centigrade Temperature Sensor):

For Automatic switching of AC or Room Heater the temperature in the room is to be monitored and the sensor used for this purpose is LM35 Precision Centigrade Temperature Sensor.

General Description of LM35:

The LM35 series are precision integrated-circuit temperature sensors, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 thus has an advantage over linear temperature sensors calibrated in ° Kelvin, as the user is not required to subtract a large constant voltage from its output to obtain convenient Centigrade scaling. The LM35 does not require any external calibration or trimming to provide typical accuracies of ±1/4°C at room temperature and ±3/4°C over a full -55 to +150°C temperature range. Low cost is assured by trimming and calibration at the wafer level. The LM35’s low output impedance, linear output, and precise inherent calibration make interfacing to readout or control circuitry especially easy. It can be used with single power supplies, or with plus and minus supplies. As it draws only 60 µA from its supply, it has very low self-heating, less than 0.1°C in still air. The LM35 we are using is rated to operate over a 0° to +100°C temperature range and is LM35DT package, while the packages such as LM35C is also available which is rated for a -40° to +110°C range.

Image:Clip image004.jpg

       Fig 2:

Output = 10 mV/°C.

                For a full scale of 100°C the maximum 
                 output voltage range is 0V to 1V.                                                                                             

Features:

· Calibrated directly in ° Celsius (Centigrade)

· Linear + 10.0 mV/°C scale factor

· 0.5°C accuracy guarantee able (at +25°C)

· Rated for full -55° to +150°C range

· Suitable for remote applications

· Low cost due to wafer-level trimming

· Operates from 4 to 30 volts

· Less than 60 µA current drain

· Low self-heating, 0.08°C in still air

· Nonlinearity only ±1/4°C typical

· Low impedance output, 0.1 for 1 mA load

Image:Clip image006.jpg

Image:Clip image008.jpg

Fig3: The LM35 with the amp. Ckt with o/p Vol. appearing at IN1

As the maximum supply voltage in the circuit is 5V, in order to improve accuracy, the output voltage is amplified with a gain factor of 5. By this the the range of temperatures can be obtained as 0 to 100°C on a scale of 0 to 5V with the new scale factor of 50.0mV/°C. The chosen threshold temperature is 40°C which when exceeds a signal is sent for switching the AC. This temperature corresponds to a voltage of 2V, which is recorded at the IN1 voltage line.

3. OBT 500-18GM70 (Reflective Type IR Sensor):

The main idea behind using an IR Sensor is to detect a human at various locations around the house and use it the way as is needed, indicate if anyone has come to home, welcome the people when they arrive at the door, rescue from the larcenists at night, which founds to be more demanding and the installation of the IR Sensor for this purpose as a Automation task is known to be the “Security System”.

From various types of IR sensors, the main aim being detecting the wavelength of human body, which is around 8 to 10 mm, the best sensor usually used is PIR 325, which needs an external circuitry, and also a Fresnel lens, which is to be mounted at an angle of 95°. For Automation Project this will be working out very fine but implementing this PIR 325 will be another good project and because of these constraints this is replaced by a Reflective Type IR Sensor called OBT500-18GM70 by Pepperl and Fuchs Group.

Image:Clip image010.jpg'

· Sensing range up to 500 mm

· Light/dark ON, programmable

· Strong metallic housing in cylindricalshape M18 x 1

· Sensitivity adjuster for optimal adaptation to the application

· LED indicating for a simple operation start

Fig 4: OBT500-18GM70 IR Sensor.

Image:Clip image012.jpg

Fig 5: Electrical Connections for OBT500

Principle: The OBT500 supply voltage range from 5V to 24V. Typically, there will be a const voltage appearing at the load and whenever there is a detection of 500mm range wavelength then there will be change in the output of about 1V. Now to restrict the output voltage to 5V a 4.7V Zener is used as shown in the above fig. which now limit to a change of .6V from a constant voltage of 4.2V before any detection. These voltages are recorded at the IN2 voltage line and any change in voltage at IN2 will switch the alarm. (Software is discussed in the further pages).

Image:Clip image014.jpgFig 6.

Technical Information of OBT500:

Detection range 0 ... 500 mm

Reference target Standard white 200 mm x 200 mm

Adjustment range 5 ... 500 mm

Light type IR-light 940 nm

Ambient light limit <= 10000 Lux sun light

<= 3000 Lux halogen light

Standard conformity EN 60947-5-2

Function display LED yellow: switching state

Controls sensitivity adjuster

No-load supply current 20 mA

Time delay before availability 50 ms

Switching type Light/dark ON, programmable

Voltage drop 2.5 V

Switching frequency 300 Hz

Switch-on delay 1.5 ms

Range hysteresis 10 %

Ambient temperature -25 ... +55

Storage temperature -40 ... +70

Protection degree IP67 according to EN 60529

Connection type Connector M12 x 1

2 m cable, 3 x 0.34 mm², PVC

Housing brass, nickel plated

Light exit PC

Mass 45 g

'4. 'Microphone:

Forget switching of devices manually. Just speak and let the things be done. Here Microphone is used for inputting the voice commands. There is no special hardware required for switching devices listening to the voice commands. The software is developed such that when the command “On” is received then the corresponding output device is kept on and on the same lines when the string is recognized as “Off” the device is kept off and listening to the “Stop” command stops and exits the Home Automation (Room Engine). The procedure and subroutines for recognition of voice is discussed in detail in the Software Section.

This completes the Instrumentation Section.

II. PARALLEL PORT HARDWARE SECTION:

Parallel Port is the gateway between the PC and the hardware circuitry.

Introduction to Parallel Ports:

The Parallel Port is the most commonly used port for interfacing home made projects. This port will allow the input of up to 9 bits or the output of 12 bits at any one given time, thus requiring minimal external circuitry to implement many simpler tasks. The port is composed of 4 control lines, 5 status lines and 8 data lines. It's found commonly on the back of PC as a D-Type 25 Pin female connector.

Newer Parallel Port’s are standardized under the IEEE 1284 standard first released in 1994. This standard defines 5 modes of operation, which are as follows,

1. Compatibility Mode.

2. Nibble Mode.

3. Byte Mode.

4. EPP Mode (Enhanced Parallel Port).

5. ECP Mode (Enhanced Capabilities Mode).

The aim was to design new drivers and devices, which were compatible with each other and also backwards compatible with the Standard Parallel Port (SPP). Compatibility, Nibble & Byte modes use just the standard hardware available on the original Parallel Port cards while EPP & ECP modes require additional hardware, which can run at faster speeds, while still being downwards compatible with the Standard Parallel Port.

For Automation Project Standard Parallel Port in Nibble Mode is used. This requires no additional hardware for the functionality of inputting and outputting unlike EPP and ECP Modes. Using SPP in Bi-directional Mode is also another option but as since we are only manipulating four variables in our Automation, SPP will be quite sufficient.

Also compatibility mode or "Centronics Mode" as it is commonly known, can only send data in the forward direction at a typical speed of 50 kbytes per second but can be as high as 150+ kbytes a second. In order to receive data, you must change the mode to either Nibble or Byte mode. Nibble mode can input a nibble (4 bits) in the reverse direction. E.g. from device to computer. Byte mode uses the Parallel's bi-directional feature (found only on some cards) to input a byte (8 bits) of data in the reverse direction.

Below is a table of the "Pin Outs" of the D-Type 25 Pin connector and the Centronics 34 Pin connector (defined for printers). The D-Type 25 pin connector is the most common connector found on the Parallel Port of the computer, while the Centronics Connector is commonly found on printers. The IEEE 1284 standard specifies 1284 Type A is the D-Type 25 connector found on the back of most computers.

This project is no way concerned with the Centronics, it is only defined for the printer. The pin structure found on parallel port is connected to the hardware through a 25 pin D-Type Male to Male connetor.

Image:Clip image016.jpg

The above table uses "n" in front of the signal name to denote that the signal is active low. The "Hardware Inverted" means the signal is inverted by the Parallel card's hardware. Such an example is the Busy line. If +5v (Logic 1) was applied to this pin and the status register read, it would return back a 0 in Bit 7 of the Status Register.

The output of the Parallel Port is normally TTL logic levels. The voltage levels are the easy part. The current you can sink and source varies from port to port. Most Parallel Ports implemented in ASIC, can sink and source around 12mA. However these are just some of the figures taken from Data sheets, Sink/Source 6mA, Source 12mA/Sink 20mA, Sink 16mA/Source 4mA, Sink/Source 12mA. As you can see they vary quite a bit. The best bet is to use a buffer, so the least current is drawn from the Parallel Port. (Note 1: The buffer interface part will be discussed further).

Software Registers in SPP Mode:

Image:Clip image018.jpgData Port

The base address, usually called the Data Port or Data Register is simply used for outputting data on the Parallel Port's data lines (Pins 2-9). This register is normally a write only port. If you read from the port, you should get the last byte sent. However if your port is bi-directional, you can receive data on this address. See Bi-directional Ports for more detail.

Image:Clip image020.jpgStatus Port

The Status Port (base address + 1) is a read only port. Any data written to this port will be ignored. The Status Port is made up of 5 input lines (Pins 10,11,12,13 & 15), an IRQ status register and two reserved bits. Please note that Bit 7 (Busy) is an active low input. E.g. if bit 7 happens to show logic 0, this means that there is +5v at pin 11.

Image:Clip image022.jpgControl Port

The Control Port (base address + 2) was intended as a write only port. When a printer is attached to the Parallel Port, four "controls" are used. These are Strobe, Auto Linefeed, Initialize and Select Printer, all of which are inverted except Initialize.

However these four outputs can also be used for inputs. If the computer has placed a pin high (e.g. +5v) and your device wanted to take it low, you would effectively short out the port, causing a conflict on that pin. Therefore these lines are "open collector" outputs (or open drain for CMOS devices). This means that it has two states. A low state (0v) and a high impedance state (open circuit). Normally the Printer Card will have internal pull-up resistors but not all will. Some may just have open collector outputs, while others may even have normal totem pole outputs. In order to make our device work correctly on as many Printer Ports as possible, an external resistor as well can be used. If there is an internal resistor already, then it will act in Parallel with it, or if you have Totem pole outputs, the resistor will act as a load.

An external 4.7k resistor can be used to pull the pin high. Using anything lower, just in case there is an internal pull up resistor, as the external resistor would act in parallel giving effectively, a lower value pull up resistor. When in high impedance state the pin on the Parallel Port is high (+5v). When in this state, our external device can pull the pin low and have the control port change read a different value. This way the 4 pins of the Control Port can be used for bi-directional data transfer. Also the Control Port must be set to xxxx0100 to be able to read data, that is all pins to be +5v at the port so that you can pull it down to GND (logic 0).

Bits 4 & 5 are internal controls. Bit four will enable the IRQ (See Using the Parallel Ports IRQ) and Bit 5 will enable the bi-directional port meaning that you can input 8 bits using (DATA0-7). This mode is only possible if your card supports it. Bits 6 & 7 are reserved. Any writes to these two bits will be ignored.

However in this project the control port pins are not used as inputst as inputs but for extending project for more outputs and inputs then this will be useful and therefore this contributes only to the further scope of the project.

Therefore, here is the summary of the ports and bits we use:

  • 8 output pins accessed via the DATA Port
  • 5 input pins (one inverted) accessed via the STATUS Port

Now that there are only 5 input pins, for inputting 8-bit digital word parallel port is operated in Nibble Mode.

The three port addresses as follows:

         Port                               Decimal Address

1. Data Port 888

2. Status Port 889

3. Control Port 890

The software instructions are used to read/write data from these ports and for manipulation. The programming language used is “Visual Basic 6.0”, the basic functions for reading and writing data are “vbInp(PortAddress)” and “vbOut(PortAddress, DecimalValue)” respectively which will be discussed in detail in the Software Section.

Nibble Mode To Input 8-Bits to PC:

Nibble mode is the preferred way of reading 8 bits of data without placing the port in reverse mode and using the data lines. Nibble mode uses a Quad 2 line to 1 line multiplexer to read a nibble of data at a time. Then it "switches" to the other nibble and reads its. Software can then be used to construct the two nibbles into a byte. The only disadvantage of this technique is that it is slower. It now requires a few I/O instructions to read the one byte, and it requires the use of an external IC.

Image:Clip image024.jpg''''

The operation of the 74LS157, Quad 2 line to 1 line multiplexer is quite simple. It simply acts as four switches. When the A/B input is low, the A inputs are selected. E.g. 1A passes through to 1Y, 2A passes through to 2Y etc. When the A/B is high, the B inputs are selected. The Y outputs are connected up to the Parallel Port's status port, in such a manner that it represents the MSnibble of the status register. While this is not necessary, it makes the software easier.

Behavior of Strobe^ Signal:

Strobe^, pin 1of the control port, is an active low signal. Whenever there is an output data written on the data port this Strobe^ occurs with a short duration of few microseconds. Therefore, this signal can be used for the typical ALE signals in the circuit, for example, Output data latch etc. The Strobe^ and its associated logic will be discussed further in Circuit Description.

III'. 'Interface and Digital Hardware Circuitry Section:

Having acquainted with the parallel port hardware this section looks at the external circuitry needed to interface the Instrumentation Section with the PC. As already mentioned in the hardware section of the parallel port, (refer to Note 1) to draw the least current from it the best bet is to use the buffers. Hence the basic initial step to be taken in external circuitry is to protect the parallel port from damage using the buffer interface as shown in the fig. The buffer IC used here is 74LS367.

74LS367 (Hex 3-State Buffer Bus Driver):

This device contains six independent gates each of which performs a non-inverting buffer function. The outputs have the 3-STATE feature. When enabled, the outputs exhibit the low impedance characteristics of a standard LS output with additional drive capability to permit the driving of bus lines without external resistors. When disabled, both the output transistors are turned OFF presenting a high-impedance state to the bus line. Thus the output will act neither as a significant load nor as a driver. To minimize the possibility that two outputs will attempt to take a common bus to opposite logic levels, the disable time is shorter than the enable time of the outputs.

Connection Diagram

Image:Clip image026.jpg''''

Image:Clip image028.jpg

[edit] Absolute Maximum Ratings:

[edit] Supply Voltage 7V

Input Voltage 7V

Operating Free Air Temperature Range 0°C to +70°C

Storage Temperature Range -65°C to +150°C

Image:Clip image030.jpg''''

Image:Clip image032.jpg

Fig : Buffer Interface with the Parallel Port

Having done with the buffer interface, the output lines from the buffers corresponds to its respective pins on the parallel port. The data outputs from the data port are to be latched, as there is continuous change on data port and for this purpose an 8-bit latch, 74LS373 3-State Octal D-Type latch is used.

74LS373 (3-State Octal D-Type Transparent Latch and Edge Triggered FlipFlop):

These 8-bit registers feature totem-pole 3-STATE outputs designed specifically for driving highly-capacitive or relatively low-impedance loads. The high-impedance state and increased high-logic level drive provide these registers with the capability of being connected directly to and driving the bus lines in a bus-organized system without need for interface or pull-up components. They are particularly attractive for implementing buffer registers, I/O ports, bi-directional bus drivers, and working registers.

The eight latches of the DM74LS373 are transparent D-type latches meaning that while the enable (G) is HIGH the Q outputs will follow the data (D) inputs. When the enable is taken LOW the output will be latched at the level of the data that was set up. A buffered output control input can be used to place the eight outputs in either a normal logic state (HIGH or LOW logic levels) or a high-impedance state. In the high-impedance state the outputs neither load nor drive the bus lines significantly. The output control does not affect the internal operation of the latches or flip-flops. That is, the old data can be retained or new data can be entered even while the outputs are OFF.

Connection Diagram:

Image:Clip image034.jpg

Image:Clip image036.jpg

Features:

· Choice of 8 latches or 8 D-type flip-flops in a single package

· 3-STATE bus-driving outputs

· Full parallel-access for loading

· Buffered control inputs

· P-N-P inputs reduce D-C loading on data lines

[edit] Absolute Maximum Ratings:

Supply Voltage 7V

Input Voltage 7V

Operating Free Air Temperature Range 0°C to +70°C

Storage Temperature Range -65°C to +150°C

Recommended Operating Conditions:

Image:Clip image038.jpg

The outputs of the latch are classified for controlling the hardware i.e., A^/B signal of 74LS157 & A0, A1, A2 signals of ADC 0809 MUX and for outputting the four devices accordingly as per the conditions mentioned through relays as shown in the below figure.

Image:Clip image040.jpg

Fig  : Compromising 8 o/p’s for controlling hardware and outputting devices

Note1: The On/Off control utilized relays connected to the interface through a simple transistor switch as shown in figure.

Image:Clip image042.jpg

Fig: Relay Driver Circuit

Note2: A step down transformer (12V-0-12V) is used with some regulators for supply voltages in the circuit.

These classifications will be discussed in detail in Circuit Description and Software Sections.

Having acquainted with the interfacing of the outputting circuitry we now discuss inputting the analog voltages into the PC by digitizing using an ADC. As we are measuring 3 analog inputs there should be a compromising in selecting the inputs and switching between the inputs and therefore we need a Multiplexer. Even the digitized output from ADC should be latched; here we needed an 8-bit Latch. Therefore, we need a circuit with an ADC, MUX and an output Latch. The best replacement for all this circuit is ADC0809, the heart of the circuit.

'ADC 0809 ('8-Bit µP Compatible A/D Converters with 8-Channel Multiplexer):

The ADC0809 data acquisition component is a monolithic CMOS device with an 8-bit analog-to-digital converter, 8-channel multiplexer and microprocessor compatible control logic. The 8-bit A/D converter uses successive approximation as the conversion technique. The converter features a high impedance chopper stabilized comparator, a 256R voltage divider with analog switch tree and a successive approximation register. The 8-channel multiplexer can directly access any of 8-single-ended analog signals. The device eliminates the need for external zero and full-scale adjustments. Easy interfacing to microprocessors is provided by the latched and decoded multiplexer address inputs and latched TTL TRI-STATE outputs. Incorporating the most desirable aspects of several A/D conversion techniques has optimized the design of the ADC0809. The ADC0809 offers high speed, high accuracy, minimal temperature dependence, excellent long-term accuracy and repeatability, and consumes minimal power. These features make this device ideally suited to applications from process and machine control to consumer and automotive applications.

Features:

· Easy interface to all microprocessors

· Operates ratiometrically or with 5 VDC or analog span adjusted voltage reference

· No zero or full-scale adjust required

· 8-channel multiplexer with address logic n 0V to 5V input range with single 5V power supply

· Outputs meet TTL voltage level specifications n Standard hermetic or molded 28-pin DIP package n 28-pin molded chip carrier package

Key Specifications

· Resolution 8 Bits

· Total Unadjusted Error ±1/2 LSB and ±1 LSB

· Single Supply 5 VDC

· Low Power 15 mW

  • Conversion Time 100 µs

Connection Diagram of ADC 0809:

Image:Clip image044.jpg

Block Diagram of ADC 0809:

Mux Address Analog Inputs

Image:Clip image046.jpg'

Absolute Maximum Ratings:

· Supply Voltage (VCC) 6.5V

· Voltage at Any Pin (Except Control Inputs) -0.3V to (VCC+0.3V)

· Voltage at Control Inputs -0.3V to +15V

(START, OE, CLOCK, ALE, ADD A, ADD B, ADD C)

· Storage Temperature Range -65°C to +150°C

· Package Dissipation at TA 25°C 875 mW

· Lead Temp. (Soldering, 10 seconds)

· Dual-In-Line Package (plastic) 260°C

· Dual-In-Line Package (ceramic) 300°C

· Molded Chip Carrier Package

Vapor Phase (60 seconds) 215°C

· Infrared (15 seconds) 220°C

· ESD Susceptibility 400V

Operating Conditions:

· Temperature Range TMIN <= TA <= TMAX

· ADC0809 -40°C <= TA <= +85°C

· Range of VCC 4.5 VDC to 6.0 VDC

Image:Clip image048.jpg

Image:Clip image050.jpg

Functional Description

Multiplexer: The device contains an 8-channel single-ended analog signal multiplexer. A particular input channel is selected by using the address decoder. Below table shows the input states for the address lines to select any channel. The address is latched into the decoder on the low-to-high transition of the address latch enable signal.

Image:Clip image052.jpg

[edit] CONVERTER CHARACTERISTICS

The Converter:

The heart of this single chip data acquisition system is its 8-bit analog-to-digital converter. The converter is designed to give fast, accurate, and repeatable conversions over a wide range of temperatures. The converter is partitioned into 3 major sections: the 256R ladder network, the successive approximation register, and the comparator. The converter’s digital outputs are positive true. The 256R ladder network approach ( Figure 1) was chosen over the conventional R/2R ladder because of its inherent monotonicity, which guarantees no missing digital codes. Monotonicity is particularly important in closed loop feedback control systems. A non-monotonic relationship can cause oscillations that will be catastrophic for the system. Additionally, the 256R network does not cause load variations on the reference voltage.

The bottom resistor and the top resistor of the ladder network in Figure 1are not the same value as the remainder of the network. The difference in these resistors causes the output characteristic to be symmetrical with the zero and full-scale points of the transfer curve. The first output transition occurs when the analog signal has reached +1/2 LSB and succeeding output transitions occur every 1 LSB later up The successive approximation register (SAR) performs 8 iterations to approximate the input voltage. For any SAR type converter, n-iterations are required for an n-bit converter. Figure 2shows a typical example of a 3-bit converter. In the ADC0808, ADC0809, the approximation technique is extended to 8 bits using the 256R network. The A/D converter’s successive approximation register (SAR) is reset on the positive edge of the start conversion (SC) pulse. The conversion is begun on the falling edge of the start conversion pulse. A conversion in process will be interrupted by receipt of a new start conversion pulse. Continuous conversion may be accomplished by tying the end-of-conversion (EOC) output to the SC input. If used in this mode, an external start conversion pulse should be applied after power up. End-of-conversion will go low between 0 and 8 clock pulses after the rising edge of start conversion.

The most important section of the A/D converter is the comparator. It is this section, which is responsible for the ultimate accuracy of the entire converter. It is also the comparator drift, which has the greatest influence on the repeatability of the device. A chopper-stabilized comparator provides the most effective method of satisfying all the converter requirements. The chopper-stabilized comparator converts the DC input signal into an AC signal. This signal is then fed through a high gain AC amplifier and has the DC level restored. This technique limits the drift component of the amplifier since the drift is a DC component, which is not passed by the AC amplifier. This makes the entire A/D converter extremely insensitive to temperature; long term drift and input offset errors. Figure 4 shows a typical error curve for the ADC0808 as measured using the procedures outlined in AN-179.

Image:Clip image054.jpg

Figure : Resistor Ladder and Switch Tree

Image:Clip image056.jpg

Fig  : 3-bit A/D Transfer Curve

Image:Clip image058.jpg

Fig :3-bit A/D Absolute Accuracy Curve

Image:Clip image060.jpg

Fig : Typical Error Curve

As there are only three analog inputs to be measured we use only P26, P27, P28 respectively for IN0, IN1, IN2. The input is selected based on address given to MUX A0, A1, and A2 from the software. The digital output is now given to the 74LS157 Quad 2 line to 1 line MUX as shown in the fig.

Image:Clip image062.jpg

Fig : The ADC 0809 with 74LS157 block

74LS157(Quad 2 Line to 1 Line Multiplexer):

This is a monolithic data selector/multiplexer, which contains inverters and drivers to supply full on-chip data selection to the four output gates. A separate strobe input is provided. A 4-bit word is selected from one of two sources and is routed to the four outputs. When the A^/B signal is low it selects the low nibble and when it goes high, the most significant nibble appears at the output the MUX. The software routine is used to read the whole byte. Thus an 8-bit data is inputted to the PC through the status lines of the parallel port.

For the conversion of analog to digital ADC 0809 needs an external clock typically of about 640kHz. Hence a 555 Timer configured, as Astable Multi Vibrator is needed for the circuit to be complete. Fig . shows 555 timer circuit.

Image:Clip image064.jpg

Fig : 555 Timer Circuit

This completes the Hardware Section of the Project.

In the coming section we discuss the operation of the circuit.

CIRCUIT DESCRIPTION

In this section the detailed description of the circuit working is explained.

Where to Proceed From:

As seen from Instrumentation Section three analog inputs are being manipulated and the outputs of the respective sensing circuits appear as inputs for the ADC at pins 25, 26, 27, which were named as IN0, IN1, IN2. The ADC has to now switch between the inputs at equal intervals and the digitized output is to be read by the software. Here follows how the above task is performed:

Assigning the Data Bits:

As discussed earlier Parallel Port is used in Standard Parallel Port Mode, which doesn’t support bi-directional transfer of data. Now that there are only Data Outputs, there should be a compromise between these 8 data lines for controlling A^/B signal of Quad 2 line to 1 line MUX (74LS157), the three address lines for the Multiplexer of ADC 0809 to select the different analog inputs and four data lines are needed for outputting devices respectively for Automatic Switching of Lights, Automatic Switching of AC, Alarm for Security System and Switching On/Off lights listening to the Voice Commands. Therefore the classified 8 Data lines as follows:

         D7     D6     D5     D4               D3     D2     D1     D0
     Switch   AC  Voice Alarm            A2     A1     A0    A^/B

Initializing the Hardware:

Now considering the first four bits ie, D0 to D3, they are used for the controlling of MUX of 74LS157 and ADC 0809. To start the process the MUX of ADC is first initialized and therefore the bits D1, D2, D3 take the values 0. Also the signal A^/B is made 0 initially so that is refers to the Low Nibble for any output from the ADC as the “Output Enable (OE)” signal is kept high all time. Through software the process is initialized i.e., a decimal value of 0 is given to the data port through “vbOut” command.

Enabling the Latch signals by Strobe:

As per the behavior of the strobe, the “vbOut” command when executed there is a strobe pulse, active low pulse of few microseconds, which enables the “Address Latch Enable (ALE)” high thereby placing the address A2 A1 A0 on the address lines. (It is to be noted that Strobe also enables the ALE of output data Latch 74LS373). This now selects the first analog input. As seen from the Circuit Diagram Strobe from pin 1 is given to the “Start of Conversion (SOC)” thereby the SOC signal goes high and the conversion starts and typically the conversion time is 100 microseconds. When SOC goes high, EOC goes low and is high only after the conversion is complete.

Chances of Interruption in the Process:

If it is taken into consideration that the execution time of a PC is much faster than that of the ADC 0809 then it should be noticed that if the PC sends the out signal before any conversion is completed and because there will be a strobe pulse, the new address is latched and switches into the next analog input, results in the interruption of that conversion and erroneous results are obtained.

Remedy through Hardware Logic:

To overcome this problem of Asynchronous, a simple logic is used as shown in the figure below:

Image:Clip image066.jpg

Fig: To OverCome the asynchronous problem.

The Strobe is “ANDed” with EOC before giving it to the ALE and therefore any Strobe at the time of conversion is made low and is active only when both the EOC and Strobe are high. Note that Strobe here is inverted before “ANDing” with the EOC. The timing sequence of the above logic is drawn as follows:

Clearly from the timing diagram Strobe comes into play only when the EOC signal goes high thereby resolving the problem the Asynchronization.

Image:Clip image068.jpg

Remedy through Software Logic:

Here the EOC is monitored through the software, the condition for EOC=1 is checked and the “vbOut” command which possibly occurs the Strobe is given only when the condition is satisfied i.e., the command waits for the EOC to be high. Giving EOC to the Status 3 pin, the unused input in the Status Port, where in other pins s4-s7 used for reading the nibble, does this. Even this is shown on the screen.

Getting the Byte:

With the above process the digital word of the first analog input appears as inputs to the Quad 2 line to 1 line MUX. Now incrementing the data on the data port A^/B is made 1 which selects the high nibble of the digital word. The got Low Snibble and Most Snibble are concatenated using the software and is compared with the threshold values as explained in the Instrumentatin Section. As per the condition the output devices are switched.

Masking:

Again the word on the data port is incremented there by selecting the LSnibble of the 2nd analog input and this process is repeated. After one cycle of conversions i.e., conversion of 3 inputs into digital form, the last four bits on the data port are to be masked and then process is continued in order to remain the previous state of the output devices.

Voice Recognition:

For voice control, the input from the microphone is processed through the software and the voice is recognized as text, which then checks for the “recognized command” and switches the output device through a relay.

This whole process is repeated for continuous monitoring.

SOFTWARE SECTION:

The software section deals with the programming of the “Room Engine” for the Automation in “Visual Basic 6.0”. As this package handles all the Automation Tasks of the home, it is called by name “Room Engine”. As VB possesses the best GUI, automating the events and switching the devices by a mouse click is easier to do.

Everything is monitored and the status is showed. The “Room Engine” runs in the background (taskbar) and starts whenever the PC is online. The outcome of the VB is shown is figure. Any change in input and output will be shown in their respective textboxes and the comments are displayed of what the “Room Engine” is performing. To overcome any problem of conversion timings and synchronization between PC and ADC, some delays are introduced.

ALGORITHM:

1. Initialize the MUX (ADC0809) and Quad 2 to 1 MUX by sending the control word (0000) to least 4 bits of data port.

2. Read the LSnibble on the status lines ignoring the pin 3 of status.

3. Increment the control word to set 74LS157 to read MSnibble.

4. Read the Msnibble on the status lines.

5. Concatenate Msnibble and Lsnibble to get the 8-bit digital equivalent.

6. Compare with the got byte with the threshold value.

7. Check for the EOC status on the pin 3 of the status.

8. If EOC=1 then according to the condition, the corresponding signal to switch On or Off the output relays.

9. Increment the control word masking the high nibble on the data port.

10. Repeat the process for continuous monitoring of the system.

Features:

1. The Data Port and the Status Port is monitored all time and status is shown on the screen.

2. Can be interrupted at anytime to install any new devices.

3. All time compared with the theoretical values and any error can be easily detected.

VB CODE FOR ROOM ENGINE:

There are two forms 1. Automation.frm 2. FrmLogin.frm and a module Module1.bas and code for each are given separately. As per the screen shot shown the buttons, labels and textboxes are to be placed on the form and the Name Property should be set as per the code. Note that this works fine only in Windows 9x but not on WinNT, 2k as it has some constraints on parallel port and some different procedure should be followed.

' PROGRAMMING CODE FOR THE PC BASED HOME AUTOMATION

Note: A DLL is defined as “Dynamic Link Library”. The DLL’s required are to be placed in the /windows/system directory. This code uses the following DLL’s:

1. WIN95IO.DLL : Required in order to control the port directly.

2. KERNEL32.DLL: Required for Sleep() function.

3. SHELL32.DLL: For executing external command.

4. SAPI.DLL: Microsoft Speech Object Library.

5. XVOICE.DLL: Microsoft Direct Speech Recognition.

6. XLISTEN.DLL: Microsoft Direct Speech Synthesis.

‘ THIS CODE IS WRITTEN IN THE AUTOMATIO.FRM FORM

‘ DECLARATION

Private Declare Sub vbOut Lib "WIN95IO.DLL" (ByVal nPort As Integer, ByVal nData As Integer)

Private Declare Sub vbOutw Lib "WIN95IO.DLL" (ByVal nPort As Integer, ByVal nData As Integer)

Private Declare Function vbInp Lib "WIN95IO.DLL" (ByVal nPort As Integer) As Integer

Private Declare Function vbInpw Lib "WIN95IO.DLL" (ByVal nPort As Integer) As Integer

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Declare Function ShellExecute Lib "shell32.dll" _

   Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal _
   lpOperation As String, ByVal lpFile As String, ByVal _
   lpParameters As String, ByVal lpDirectory As String, _
   ByVal nShowCmd As Long) As Long

Dim sFile As String

Dim noth As Long

Dim WithEvents RC As SpInProcRecoContext

Dim Recognizer As SpInprocRecognizer

Dim myGrammar As ISpeechRecoGrammar

Dim AutoMode As Boolean

Const ThresholdLDR = 204 'Equals 4v (11001100) from the LDR, Switches on light when dark

Const ThresholdLM35 = 102 'Equals 2v (01100110)=40^C from the LM35, Switches AC on

Const ThresholdOBT500 = 204 'Give the range in actual implementation

Dim StopAuto As Integer

‘This functions returns the status of the specified bit

Function BitStatus(PortAddress, BitYouWant) As Integer

   If PortAddress = 888 Then
       NumOfBits = 8                 ‘Data Register
   ElseIf PortAddress = 889 Then
       NumOfBits = 8                 ‘Status Register S0 to S2 are reserved
   ElseIf PortAddress = 890 Then
       NumOfBits = 4                 ‘Control Register   
   End If
   ReDim PortBits(NumOfBits) As Integer
   PortNum = vbInp(PortAddress)
   While (j < NumOfBits)
       PortBits(j) = PortNum Mod 2
       j = j + 1
       PortNum = PortNum \ 2
   Wend
   BitStatus = PortBits(BitYouWant)

End Function

Function DecToBin(DecValue, BitYouNeed) As Integer

   Dim bitvalues(8) As Integer
   While bi < 8
       bitvalues(bi) = DecValue Mod 2
       bi = bi + 1
       DecValue = DecValue \ 2
   Wend
   DecToBin = bitvalues(BitYouNeed)

End Function

‘ This function is used in outputting the data

Sub OutPort(OutNum As Integer)

   vbOut 888, vbInp(888) + OutNum
   If OutNum = 0 Then vbOut 888, 0
       valueondata.Text = vbInp(888)
   While vod < 8
       data(vod).Text = DecToBin(valueondata.Text, vod)
       vod = vod + 1
   Wend

End Sub

‘This procedure is called when delay is needed

Public Sub Delay(HowLong As Date)

   TempTime = DateAdd("s", HowLong, Now)
   While TempTime > Now
       DoEvents 'Allows windows to handle other stuff
   Wend

End Sub

Private Function Invert(GiveBit As Integer)

If GiveBit = 0 Then

GiveBit = 1

ElseIf GiveBit = 1 Then

GiveBit = 0

End If

Invert = GiveBit

End Function

Private Sub Form_Load()

With nid

       .cbSize = Len(nid)
       .hwnd = Automation.hwnd
       .uId = vbNull
       .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
       .uCallBackMessage = WM_MOUSEMOVE
       .hIcon = Automation.Icon
       .szTip = "Suman's Home Automation Running..." & vbNullChar
      End With
      Shell_NotifyIcon NIM_ADD, nid
      AutoMode = False
      StopAutoBtn.Enabled = False
      TrayStopAutomation.Enabled = False

‘Initializing

While DataInd < 8

   data(DataInd).Text = 0
   dataget(DataInd).Text = 0
   DataInd = DataInd + 1

Wend

While DataInd2 < 8

   statusget(DataInd2).Text = 0
   DataInd2 = DataInd2 + 1

Wend

While DataInd3 < 8

   controlget(DataInd3).Text = 0
   DataInd3 = DataInd3 + 1

Wend

   valueondata.Text = vbInp(888)
   Automation.WindowState = vbMaximized

End Sub

Private Sub Form_Resize()

   'This is necessary to assure that the minimized window is hidden
   If Automation.WindowState = vbMinimized Then Automation.Hide

End Sub

Private Sub Form_Unload(Cancel As Integer)

   'This removes the icon from the system tray
   Shell_NotifyIcon NIM_DELETE, nid

End Sub

‘ ALLOWS TO ROOM ENGINE TO RUN IN THE TASKBAR, LOOK CODE FOR MODULE1

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As _

        Single, Y As Single)

'This procedure receives the callbacks from the System Tray icon.

     Dim Result As Long
     Dim msg As Long
     'the value of X will vary depending upon the scalemode setting
     If Me.ScaleMode = vbPixels Then
     msg = X
     Else
     msg = X / Screen.TwipsPerPixelX
     End If
     Select Case msg
     Case WM_LBUTTONDBLCLK    '515 restore form window
     Me.WindowState = vbMaximized
     Result = SetForegroundWindow(Me.hwnd)
     Me.Show
     Case WM_RBUTTONUP        '517 display popup menu
     Result = SetForegroundWindow(Me.hwnd)
     Me.PopupMenu Me.TrayMenu
     End Select

End Sub

Private Sub manualonoff_Click(Index As Integer)

If Index = 0 Then

   If manualonoff(0).Caption = "Switch On" Then
       OutPort (128)
       HereStatus.Caption = "The Switch at D7 is kept ON"
       manualonoff(0).Caption = "Switch Off"
   ElseIf manualonoff(0).Caption = "Switch Off" Then
       vbOut 888, vbInp(888) - 128
       valueondata.Text = vbInp(888)
       HereStatus.Caption = "The Switch at D7 is kept OFF"
       manualonoff(0).Caption = "Switch On"
   End If

ElseIf Index = 1 Then

   If manualonoff(1).Caption = "AC On" Then
       OutPort (64)
       HereStatus.Caption = "The AC at D6 is kept ON"
       manualonoff(1).Caption = "AC Off"
   ElseIf manualonoff(1).Caption = "AC Off" Then
       vbOut 888, vbInp(888) - 64
       valueondata.Text = vbInp(888)
       HereStatus.Caption = "The AC at D6 is kept OFF"
       manualonoff(1).Caption = "AC On"
   End If

ElseIf Index = 2 Then

   If manualonoff(2).Caption = "Voice On" Then
       OutPort (32)
       HereStatus.Caption = "The Voice Control Switch at D6 is kept ON"
       manualonoff(2).Caption = "Voice Off"
   ElseIf manualonoff(2).Caption = "Voice Off" Then
       vbOut 888, vbInp(888) - 32
       valueondata.Text = vbInp(888)
       HereStatus.Caption = "The Voice Control Switch at D6 is kept OFF"
       manualonoff(2).Caption = "Voice On"
   End If

ElseIf Index = 3 Then

   If manualonoff(3).Caption = "Alarm On" Then
       OutPort (16)
       HereStatus.Caption = "The Buzzer at D5 is kept ON"
       manualonoff(3).Caption = "Alarm Off"
   ElseIf manualonoff(3).Caption = "Alarm Off" Then
       vbOut 888, vbInp(888) - 16
       valueondata.Text = vbInp(888)
       HereStatus.Caption = "The Buzzer at D5 is kept OFF"
       manualonoff(3).Caption = "Alarm On"
   End If

End If

End Sub

Private Sub Restart_Click()

Call StopAutoBtn_Click

HereStatus.Caption = "Home Automation Resetted and Restarted...!!"

Delay 1

Call starthome_Click

End Sub

Private Sub SensorInps_Change(Index As Integer)

SensorInps(1).Text = (SensorInps(0).Text * 5) / (2 ^ 8)

If SensorInps(1).Text > 4 Then

portname(9).Caption = "LDR detected Darkness..Sent high Signal to Switch(D7)"

Else

portname(9).Caption = "LDR detected No Darkness..Sent low Signal to Switch(D7)"

End If

SensorInps(3).Text = (SensorInps(2).Text * 5) / (2 ^ 8)

If SensorInps(3).Text > 2 Then

portname(11).Caption = "LM35 detected high temp. of " & SensorInps(3) * 20 & " C ..Sent high Signal to AC(D6)"

Else

portname(11).Caption = "LM35 detected No high temp..Sent low Signal to AC(D6)"

End If

SensorInps(5).Text = (SensorInps(4).Text * 5) / (2 ^ 8)

End Sub

Private Sub StopAuto_Click()

AutoMode = False

End Sub

‘Stops the Automation

Private Sub StopAutoBtn_Click()

AutoMode = False

StartHome.Enabled = True

StopAutoBtn.Enabled = False

   For mof2 = 0 To 3
       manualonoff(mof2).Enabled = True
   Next mof2

Call clear_Click(0)

HereStatus.Caption = "Stopped Home Automation!!!"

TrayStartAutomation.Enabled = True

TrayStopAutomation.Enabled = False

End Sub

Private Sub TrayExit_Click()

If vbYes = MsgBox("Are you sure to Exit !", vbYesNo) Then

End

End If

End Sub

Private Sub TrayOpen_Click()

Dim Result As Long

      Me.WindowState = vbMaximized
      Result = SetForegroundWindow(Me.hwnd)
      Me.Show

End Sub

Private Sub TrayStartAutomation_Click()

Call starthome_Click

AutoMode = True

TrayStartAutomation.Enabled = False

TrayStopAutomation.Enabled = True

End Sub

Private Sub TrayStopAutomation_Click()

AutoMode = False

TrayStopAutomation.Enabled = False

TrayStartAutomation.Enabled = True

End Sub

Private Sub trayabout_click()

MsgBox " This is the Software Package for PC BASED HOME AUTOMATION Project By, Suman K And Team"

End Sub

‘VOICE RECOGNITION CODE

Private Sub voiceenabled_Click()

If voiceenabled.Caption = "Start Voice Interface" Then

   VoiceMode.Caption = "Please Wait....."

Set RC = New SpInProcRecoContext

   Set Recognizer = RC.Recognizer
   Set myGrammar = RC.CreateGrammar
   myGrammar.DictationSetState SGDSActive
   Dim Category As SpObjectTokenCategory
   Set Category = New SpObjectTokenCategory
   Category.SetId SpeechCategoryAudioIn
   Dim Token As SpObjectToken
   Set Token = New SpObjectToken
   Token.SetId Category.Default()
   Set Recognizer.AudioInput = Token
   voiceenabled.Caption = "Stop Voice Interface"
       VoiceMode.Caption = "Running...."
       ElseIf voiceenabled.Caption = "Stop Voice Interface" Then
       voiceenabled.Caption = "Start Voice Interface"
       VoiceMode.Caption = "Stopped.."
       myGrammar.DictationSetState SGDSInactive
       voiceinput.Text = "Your String Shown Here"
   Exit Sub
   End If

End Sub

Private Sub RC_Recognition(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal RecognitionType As SpeechLib.SpeechRecognitionType, ByVal Result As SpeechLib.ISpeechRecoResult)

    voiceinput.Text = Result.PhraseInfo.GetText
   If voiceinput.Text = "on" Or voiceinput.Text = "On" Or voiceinput.Text = "ON" Then
   If BitStatus(888, 5) = 1 Then
   vbOut 888, 0 + vbInp(888)
   Else
   OutPort (32)
   End If
   'herestatus.Caption = "Swithced on light through voice input"
   portname(7).Caption = "The on command recognized and switched on the light"
   ElseIf voiceinput.Text = "off" Or voiceinput.Text = "of" Or voiceinput.Text = "Off" Or voiceinput.Text = "Of" Or voiceinput.Text = "all" Or voiceinput.Text = "half" Then
   If BitStatus(888, 5) = 0 Then
   vbOut 888, 0 + vbInp(888)
   Else
   vbOut 888, vbInp(888) - 32
   valueondata.Text = vbInp(888)
   End If
   portname(7).Caption = "The off command recognized and switched off the light"
   ElseIf voiceinput.Text = "stop" Or voiceinput.Text = "Stop" Or voiceinput.Text = "stopped" Or voiceinput.Text = "stop and" Then
   portname(7).Caption = "The stop command recognized and now exiting the automation...."
   Delay 2
   End
   Else
   portname(7).Caption = "The Command not recognized"

' sFile = "C:\Program Files\auto2\HomeAutomation.exe"

'

' noth = ShellExecute(0, "OPEN", _

' Environ("SystemRoot") & sFile, "", "", 1)

' vbOut 888, 128

' MsgBox "ready to switch on...... and switched on"

   End If

End Sub

‘ THIS IS THE PROCEDURE WHICH REPEATS AND MANAGES THE “ROOM ENGINE”, COMPARES WITH THE THRESHOLDS AND SWITHCHES THE DEVICES.

Private Sub starthome_Click()

   AutoMode = True
   StartHome.Enabled = False
   StopAutoBtn.Enabled = True
       For mof = 0 To 3
           manualonoff(mof).Enabled = False
       Next mof
   TrayStartAutomation.Enabled = False
   TrayStopAutomation.Enabled = True
   EOC = BitStatus(889, 3)
   status(3).Text = EOC
   HereStatus.Caption = "Home Automation Started !!!!!!!!!"
   Delay 1
   vbOut 888, 0 'FIRST Data port is cleared ie, initialized, first anolog input low nibble is selected'
   'MsgBox vbInp(888), vbInformation + vbOKOnly, "data port cleared"
   valueondata.Text = 0

TheStart:

   If AutoMode = False Then
       Exit Sub
   End If
   HereStatus.Caption = "data port cleared"

‘ MANAGES AUTOMATING SWITHCHING OF THE LIGHTS

   ReDim LsnibbleLDR(4) As Integer
   For i = 4 To 7
               LsnibbleLDR(i - 4) = BitStatus(889, i)
               status(i).Text = LsnibbleLDR(i - 4)
   Next i
   If AutoMode = False Then
               Exit Sub
   End If
   Delay 1
   OutPort (1) 'vbOut 888, vbInp(888) + 1 ' data port now contains dec value                   1, high nibble of first anolog input selected
           'MsgBox vbInp(888), vbInformation + vbOKOnly, "high nibble                            selected"
   HereStatus.Caption = vbInp(888) & "high nibble selected"
           ReDim MSnibbleLDR(4) As Integer
               For k = 4 To 7
               MSnibbleLDR(k - 4) = BitStatus(889, k)
               status(k).Text = MSnibbleLDR(k - 4)
               Next k
           ReDim GotByteLDR(8) As Integer
           While m < 8
               While m2 < 4
               GotByteLDR(m) = LsnibbleLDR(m2)
               m = m + 2
               m2 = m2 + 1
               Wend
           Wend
           While n < 8
               While n2 < 4
               GotByteLDR(n + 1) = MSnibbleLDR(n2) ' the low and high                                       nibble of ldr concatenated and kept in gotbyteldr
               n = n + 2
               n2 = n2 + 1
               Wend
           Wend
                       For inv1 = 6 To 7
                           GotByteLDR(inv1) = Invert(GotByteLDR(inv1))
                       Next inv1
           While bits < 8
           dataget(bits).Text = GotByteLDR(bits)
           bits = bits + 1
           Wend
           While ik < 8
           GotDecLDR = GotDecLDR + ((2 ^ ik) * GotByteLDR(ik)) 'decimal equi. of gotbyteldr
           ik = ik + 1
           Wend
           'MsgBox GotDecLDR, vbInformation + vbOKOnly, "the decimal of                              LDR    now compared with the threshold which is                                                   ThresholdLDR"
           HereStatus.Caption = GotDecLDR & " the decimal of LDR now                          compared with the threshold "
           Delay 1
           SensorInps(0).Text = GotDecLDR
           If GotDecLDR > ThresholdLDR Then 'compared with the threshold values
           'MsgBox "yes condition satisfied, switching signal light, press ok"
           HereStatus.Caption = "yes condition satisfied, switching signal light"
               If AutoMode = False Then
               Exit Sub
               End If
           Delay 1
               If BitStatus(888, 7) = 1 Then
               vbOut 888, (0 + vbInp(888))
               Else
               OutPort (128) 'vbOut 888, 128 + vbInp(888) 'if sent then the out is                             1000 0001
               End If
           'MsgBox "now the value on the data port is: ", vbInp(888), "   now                                 incrementing........... press ok"
           HereStatus.Caption = "now the value on the data port is: " &                                          vbInp(888) & "   now incrementing..."
               If AutoMode = False Then
               Exit Sub
               End If
           Delay 1
           OutPort (1) 'vbOut 888, (vbInp(888) + 1) 'then inc. to select the low                               nibble of 2nd anolog input
           'MsgBox vbInp(888), vbInformation + vbOKOnly, " low nibble of 2                              nd analog input selected"
           HereStatus.Caption = vbInp(888) & " low nibble of 2 nd analog input selected"
           Else
           'MsgBox "no condition not satisfied   just selecting the low nibble of                              2 nd analog input"
           HereStatus.Caption = "no condition not satisfied   just selecting the low nibble of 2 nd analog input"
               If BitStatus(888, 7) = 1 Then
               vbOut 888, vbInp(888) - 128
               Else
               vbOut 888, 0 + vbInp(888)
               End If
                   If AutoMode = False Then
                   Exit Sub
                   End If
           Delay 1
           OutPort (1) 'vbOut 888, (vbInp(888) + 1) 'SECOND  if here it will be 0000 0010 ie,, second anolog input
           End If
           'MsgBox "first finisthed"

‘ MANAGES AUTOMATIC SWITCHING OF AC/ROOM HEATER

           ReDim LSnibbleLM35(4) As Integer
               For ki = 4 To 7
               LSnibbleLM35(ki - 4) = BitStatus(889, ki)
               status(ki).Text = LSnibbleLM35(ki - 4)
               Next ki
                   If AutoMode = False Then
                   Exit Sub
                   End If
           Delay 1
           OutPort (1) 'vbOut 888, vbInp(888) + 1 ' data port now contains dec value 1, high nibble of second anolog input selected
           'MsgBox vbInp(888), vbInformation + vbOKOnly, " selecting high nibble of second"
           HereStatus.Caption = vbInp(888) & " selecting high nibble of second"
           ReDim MSnibbleLM35(4) As Integer
               For kLM = 4 To 7
               MSnibbleLM35(kLM - 4) = BitStatus(889, kLM)
               status(kLM).Text = MSnibbleLM35(kLM - 4)
               Next kLM
           ReDim GotByteLM35(8) As Integer
           While mLM < 8
               While mLM2 < 4
               GotByteLM35(mLM) = MSnibbleLM35(mLM2)
               mLM = mLM + 2
               mLM2 = mLM2 + 1
               Wend
           Wend
           While nLM < 8
               While nLM2 < 4
                   GotByteLM35(nLM + 1) = LSnibbleLM35(nLM2) ' the low and high nibble of lM35 concatenated and kept in gotbyteldr
                   nLM = nLM + 2
                   nLM2 = nLM2 + 1
               Wend
           Wend
                       For inv2 = 6 To 7
                           GotByteLM35(inv2) = Invert(GotByteLM35(inv2))
                       Next inv2
           While bitsLM < 8
               dataget(bitsLM).Text = GotByteLM35(bitsLM)
               bitsLM = bitsLM + 1
           Wend
           While ikLM < 8
               GotDecLM35 = GotDecLM35 + ((2 ^ ikLM) * GotByteLM35(ikLM)) 'decimal equi. of gotbytelM35
               ikLM = ikLM + 1
           Wend
           SensorInps(2).Text = GotDecLM35
                   If AutoMode = False Then
                   Exit Sub
                   End If
           If GotDecLM35 > ThresholdLM35 Then 'compared with the threshold values
           Delay 1
               If BitStatus(888, 6) = 1 Then
               vbOut 888, (0 + vbInp(888))
               Else
               OutPort (64)
               End If
           Else
               If BitStatus(888, 6) = 1 Then
               vbOut 888, vbInp(888) - 64
               Else
               vbOut 888, 0 + vbInp(888)
               End If
           ' vbOut 888, (64 + vbInp(888)) 'if sent then the out is 1100 0001 , OR 0100 0001
           End If
           'MsgBox vbInp(888), vbInformation + vbOKOnly, "is the status now "
           HereStatus.Caption = vbInp(888) & " is the status now "
                   If AutoMode = False Then
                   Exit Sub
                   End If
           Delay 1
           OutPort (1) ' vbOut 888, (vbInp(888) + 1)
                   If AutoMode = False Then
                   Exit Sub
                   End If
           HereStatus.Caption = " Starting to manipulate for the second cycle "
                   If AutoMode = False Then
                   Exit Sub
                   End If
           Delay 1

‘MANAGES THE SECURITY SYSTEM (GIVES ALARM WHEN HUMAN IS DETECTED)

           ReDim LSnibbleOBT(4) As Integer
               For kiOBT = 4 To 7
               LSnibbleOBT(kiOBT - 4) = BitStatus(889, kiOBT)
               status(kiOBT).Text = LSnibbleOBT(ki - 4)
               Next kiOBT
                   If AutoMode = False Then
                   Exit Sub
                   End If
           OutPort (1) 'vbOut 888, vbInp(888) + 1 ' data port now contains dec value 1, high nibble of third anolog input selected
           Delay 1
           HereStatus.Caption = vbInp(888) & " selecting high nibble of third input OBT"
           ReDim MSnibbleOBT(4) As Integer
               For kOBT = 4 To 7
               MSnibbleOBT(kOBT - 4) = BitStatus(889, kOBT)
               status(kOBT).Text = MSnibbleOBT(kOBT - 4)
               Next kOBT
           ReDim GotByteOBT(8) As Integer
           While mOBT < 8
               While mOBT2 < 4
               GotByteOBT(mOBT) = MSnibbleOBT(mOBT2)
               mOBT = mOBT + 2
               mOBT2 = mOBT2 + 1
               Wend
           Wend
           While nOBT < 8
               While nOBT2 < 4
                   GotByteOBT(nOBT + 1) = LSnibbleOBT(nOBT2) ' the low and high nibble of OBT concatenated and kept in gotbyteldr
                   nOBT = nOBT + 2
                   nOBT2 = nOBT2 + 1
               Wend
           Wend
                       For inv3 = 6 To 7
                           GotByteOBT(inv3) = Invert(GotByteOBT(inv3))
                       Next inv3
           While bitsOBT < 8
               dataget(bitsOBT).Text = GotByteOBT(bitsOBT)
               bitsOBT = bitsOBT + 1
           Wend
           While ikOBT < 8
               GotDecOBT = GotDecOBT + ((2 ^ ikOBT) * GotByteOBT(ikOBT)) 'decimal equi. of gotbyteOBT
               ikOBT = ikOBT + 1
           Wend
           SensorInps(4).Text = GotDecOBT
           GotDecOBTPreset = GotDecOBT
                   If AutoMode = False Then
                   Exit Sub
                   End If
           portname(13).Caption = "Waiting for Human to be Detected....!!"
           If GotDecOBT <> GotDecOBTPreset Then 'Is any human detected
           portname(13).Caption = "Human Presence Detected...Sent High Signal to Alarm(D4)."
           Delay 1
               If BitStatus(888, 4) = 1 Then
               vbOut 888, (0 + vbInp(888))
               Else
               OutPort (16)
               End If
           Else
               If BitStatus(888, 4) = 1 Then
               vbOut 888, vbInp(888) - 16
               Else
               vbOut 888, 0 + vbInp(888)
               End If
           End If
           'MsgBox vbInp(888), vbInformation + vbOKOnly, "is the status now "
           HereStatus.Caption = vbInp(888) & " is the status now "
                   If AutoMode = False Then
                   Exit Sub
                   End If
           HereStatus.Caption = " Manipulated three inputs successfully"
           HereStatus.Caption = " Starting to manipulate for the second cycle "
           vbOut 888, vbInp(888) And 240
           valueondata.Text = vbInp(888)
                   If AutoMode = False Then
                   Exit Sub
                   End If
           Delay 1

‘REPEATS THE PROCESS

           GoTo TheStart

End Sub

Private Sub exit_Click()

End

End Sub

Private Sub getbyte_Change(Index As Integer)

   If Index = 0 Then
   While DI < 8
   dataget(DI).Text = DecToBin(getbyte(0), DI)
   DI = DI + 1
   Wend
   ElseIf Index = 1 Then
   'While DI < 5
   'statusget(DI).Text = DecToBin(getbyte(1), DI)
   'DI = DI + 1
   While DI < 8
   statusget(DI).Text = DecToBin(getbyte(1), DI)
   DI = DI + 1
   Wend
   ElseIf Index = 2 Then
   While DI < 8
   controlget(DI).Text = DecToBin(getbyte(2), DI)
   DI = DI + 1
   Wend
   End If

End Sub

Private Sub send_Click(Index As Integer)

   If Index = 0 Then
   getbyte(0).Text = vbInp(888)
   HereStatus.Caption = "Data Value retrieved"
   ElseIf Index = 1 Then
   getbyte(1).Text = vbInp(889)
   HereStatus.Caption = "Status Value retrieved"
   ElseIf Index = 2 Then
   getbyte(2).Text = vbInp(890)
   HereStatus.Caption = "Control Value retrieved"
   End If

End Sub

Private Sub valueondata_Change()

   While vod < 8
       data(vod).Text = DecToBin(valueondata.Text, vod)
   If data(vod).Text = 0 Then
       datacheck(vod).Value = 0
   Else
       datacheck(vod).Value = 1
   End If
       vod = vod + 1
   Wend

End Sub

‘ THIS IS FOR TESTING AND DEBUGGING ONLY

Private Sub todata_Click(Index As Integer)

   If givevalue.Text = "" Then
       givevalue.Text = 0
   End If
   If Index = 0 Then
       vbOut 888, givevalue.Text
       valueondata.Text = vbInp(888)
       HereStatus.Caption = " The value " + givevalue.Text + " sent to Data Port"
   ElseIf Index = 1 Then
       vbOut 890, givevalue.Text
       valueondata.Text = vbInp(888)
       HereStatus.Caption = " The value " + givevalue.Text + " sent to Control Port"
   End If

End Sub

Private Sub clear_Click(Index As Integer)

   If Index = 0 Then
       vbOut 888, 0
       valueondata.Text = vbInp(888)
       givevalue.Text = vbInp(888)
       HereStatus.Caption = "Data Port Cleared"
       getbyte(0).Text = 0
   ElseIf Index = 1 Then
       vbOut 890, 0
       valueondata.Text = vbInp(888)
       HereStatus.Caption = "Control Port Cleared"
   ElseIf Index = 2 Then
       vbOut 888, 0
       vbOut 890, 0
       valueondata.Text = vbInp(888)
       HereStatus.Caption = "Data,Control Ports Cleared and Resetted"
   End If

End Sub

‘ THERE TIMERS SERVE THE PURPOSE OF BETTER LOOK

Private Sub Timer1_Timer()

   If Label1.Visible = True Then
   Label1.Visible = False
   ElseIf Label1.Visible = False Then
   Label1.Visible = True
   End If

End Sub

Private Sub herestatusblink_Timer()

   If herestat.Visible = True Then
   herestat.Visible = False
   ElseIf herestat.Visible = False Then
   herestat.Visible = True
   End If
   If VoiceMode.Caption = "Running...." And VoiceMode.Visible = True Then
   VoiceMode.Visible = False
   ElseIf VoiceMode.Visible = False Then
   VoiceMode.Visible = True
   End If
   If portname(15).Visible = True Then
   portname(15).Visible = False
   ElseIf portname(15).Visible = False Then
   portname(15).Visible = True
   End If

End Sub

‘ HERE ENDS THE CODE PART OF AUTOMATION.FRM

For the program to run in the taskbar a module should be added to the project.vbp and here it is Module1.bas. Following is the code for Module.bas

‘ THIS ALLOWS “ROOM ENGINE” TO RUN IN THE TASKBAR

     Public Type NOTIFYICONDATA
      cbSize As Long
      hwnd As Long
      uId As Long
      uFlags As Long
      uCallBackMessage As Long
      hIcon As Long
      szTip As String * 64
     End Type
     'constants required by Shell_NotifyIcon API call:
     Public Const NIM_ADD = &H0
     Public Const NIM_MODIFY = &H1
     Public Const NIM_DELETE = &H2
     Public Const NIF_MESSAGE = &H1
     Public Const NIF_ICON = &H2
     Public Const NIF_TIP = &H4
     Public Const WM_MOUSEMOVE = &H200
     Public Const WM_LBUTTONDOWN = &H201     'Button down
     Public Const WM_LBUTTONUP = &H202       'Button up
     Public Const WM_LBUTTONDBLCLK = &H203   'Double-click
     Public Const WM_RBUTTONDOWN = &H204     'Button down
     Public Const WM_RBUTTONUP = &H205       'Button up
     Public Const WM_RBUTTONDBLCLK = &H206   'Double-click
     Public Declare Function SetForegroundWindow Lib "user32" _
     (ByVal hwnd As Long) As Long
     Public Declare Function Shell_NotifyIcon Lib "shell32" _
     Alias "Shell_NotifyIconA" _
     (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
     Public nid As NOTIFYICONDATA

‘HERE ENDS THE CODE FOR MODULE1.BAS

In order to add security to the “Room Engine”, only authenticated users are allowed to login. The following is the code for frmlogin.frm form.

‘THIS ALLOWS ONLY AUTHENTICATED USERS TO LOGIN AND CONTROL ROOM ENGINE

Option Explicit

Public LoginSucceeded As Boolean

Private Sub cmdCancel_Click()

   'set the global var to false     'to denote a failed login
   LoginSucceeded = False
   Me.Hide

End Sub

Private Sub cmdOK_Click()

   'check for correct username and password
   If txtPassword.Text = "Automation" And (txtUserName.Text = "Project" Or txtUserName.Text = "suman") Then
               'success to the calling sub
       'setting a global var is the easiest
       LoginSucceeded = True
       Me.Hide

' form1.Visible = True

      Load form1
   Else
       MsgBox "Invalid User name or Password, try again!", , "Login"
       txtPassword.SetFocus
       SendKeys "{Home}+{End}"
   'End If
   End If

End Sub

Note: frmlogin.frm should be set as the starting form to be loaded for login interface. UserName = “Project” and Password = “Automation”

‘ HERE ENDS CODE FOR FRMLOGIN.FRM

SCOPE AND CONCLUSION OF THE PROJECT:

The outputs and inputs can be extended using some DeMultiplexers. These outputs on the parallel interface can be used to control all the lights in the room; the TV, answering machine, stereo and several tube radios. To control the volume on the TV and stereo, a DAC can be used in place of the pot. Tuning the TV can be easily accomplished by connecting a small relay in place of the up and down channel buttons on the tuner box. The stereo can also controlled by relays, except for tuning. A small stepper motor can turn the dial. Tape playing functions were controlled by solenoids.

Remote Control: A remote that uses DTMF tones to communicate between the transmitter and receiver can be used.

Other Sensors can be used as: Humidity sensor, Rain sensor, EMF sensor.

The “Room Engine” if likely is placed on the web as a form, and then it is possible for controlling the home from any other place in the world. One can connect to their PC when IP address of that PC is known. Also the software’s like “PCAnywhere” can be used to connect remotely to another computer and manage the “Room Engine”.

BIBLIOGRAPHY:''''

1. www.aaroncake.net

2. www.beyondlogic.com

3. www.homeautomation.com

4. www.national.com

5. www.ourworld.compuserve.com

6. www.fairchild.com

7. IEEE 1284 STANDARDS FOR PARALLELL PORT.

8. INTRODUCTION TO PARALLEL PORT INTERFACING, BY W. A. STEER.

Personal tools