This articles explains you to interface 2 microcontrollers through serial port. 2 Atmega16 microcontrollers are used here.

The microcontroller 1 has an temperature sensor, it reads the temperature through the ADC and send the data to the microcontroller 2 through the serial port.

The microcontroller 2 reads the data through its serial port and if the the temperature is below than 20deg then the heater is switched on and if the temperature is greater than 30deg then the fan is switched on. While the temperature is in between 20-30deg then both the heater and fan is kept in off position.

An Proteus simulation file is also added at the download.

Circuit diagram

Bascom code for microcontroller 1

$regfile = "m16def.dat"
$crystal = 8000000
$baud = 28800
Config Adc = Single , Prescaler = Auto
Config Portb = Input
Dim A As Word , B As Byte
Cursor Off
Start Adc
Do
A
= Getadc(0)
A
= A / 2
Locate 1 , 1
Printbin A
Waitms 25
Loop
End

Bascom code for microcontroller 2

$regfile = "m16def.dat"
$crystal = 8000000
$baud = 28800
Config Portb = Output
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , Rs = Portb.0 , E = Portb.1
Dim A As Word , B As Byte
Cls
Cursor Off
Do
Home
A
= Waitkey()
Locate 1 , 1
Lcd "Temp : "
Lcd A
If A < 20 Then
     
Portb.2 = 0
     
Portb.3 = 1
     
Locate 2 , 1
     
Lcd "Heater ON       "
     
Waitms 150
Elseif A => 20 And A <= 30 Then
        
Portb.2 = 0
        
Portb.3 = 0
        
Locate 2 , 1
        
Lcd "Fan,Heater: OFF"
        
Waitms 150
Elseif A > 30 Then
        
Portb.3 = 0
        
Portb.2 = 1
        
Locate 2 , 1
        
Lcd "Fan ON           "
        
Waitms 150
End If
Loop
End

Download