Pages

Web-Monitored Thermostat

Web-Monitored Thermostat



            Imagine being able to monitor the status of a given room or area from anywhere in the world, at anytime.  In today’s booming technological atmosphere, this dream doesn’t sound so far off.  However, imagine being able to do this cheaply, while not sacrificing efficiency and functionality.  Our microcontroller web-monitored thermostat does exactly this.  It offers flexibility and functionality at a very low cost. 
While conceiving our final project idea, we thought of many applications where a thermostat could be remotely monitored using a serially connected web-server.  Food businesses or warehouses would be able to continually monitor temperature histories as well as possible problematic conditions that could potentially destroy their inventory.  Dense computer labs utilizing millions of dollars of high-end computer equipment need to be carefully temperature controlled.  Wouldn’t it be helpful if the lab administrator could monitor the lab’s environment as well as its individual computer conditions?

Our web-monitored thermostat continually monitors a room temperature, and using the power of Matlab, sends this information to a web server for posting on the Internet.  Simultaneously, the device compares the current temperature to some temperature threshold, which the user sets, to determine if a fan should be turned on.  The device’s feature set is completely flexible and very easily changed through software and minor hardware changes as per customer need basis.

            Our thermostat uses the Atmel AT90s8535 microcontroller to control and interface the devices involved. Our main objective was to accurately measure room temperature.  We achieved this using National Semiconductor's LM35  temperature sensor chip, which outputs some voltage based on the temperature in Celsius.  The microcontroller analyzes this voltage using its Analog to Digital Converter, and displays this temperature on the LCD.  Simultaneously, the current temperature and fan status is outputted via the Universal Asynchronous Receiver and Transmitter (UART) to be interfaced with Matlab and sent to a web server for output on the Internet.  At any time in this process, the threshold temperature can be changed by the press of a pushbutton.  This  will make Matlab prompt the user for a new threshold, and the input is sent back to the microcontroller via the UART.

            We designed our device to work at a range of 0 degrees Celsius to 150 degrees Celsius.   The specification for the LM35 chip says that for every degree Celsius the chip measures, the output voltage will be 10mV, and that the device is accurate to +/- .5 degrees.  We used a reference voltage of 2.55 Volts on the Analog to Digital Converter to ensure an 8-bit temperature for simplicity, and to ease the mathematical calculations necessary to convert the digital input to a hexadecimal temperature.  The math required came down to a simple shift.  We simply shifted the digital 10-bit input by 2 to the right, resulting in a division by 4. For example, if our input is 512, we would divide by 4 and get a temperature of 128 degrees.

            The microcontroller polls for a new temperature about once every second, and then outputs it to Matlab and the LCD.  Matlab will then analyze the input from the UART and format HTML for viewing on the web.  Every 5 readings, a history graph is updated on the web.  This history graph contains up to 20 data points, with each data point containing the precise time that the data was recorded, and the temperature reading.  The web page also shows the status of the cooling fan through text and an animated graphic.
            
The threshold temperature defaults to 25 degrees Celsius. If the user wants to change this, a pushbutton must be held down.  Matlab will prompt the user for the threshold temperature, and the updated threshold will be displayed on the LCD along with the current temperature.

           Program/hardware design
            Our assembly code revolves around a simple loop. Before the loop, the program sets up a handshake with the web-server to ensure synchronization.  Then the program enters the main loop, which acts as a task scheduler.  Here is the pseudo-code:
 main:
  •             Get temperature
  •             Send temperature to LCD and temperature, fan status and button status to UART
  •             Check for button press
  •             Get new threshold
  •             Set fan status
goto main
            Get_temperature reads the digital input from the ADC and shifts the 10 bit input into 8 bits. This hexadecimal temperature is then sent to Ana_to_LCD to get displayed on the LCD and sent to the UART for Matlab interception.     Check for button press does exactly that.  If the pushbutton to signal a change in threshold is pressed, this routine will record this action and Get_new_threshold will ask Matlab for a new one using a blocking polling UART send/receive routine. Finally, Set_fan_status compares the current temperature with the threshold temperature to determine if the fan should go on or off.  If the temperature equals the threshold or above, the fan will turn on. If the temperature is below the threshold, the fan will go off. See appendix - Final.asm for this code and the rest.

            We utilized 2 interrupt service routines.  Timer 0 overflow was used for miscellaneous timing features, like intermittent delays for the LCD code.  Timer 1 compare match A was used to turn the ADC Start Conversion bit on once per second, ensuring that at the very next time the loop got to Get_temperature after the interrupt, it would know to start the conversion and get the new current temperature.  

