brock

Monday, October 29, 2012

Cellphone-Based Device Control With Voice Acknowledgement

Here is a circuit that lets you operate your home appliances like lights and water pump from your office or any other remote place. So if you forgot to switch off the lights or other appliances while going out, it helps you to turn off the appliance with your cellphone. Your cellphone works as the remote control for your home appliances. You can control the desired appliance by pressing the corresponding key. The system also gives you voice acknowledgement of the appliance status.
Circuit description
Fig.1 shows the circuit for cellphone based device control with voice acknowledgement. It comprises microcontroller AT89C51, DTMF decoder MT8870, voice recording/playback device APR9600 and a few discrete components.

fig1
Microcontroller AT89C51 is at the heart of the circuit. It is a low-power, high-performance, 8-bit microcontroller with 4 kB of flash programmable and erasable read-only memory (PEROM) used as on-chip program memory, 128 bytes of RAM used as internal data memory, 32 individually programmable input/output (I/O) lines divided into four 8-bit ports, two 16-bit programmable timers/counters, a five-vector two-level interrupt architecture, on-chip oscillator and clock circuitry. A 11.0592MHz crystal (XTAL1) is  used to provide basic clock frequency for the microcontroller. Capacitor C3 and resistor R3 form the power-on reset circuit, while push-to-on switch S20 is used for manual reset.

Port pins P1.0 through P1.7 of the microcontroller are configured to get the input from push-to-on switches S1 through S8. Pins of Port P1 are pulled high via resistor network RNW1. Port pins P2.0 through P2.4 are configured to receive the decoded DTMF signal from DTMF receiver MT8870. The functions of the corresponding switches (S1 through S8) and cellphone keys are shown in Table I.



The DTMF decoder is used for decoding the mobile signal. It gets DTMF tone from the mobile headset’s speaker pins and decodes it into 4-bit digital signal. The DTMF decoder is operated with a 3.579MHz crystal (XTAL2 )  In DTMF receiver MT8870 (IC3), capacitor C12 is used to filter the noise and resistors R6 and R7 help to amplify the input signal using the internal amplifier.

Pin 16 of IC3 connected to resistor R5 provides the early steering output. It goes high immediately when the digital algorithm detects a valid tone pair (signal condition). Any momentary loss of signal condition causes ESt to return to low state.
Pin 17 of IC3 connected to capacitor C11 is bidirectional, acting as steering input/guard time output (St/GT). A  steering logic VTStdetected at St causes the device to register the detected tone pair. The guard time output resets the external steering time constant, and its state is a function of ESt and the voltage at St.

Port P3 pins P3.6 and P3.7 of IC1 are configured to select the control source for the devices. These are connected to DIP switches S17 and S18 and pulled high via resistors R2 and R1, respectively. Here, we are using two control sources, switches and mobile’s key. DIP switches S17 and S18 select the control sources as shown in Table II.



Pin 2.5 of Port P2 is configured to show the rest status. That is, if none of the control sources is selected by DIP switches S17 and S18, LED1 glows. Resistor R14 limits the current through LED1. 

Voice acknowledgement is provided by the APR9600 (IC2). It is a single-chip voice recording and playback device that can record and play multiple messages at random or in sequential mode for 60 seconds. The user can select sample rates with corresponding  quality recording lengths. Microphone amplifier, automatic gain control (AGC) circuits, internal anti aliasing filter, internal output amplifier and message management are some of the features of the APR9600. 

Here the APR9600 is configured in random-access mode, which supports two, four and eight messages of fixed durations. The length of each message is the total recording length available divided by the total number of memory segments/tracks enabled. 

Audio processor APR9600 can store up to eight voice messages. Port P0 pins and P2.7 are configured to communicate with IC2. Port P0 pins trigger selection of the message. Port pin P2.7 is the input signal to identify whether the voice message is playing or not.
Pins P3.0 through P3.5 of Port P3 control the devices with the help of relays RL1 through RL6 via relay driver IC4.

