How to interface Temperature controller module in C and Assembly Language code?

www.spiroprojects.com
This is simple experiment, where we have to connect temperature sensor module with 8051 microcontroller. Actual IC could be P8951RD2 also.  As temperature is physical quantity, it can be measured in analog only. We need some sensor which sense temperature. Then we have to process this value by Analog to Digital converter. We can use LM35 as temperature sensor. We will use one ADC0808 IC which will convert analog value of temperature in to digital for 8051  micro-controller. Below Fig 1 shows LM35 in IC form.
 
  The LM35 series are precision integrated-circuit temperature devices with an output voltage linearly-proportional to the Centigrade temperature. The LM35 device has an advantage over linear temperature sensors calibrated in Kelvin, as the user is not required to subtract a large constant voltage from the output to obtain convenient Centigrade scaling. The LM35 device does not require any external calibration or trimming to provide typical accuracies of ±¼°C at room temperature and ±¾°C over a full −55°C to 150°C temperature range. Lower cost is assured by trimming and calibration at the wafer level.
The famous LM35 linear temperature sensor is very useful to sense ambient/environment temperature. This sensor is produced by National Semiconductor Corporation and offers a functional range between -40 degree Celsius to 150 degree Celsius. Sensitivity is 10mV per degree Celsius. The output voltage is proportional to the temperature. The output is linear to the temperature in degree Celsius and has high stability. The power supply required is 5V.
 
   Fig 1 LM35 with three pin, you can bring heating element near to this sensor, Output pin will show some voltage.

The output of the LM 35 is 10 mV (0.01 volts) per degree Celsius. This means at 20°C we will get 20 x 0.01 = 200 mV, or 0.2 volts.

At 100°C we will get 100 x 0.01 =  1.0 volts out.
At 50°C  we will get   50 x 0.01 =  0.5v

Our temperature controlling module is not having LCD, we are controlling temperature trough Relay. Small bulb is connected in front of LM35 IC. P3.7 is connected  EOC (End of Conversion) signal of  ADC0808 IC. Fig 2 shows front end of Temperature controlling module.

 
                         Fig 2: Temperature control System Using Relay (Front side of module)


                                         Fig 3: Back side of temperature controlling Module

Before  going for coding part, lets see some details of ADC0808 IC.



ADC0808 is an 8 bit analog to digital converter with eight input analog channels, i.e., it can take eight different analog inputs. The input which is to be converted to digital form can be selected by using three address lines. The voltage reference can be set using the Vref+ and Vref- pins. The step size is decided based on set reference value. Step size is the change in analog input to cause a unit change in the output of ADC. The default step size is 19.53mV corresponding to 5V reference voltage. ADC0808 needs an external clock to operate unlike ADC0804 which has an internal clock. The ADC needs some specific control signals for its operations like start conversion and bring data to output pins. When the conversion is complete the EOC pins goes low to indicate the end of conversion and data ready to be picked up.
We are using IN2 channel of ADC to connect to LM35. LM35 sensor is sending data to IN2 channel of ADC. But we should know, how to “start” and “stop” ADC0808 works on particular pulse width of handshaking signals. Before going for coding, it is good to refer timing diagram of ADC0808 on “EngineersGrage website.  
You can type following code in the Keil version 2 or version 4. We are using Port 3 of 8051 microcontroller as handshaking purpose. We are also using P1 port for inputting value of ADC0808 IC. Pin P3.1 is used as Enable pin. P3.2 is connected to ALE signal of ADC0808.  P3.4 is connected START signal of ADC. P3.5 is connected to OE pin of ADC0808. P3.6 is connected to Relay.
Once we understand connection of Temperature module with 8051 microcontroller. We can easily understand C code.  Before going inside super loop of code, we are initializing initial things. Below code snippet declaring P1 as input port ad EOC HIGH and ALE,START,OE are “NULL”.

        P1=0xff;                          //P1 acts as an input port, reads the value of ADC
        EOC=1;
        ALE=0;
        START=0;
        OE=0;

Now we are ready to go in the super-loop. We are initailiaiz ADC0808 by following code:
ADDR_C=0;
                                    ADDR_B=1;
                                    ADDR_A=1;
We are starting ADC conversion, sending  HIGH to LOW pulse on START signals. In between we are call delay() function to maintain proper Pulse width. This pulse width should be correct according to the Data sheets of ADC0808. “Mybyte” is variable to collect data from ADC0808 to 8051. This is digital value, we are storing in “mybyte”. To maintain room temperature, we using following instruction:
  mybyte=mybyte-35;

This is for calibration. Small bulb is increasing heat of LM35 sensor, whenever Temperature cross more than 40 degree Celsius, microcontroller do “Relay OFF” Here our assumption is “ACTIVE LOW” logic. You can see code how “mybyte” value drive Relay. If you want to check temperature value by multi-meter, you can put multi-meter probe with “GND” and Yellow color knob in the module.
 


 
Previous
Next Post »

1 comments:

Write comments
Unknown
AUTHOR
December 28, 2017 at 2:37 PM delete

send me its files ar arlan.yousaf@gmail.com

Reply
avatar