We had to continuously convert hexadecimal temperature to ASCII digits for output to the LCD and to Matlab. This was done by subtracting 100 continuously to find the hundreds digit, subtracting 10 continuously to find the tens bit, and the slack would be the ones bit.

            Matlab itself does not include an API for interfacing with a serial port.  We instead used a toolbox called CPort, found on the MathWorks website and written by Eyal Doron.  Cport included all the necessary routines for opening ports, setting up ports (9600 baud, 8 bits, 1 stop bit, no parity, etc.), sending characters, and receiving characters. We used a simple GUI to have the user enter the threshold temperature.  The Matlab code constantly looks at the input stream from the UART and decides if there is some error in the bitstream. If an error is detected or a CTRL-C is detected, the program will exit.

 Here is an example bitstream:
t    0    2    5   0   0
The t is used as a synchronization character. The next three characters are the current temperature.  The fifth character is a fan status bit 1 for on, 0 for off.  The sixth bit is a button status bit.  Was the button recently pressed? 0 for off, 1 for on.

            Every 5 data points, the Matlab code will update the time vs. temperature plot, output it to a JPEG image file, and update the web page’s graphic file. Each time the current temperature is updated, the code updates the HTML with the new statistics.  We picked every 5 times because the Matlab conversion from a figure to a JPEG graphic file is very processor intensive, and we found that it served as a bottleneck for the whole device operation.

            When the button is pressed, Matlab asks for a threshold, and sends it to the microcontroller. The format is simply the three characters of the threshold temperature in the normal ASCII format. The microcontroller processes this input and then for handshaking purposes outputs a 'g' to the UART to tell the web server that all is ready to be started once again.

            To trigger the fan on from a port pin, we used a simple power transistor (TIP31C) configuration, where the motor was connected to a 12 volt source and the collector of the BJT.  The port pin first went through a 1k ohm resistor, which was then fed into the base of the BJT. The emitter was tied to ground.  We also included a diode across the motor to protect the port pin from damage.

            Although we suffered the usual pitfalls along the way, in the end everything turned out well.  We accomplished all of our goals of integrating the computer serial interface with the microcontroller, and merging the microcontroller hardware with some analog circuitry and a computer hardware/software interface.  We found the temperature was usually near 1 degree accuracy, which is not too far from the LM35 specifications.  The web interface was a bit slow in the beginning, mostly because we were updating the time vs. temperature plot to a JPEG every time there was new input.  Setting this to every 5 points helped much, and this setting can be tweaked even further for better performance.  The CPort interface was a bit difficult to get working in the beginning since every time we went to read from the serial port, Matlab would crash and bring Windows down with it! As we discovered later, this was due to a timeout setting. This timeout setting controls how long the interface looks for a character from the UART, and by default the timeout is forever. Setting this value to something reasonable like 10ms worked well.  Also, CPort was attempting to do DTR flow control and handshaking by default, and turning that off in CPortconfig was a necessity.

We spent many hours trying to get a keypad working on Port B, so that the user could also enter the threshold temperature locally.  We had very sporadic problems, apparently because of slight differences with Port B than the other Ports.  For instance, only the first row of the keypad would respond to press.  If we had to do this again, we would take the 8535 chip off the developer board and connect the keypad directly to the chip with minimal hardware in between.  We couldn’t use Port A since we were using the Analog input port for the temperature probe, and we needed all 8 pins for the keypad.  We couldn’t use Port D since the UART uses pins D0 and D1 for receive and transmit. Finally, Port C was being used by the LCD screen, so we were out of ports.  Maybe a better thing to do next time would be to use a chip with more ports.

Instead of using Matlab, we would use a C interface with Linux.  This way we would easily be able to run CGI scripts and the web server.  Also, the C interface would have been less clunky then Matlab’s entire program interface, since we wouldn’t have to have Matlab open.

If we had more time, we would have liked to have the user be able to enter a new threshold from the web page.  This would require some sort of CGI script and ftp interface, and we have never used either so we would have had to learn it in detail. 

Assembly Code:
Final.asm - This is the assembly code.
AT90s8535 Include File - Standard include file for Atmel AT90s8535
Matlab Code:
TempInput.m - The main matlab interface.
Get_threshold.m - The matlab GUI interface for input
Get_value.m - Processes input from the GUI
UpdateHTML.m - Updates the html file output
UpdateTempGraph.m - Updates the time vs. temperature graph