A speaker is connected to IC2 for audio output. The speaker output drives the mic input of the mobile for audio acknowledgement. An electret microphone MIC1 is connected to IC2 to record the voice in IC2. LED2 flashes to show the busy status of IC2 during recording and playback. The audio messages to be recorded in APR9600, by using trigger switches S9 through S16, are shown in Table III. SPST switch S19 is closed for recording and switch S19 is opened for playback. 
Recording and playback 
To record the voice in IC2, follow Table III. Close SPST switch S19 to make pin 27 of IC2 low. Thereafter, press and hold switches S9 through S16 to record corresponding voice messages. LED2 flashes to indicate audio recording.

For playback of any device status, open SPST switch S19 and press the corresponding switch (S9 through S16). The recorded audio can be heard from the speaker connected to pins 14 and 15 of IC2. Fig.2 shows the pin configuration of mobile headset.


Software

The program (Device_Control.BAS) for the microcontroller is written using BASCOM microcontroller programming software. In the program, first, initialise the port (P0-P3) for corresponding controls. Thereafter, declare the variables for the program. After declaration, assign some initial value to variables. Here, microcontroller ports are initialised to make all the devices ‘off’ initially.

After that, the main function checks through ‘Do’ loop which control source has been enabled by using DIP switch pins. If you select switch S17, it searches the input from the mobile only. If you select switch S18, it searches the input from the switches (S1 through S8) only. If you enable both switch S17 and switch S18, it searches the inputs from switches and mobile. Else, the rest-status LED1 glows. Refer to Table II to select the control source. 
The mobile signal is decoded into the DTMF signal by IC3. The DTMF output for each mobile key (used in this project) pressed is shown in Table IV.
After getting the input from the switches or mobile, the program goes to the device_action subroutine and executes the corresponding action (refer Table I). 

The device_action subroutine changes the status of the device and calls the voice_alert subroutine. The voice_alert subroutine checks the device status and device name from the source input and controls the corresponding pins of IC2. First, it selects the voice signal for the device name. After playing that, it selects on/off status of corresponding device as mentioned in Table III. 

If you press ‘*’ key followed by the device number on your mobile handset, it will not change the status of that device and inform the current device status. If you press device number followed by ‘*’ key on your mobile handset, it will change the status of that device and inform the changed device status. ‘#’ key controls the voice_control subroutine and acts like a mute key.

PIC16F877A-Based Temperature Monitoring System

Temperature monitoring and  control is important in industry environments. Sensors are widely used for measurement of temperature. Usually, a temperature sensor converts the temperature into an equivalent voltage output. IC LM35 is such a sensor. Here we describe a simple temperature measurement and display system based on LM35 sensor and PIC16F877A microcontroller. The temperature in degrees Celsius is displayed on a 16×2 LCD.

Fig.1 shows the functional block diagram of the PIC16F877A-based temperature monitoring system. The key features of this system are:

1. Continuous monitoring of temperature with 1-second update interval (which can be varied in the program).

2. Temperature measurement using LM35 precision integrated-circuit sensor.

3. Precise analogue-to-digital conversion using in-built 10-bit analogue- to-digital converter (ADC) of PIC16F877A microcontroller.

Hardware description


Fig.2.shows the circuit  of the temperature  monitoring  system. The circuit mainly consists of the LM35 temperature sensor, PIC16F877A microcontroller and HD44780 controller based 16×2 LCD.

fig2
The output of the sensor is fed to the internal ADC of the microcontroller. Pin 2 of the microcontroller (RA0/AN0) is channel-1 of the internal ADC. The analogue voltage output of the sensor is converted into its equivalent digital value by the ADC and then its equivalent degree Celsius value is calculated by the software. The calculated temperature value is displayed on the LCD.
LM35 sensor. Fig.3 shows the pin configuration of LM35. It is a precision integrated-circuit centigrade temperature sensor whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 thus has an advantage over linear temperature sensors calibrated in degree Kelvin, as the user is not required to subtract a large constant voltage from its output to obtain convenient Centigrade scaling. For each degree Celsius change in temperature, the sensor output changes by 10 mV.

The sensor can measure temperature in the range of 0 to 100°C, i.e., the output of the sensor varies from 0 to 1000 mV. The LM35 operates over the temperature range of -55° to +150°C, while the LM35C is rated for a -40°C to +110°C range (-10°C with improved accuracy).

Pin layout of the sensor is as follows:

Pin 1-VDD
Pin 2-Output of the sensor
Pin 3-VSS

PIC16F877A microcontroller. IC PIC16F877A is an 8-bit microcontroller with 8k×14-bit flash program memory, 368 bytes of RAM and many other extra peripherals like ADC, universal synchronous asynchronous receiver transmitter, master synchronous serial port, timers, compare capture and pulse-width modulation modules, and analogue comparators. It is based on the reduced instruction set computer (RISC) architecture.

The microcontroller processes the sensor output to compute the temperature in degree Celsius. The internal ADC of the microcontroller is used to convert the analogue output of the sensor into its equivalent digital value.

The internal ADC of the microcontroller has eight channels of analogue input and gives 10-bit digital output. In this project, the reference voltage to the ADC is the same as the supply voltage to the microcontroller, i.e., 5V. The resolution of the ADC can be calculated as follows:

Resolution = Vref / (1024-1) ...(as it is a 10-bit ADC)
                = 5/1023
                = 4.887 mV

It means that for 4.887mV change in the analogue input, the ADC output changes by binary ‘1’ with a reference voltage of 5V.

Analogue output of the sensor at its pin 2 is connected to Port A at RA0 for conversion into digital equivalent.


The LCD. A 16×2 LCD based on HD44780 controller is used for displaying the temperature. The control lines EN, R/W and RS of the LCD module are connected to pins RA1, RA2 and RA3 of Port A of the microcontroller, respectively. The commands and the data to be displayed are sent to the LCD module in the nibble mode from Port D of the microcontroller. The higher four bits of the LCD (D4 through D7) are connected to the lower nibble of Port D (RD0 through RD3).
Software description

The software code is written in ‘C’ language and compiled using Hitech C cross compiler in MPLAB IDE. The software performs the following operations in an infinite loop:

1. Initiate analogue-to-digital conversion and obtain the result

2. Calculate the equivalent voltage value from the ADC result

3. Calculate the temperature in degree Celsius from the voltage value

4. Display the temperature on the LCD

The voltage output (in volts) of the sensor is:

(ADC result × 5) /  1023

The temperature in degree Celsius is:

Sensor output × 1000 / 10  = Sensor output × 100

The Hitech C cross-compiler provides floating-point library support that is required for doing the above calculations.


MPLAB IDE and Hitech C compiler. MPLAB IDE is a very powerful software development tool for Microchip products (microcontrollers). It is available for download at www.microchip.com free of cost. It consists of tools like text editor, cross-assembler, cross-compiler and simulator.

Hitech C cross compiler is meant for Microchip PIC10/12/16 series of microcontrollers. Its Lite edition comes free with newer versions of MPLAB IDE like MPLAB v8.2 and v8.3. It can also be downloaded for free from www.htsoft.com.
Compiling the program using MPLAB IDE. The steps follow:

1. Create project file and add source files. In the menu bar, click Project→ Project Wizard. The project wizard dialogue box appears. Click ‘Next.’ In ‘Next’ window, select the device as PIC16F877A from the drop-down menu. Click ‘Next’ and select ‘Hitech Universal Tool’ suite from the drop down menu. Click ‘Next,’ name your project file as ‘tempr’ and specify its location. The file is automatically saved with ‘.mcp’ extension. Click ‘Next’ and add source files tempr.c, lcd.c and delay. c to your project. If you want to create the source files on your own, you can skip the above step. Click Next→ Finish button. Now your project is created and the source files are added to your project.
2. Create and add source files of your own. After creating the project, proceed with typing the code. Open a new text file by clicking ‘New’ in ‘File’ menu. Type the code in the text editor and save it with ‘.c’ extension. You can create source files tempr.c, delay.c and lcd.c in this manner. After typing and saving the code, you have to add the source files to your project. In ‘Project’ menu, click ‘Add Files to Project’ and then add the files by browsing them from the location they are saved in.
3. Configure the system. To configure features like type of oscillator and WDT, click ‘Configure’ menu and then click ‘Configuration Bits.’ In the configuration bits window, select the type of oscillator as XT, and disable all other features like watchdog timer, power-up timer and brownout detect.
4. Compile the project. To compile the software, click ‘Build’ option in ‘Project’ menu. The software is compiled and ‘Build Successful’ message appears in the output window. After successful compilation of the program, the file tempr.hex is generated.