Figure 1:  A Picture from above of the setup
Figure 2: The display of the current temperature (left) and the threshold temperature (right)
  Figure 3: The input GUI control box from Matlab

Figure 4: Global Block Representation
Figure 5: Power Transistor Based Electronic Relay

0 comments:

Post a Comment

Share your knowledge

Related Posts Plugin for WordPress, Blogger...

Popular Projects

program for Dual DAC 8051 Microcontroller Based DC Motor Control A Microcontroller Based Turbidity Meter A m -Controller Based Thermostat ASCII to BCD conversion in 8051 AT90LS8515 Digital Message Machine Audio Frequency Response Analyzer Audio Homing Robot Automated Juice Mixer Automated Pet Feeder Autonomous Car Autonomous Parallel Parking RC Car Autonomous Search Robot Autonomous Tank Autonomous Vehicle Contrast Following Rover Autonomous navigating robot BCD number to ASCII in 8051 Balance Bot Blind Bot Blood Pressure Monitor Bloodshed Dev-C++ 5 Compiler/IDE Breath Alcohol Tester Converters on TI MSP430 CrossStudio MSP430 IDE Design of a Real-Time Digital Guitar Tuner Digital Oscilloscope Digital Stethoscope Digital clock project using PIC16C54A microcontroller Digital thermometer ECG monitoring system GPS Data Logger with Wireless Trigger Handwriting Recognition Systm Home Security System Home energy managment IAR Embedded Workbench IDE INFRARED TRACKING SYSTEM IntelliBOT Laser Communications System Line following van MSP-EXP430FG4618 Development Tool and the eZ430 kits MSP430FG4618 device implement a Buzzer tone generator MSP430FG4618 device implement a Real Time Clock MSP430FG4618 device implement a voltage ramp generator MSP430FG4618 device present a message on the LCD Basic Microcontroller(8051) Lab Mivo- RFID based mobile payment system Multi-Zone Fire Alarm System PC based temperature control PIC 16f877 RPM Meter PIC16C54 dual dice electronic project circuit PIC16F84A digital thermometer microcontroller project PIC16F886 horn driver PWM motor contoller with MSP430 Program Block data transfer in 8051 Program to add two BCD numbers in 8051 Program to check whether a 4th bit of a byte is 1 Program to convert ASCII to hex in 8051 Program to count from 0-9 in 8051 Program to count number of 1's in a given data byte in 8051 Program to divide an 8 bit no by another 8 bit number in 8051 Program to find largest of n numbers in 8051 Program to find the LCM of two numbers in 8051 Program to find the square of an 8 bit number in 8051 Program to generate 50msec delay in 8051 Program to implement BCD counter to count from 0-99 in 8051 Program to implement BCD counter to count from 99-0 in 8051 Program to interchange two blocks of data in 8051 Program to multiply 16 bit number by 8 bit number in 8051 Program to search an element in an array in 8051 Program to sort an array of 10 elements in 8051 Programming the ez430 Proximity Security System RAMP wave in 8051 RC Car Controller RObo Dog Radio-controlled Truck Retina color tracker Robotic Arm Controller with GUI Robotic Car Traction Control Safety-sensor vehicle Security Entrance System Self-Powered Solar Data Logger Snake Arm Ultrasonic Positioning Control System Store FFh if 1 Super Train Controller TI MSP430 Microcontrollers Timers on the MSP430 TouchPad Drawing Board Ultra-Sonic Parking Assistant Ultrasonic Parking Controller Ultrasonic Range finder Voice Activated Alarm Clock Voice Recognition Robotic Car Voting Machine Weather Station Web-Monitored Thermostat Wireless Drawing Device Wireless Telemetry Wireless message Communicator Write a C program to display the code of the key pressed in 8051 Zigbee Wireless Relay Control and Power Monitoring System add two multibyte numbers in 8051 convert a decimal number to hex number in 8051 convert an 8bit Hex number to decimal number in 8051 convert hex number to ASCII number in 8051 eZ430-F2013 Development Tool use SD16_A ADC eZ430-RF2500 Development Tool use ADC10 else store 00 in the same location in 8051 find the GCF of two numbers in 8051 find the average of 10 numbers in 8051 generate Fibonacci series in 8051 metal detector project microcontroller using IAR Embedded Workbench program for Elevator Interface in 8051 program for Stepper motor interface in 8051 spectrum analyser square wave in 8051 triangle wave in 8051 voice recognition security system

Sites U missed

Hint

Open Pictures in new page by right click on it, if it is not shown full image.