Downloading the software into the chip. After compiling the software, the hex file generated can be downloaded into the chip either using a locally made programmer (like JMD programmer) or Microchip’s programming kit (PICKit2, PICKit3, ICD2, ICD3, etc).

We have used Microchip MPLAB ICD2 (in-circuit debugger) to burn the program into PIC16F877A microcontroller.

The programming can be done from MPLAB IDE itself by selecting the kit (MPLAB ICD2) from ‘Programmer’ menu in the menu bar. If you use a JMD programmer, the hex file can be downloaded into the chip using WinPic800 software. The configuration bits have to be separately configured in WinPic800.


RFID-Based Security System


A radio-frequency identification (RFID) based access-control system allows only authorised persons to enter a particular area of an establishment. The authorised persons are provided with unique tags, using which they can access that area.

The system is based on micro controller AT89C52 and comprises an RFID module, an LCD module for displaying the status and a relay for opening the door. Fig.1 shows a user trying to open the door by placing an RFID tag near the RFID reader.

Radio-frequency identification

 You might be familiar with RFID systems as seen in access control, contactless payment systems, product  tracking and inventory control, etc. Basically, an RFID system consists of three components: an antenna or coil, a transceiver (with decoder) and a transponder (RF tag) electronically programmed with unique information.
Fig.1 shows a typical RFID system. In every RFID system, the transponder tags contain unique identifying information. This information can be as little as a single binary bit or a large array of bits representing such things as an identity code, personal medical information or literally any type of information that can be stored in digital binary format. 
fig1
The RFID transceiver communicates with a passive tag. Passive tags have no power source of their own and instead derive power from the incident electromagnetic field. Commonly, at the heart of each tag is a microchip. When the tag enters the generated RF field, it is able to draw enough power from the field to access its internal memory and transmit its stored information. When the transponder tag draws power in this way, the resultant interaction of the RF fields causes the voltage at the transceiver antenna to drop in value. This effect is utilised by the tag to communicate its information to the reader. The tag is able to control the amount of power drawn from the field and by doing so it can modulate the voltage sensed at the transceiver according to the bit pattern it wishes to transmit.
Antenna. Fig.2 shows the internal diagram of a typical RFID antenna. An RFID antenna consists of a coil with one or more windings and a matching network. It radiates the electromagnetic waves generated by the reader to activate the tag and read/ write data from it.
fig2
Antennae are the conduits between the tag and the transceiver which control the system’s data acquisition and communication. These are available in a variety of shapes and sizes. Often, the antenna is packaged with the transceiver and decoder to become a reader, which can be configured either as a hand held or a fixed-mount device. The reader emits radio waves in ranges of anywhere from 2.54 cm (one inch) to 30 metres or more, depending upon its power output and the radio frequency used. When an RFID tag passes through the electromagnetic zone, it detects the reader’s activation signal. The reader decodes the data encode din the tag’s integrated circuit (silicon chip) and the data is passed to the host computer for processing.
Tags (transponders). Fig.3 shows the internal structure of a typical RFID tag. An RFID tag comprises a microchip containing identifying information and an antenna that transmits this data wirelessly to the reader. At its most basic, the chip will contain a serialised identifier, or licence plate number, that uniquely identifies that item, similar to the way many bar codes are used today.
fig3
There are three types of tags: active, passive and semi-passive.
Passive tags have no internal power source. These draw their power from the electromagnetic field generated by the RFID reader and then the microchip can send back information on the same wave. The reading range is limited when using passive tags.
Active transponders have their own transmitters and power source, usually in the form of a small battery. These remain in a low-power ‘idle’ state until they detect the presence of the RF field being sent by the reader. When the tag leaves the area of the reader, it again powers down to its idle state to conserve its battery. As a result, active tags can be detected at a greater range than passive tags.

Semi-passive tags have their own power source that powers only the microchip. These have no transmitter. They rely on altering the RF field from the transceiver to transmit their data.

There are three ways for data encoding into tags:

1. Read-only tags contain data, which is pre-written onto them by the tag manufacturer or distributor.

2. Write-once tags enable a user to write data to the tag one time in production mor distribution processes.

3. Full read-write tags allow new data to be written to the tag as needed and later other data can be rewritten over the original data.

RF transceiver. The RF transceiver is the source of the RF energy used to activate and power the passive RFID tags. It may be enclosed in the same cabinet as the reader or it may be a separate piece of equipment. When provided as a separate piece of equipment, the transceiver is commonly referred to as an RF module. The RF transceiver controls and modulates the radio frequencies that the antenna transmits and receives. The transceiver filters and amplifies the back-scatter signal from a passive RFID tag.
Circuit description

Fig.4 shows the circuit of the RFID based security system. The compact  circuitry is built around Atmel AT89C52 microcontroller. The AT89C52 is a low-power, high performance CMOS 8-bit microcomputer with 8 kB of Flash programmable and erasable read only memory (PEROM). It has 256 bytes of RAM, 32 input/output (I/O) lines, three 16-bit timers/ counters, a six-vector two-level interrupt architecture, a full-duplex serial port, an on-chip oscillator and clock circuitry. The system clock also plays a significant role in operation of the microcontroller.
fig4
An 11.0592MHz quartz crystal connected to pins 18 and 19 provides basic clock to the microcontroller. Power-on reset is provided by the combination of electrolytic capacitor C4 and resistor R1. Switch S1 is used for manual reset. Port pins P2.0 through P2.7 of the microcontroller are connected to data port pins D0 through D7 of the LCD, respectively. Port pins P3.7 and P3.6 of the microcontroller are connected to register-select (RS) and enable (E) pins of the LCD, respectively. Read/write  pin of the LCD is grounded to enable for write operation.

All the data is sent to the LCD in ASCII format for display. Only the commands are sent in hex form. Register-select (RS) signal is used to distinguish between data (RS=1) and command (RS=0). Preset VR1 is used to control the contrast of the LCD. Resistor R6 limits the current through the backlight of the LCD. Port pins P3.0 (RXD) and P3.1 (TXD) of the microcontroller are used to interface with the RFID reader.

When an authorised person having the tag enters the RF field generated by the RFID reader, RF signal is generated by the RFID reader to transmit energy to the tag and retrieve data from the tag. Then the RFID reader communicates through RXD and TXD pins of the microcontroller for further processing.

Thus on identifying the authorised person, port pin P3.2 goes high, transistor T2 drives into saturation, and relay RL1 energises to open the door for the person. Simultaneously, the LCD shows “access granted” message and port pin P1.7 drives piezobuzzer PZ1 via transistor T1 for aural indication.

If the person is unauthorised, the LCD shows “access denied” and the door doesn’t open. LED2 and LED3show presence of the tag in the RFID reader’s electromagnetic field.

To derive the power supply, the 230V, 50Hz AC mains is stepped down by transformer X1 to deliver a secondary output of 15V, 500 mA. The transformer output is rectified by a full-wave rectifier comprising diodes D1 through D4, filtered by capacitor C1 and regulated by ICs 7812 (IC2) and 7805 (IC3). Capacitor C2 bypasses the ripples present in the regulated supply. LED1 acts as the power indicator and R2 limits the current through LED1.

CODE: