▷ Programmable automatic air conditioning system with pic16f877a and lm35

Learn to design an automatic climate control system using the PIC16F877A microcontroller and the LM35 temperature sensor. This project will allow you to control heating or ventilation devices automatically based on the ambient temperature. Through programming the PIC, you can set temperature thresholds and adjust the system's behavior accordingly. Ideal for applications in smart homes and efficient environmental control systems.

MATERIALS:

  • 1 PIC16F877A
  • 1 LCD 2 x 16
  • 1 LM35 temperature sensor
  • 2 resistors of 220Ω
  • 4 resistors of 1.0 K Ω
  • 1 potentiometer of 10 K Ω
  • 2 LEDs
  • 1 4 MHz crystal oscillator
  • 2 ceramic capacitors of 22pF

WIRING DIAGRAM:

➤➤CIRCUIT FOR POWER STAGES

EXPLANATION OF THE PROJECT FUNCTIONING:

The objective of this project is to turn on a heater or a fan depending on the ambient temperature, that is, if it is too cold or too hot, depending on the case, a heater or a fan will automatically turn on.(In this case, we simulate the heater and the fan using only LEDs. To connect the heater and the fan, we will need to add a power stage), the minimum and maximum temperature values are adjustable and are stored in the EEPROM memory of the microcontroller.IN THE VIDEO YOU CAN SEE IN DETAIL HOW THE SYSTEM WORKS.. When starting the system, the following will appear on the LCD:

Here we can observe the minimum temperature, the current temperature, and the maximum temperature. To configure the minimum and maximum temperature values, we press the button (select).

Once the select button is pressed, the following appears on the LCD.

With the (+) button we increase the temperature value and with the (-) button we decrease it; by pressing the button again (select), we save the minimum temperature value in the EEPROM memory and go to the maximum temperature configuration menu.

With the (+) button we increase the value and with the (-) button we decrease it; by pressing the button again (select), we save the maximum temperature value in the EEPROM memory and return to the main menu.

CODE EXPLAINED:

'****************************************************************
'*  Name    : UNTITLED.BAS                                      *
'*  Author  : Esteban Carrillo - www.edeptec.com                *
'*  Notice  : Copyright (c) 2022                                *
'*          : All Rights Reserved                               *
'*  Date    : 02/02/2021                                        *
'*  Version : 1.0                                               *
'*  Notes   :                                                   *
'*          :                                                   *
'****************************************************************

;*---- Pines donde ira conectado el LCD ---*

DEFINE LCD_DREG PORTB 
DEFINE LCD_DBIT 0 
DEFINE LCD_RSREG PORTB 
DEFINE LCD_RSBIT 4 
DEFINE LCD_EREG PORTB 
DEFINE LCD_EBIT 5
;*------------------------------------------*

;-----------Parametros conversor Analogico/Digital--------------*
DEFINE ADC_BITS 10 ;Fijar número de BITS del resultado (5,8,10)
DEFINE ADC_CLOCK 3 ;Fijar EL CLOCK (rc = 3)
DEFINE ADC_SAMPLEUS 50 ;Fijar el tiempo de muestreo en Us
;ADC_SAMPLEUS es el número de microsegundos que el programa espera
;entre fijar el canal y comenzar la conversión analogica/digital.
;*--------------------------------------------------------------*
TRISA =%1 ;el puerto A.0 es de entrada
ADCON1 = %00001110 ;el puerto A.0 es conversor los demás son Digitales  
TRISD = %11100000

dato VAR WORD ;crear variable dato para guardar el valor de la temperatura actual
tempMin VAR BYTE; Variable para almacenar la temperatura minima programada
tempMax VAR BYTE; Variable para almacenar la temperatura maxima programada
x VAR BYTE; Variable para hacer una pausa con un ciclo for
g CON 223 ;g constante 223. Este es el ASCII de grados
calf VAR portD.3 ;nombres para los pines
vent VAR portD.4
enter VAR portD.5
botonBajar VAR portD.6
botonSubir VAR portD.7

EEPROM 0,[18,25] ;contenido inicial de la EEPROM. Temperatura inicial que se muestra en el LCD

inicio:
READ 0,tempMIN ;lee direccion 0 de la memoria EEPROM y lo guarda en tempMin
READ 1,tempMAX ;lee direccion 1 de la memoria EEPROM y lo guarda en tempMax

sensar:
    
    ADCIN 0, dato ;leer el canal 0 (A0) y guarde en dato
    LCDOUT $fe, 1,$fe, 2, "T.MIN T.ACT T.MAX" ;limpiar LCD y sacar texto
    dato = dato /128 ; el dato dividir para 128= C/AD de 9 bits
    LCDOUT $fe,$c6,DEC dato,g,"C" ;Display el decimal de dato(Temp Actual)
    LCDOUT $fe,$c0,DEC tempMin,g,"C" ;Display el decimal de tempMin
    LCDOUT $fe,$cc,DEC tempMax,g,"C" ;Display el decimal de tempMax

    FOR X = 0 TO 100 ;Pausa: Esta pausa es para evitar cambios bruscos de la Temp Actual
        IF enter =1 THEN grabar1a
            PAUSE 15
    NEXT


    IF dato < tempmin THEN calentar ;si dato es<tempMin ir a calentar
    IF dato > tempMAX THEN enfriar ;si dato es>tempMax ir a enfiriar
    
    LOW calf : LOW vent ;apagamos calefactor y ventilador

GOTO sensar ;continuar sensando

calentar:
    HIGH calf : LOW vent; Encendemos el calefactor
GOTO sensar

enfriar:
    HIGH vent : LOW calf; Encendemos el ventilador
GOTO sensar

grabar1a:

GOSUB soltar; ;programa antirrebote de tecla

grabar1:

; Aqui vamos a programar la temperatura Minima

    LCDOUT $fe, 1, $fe, 2, "PROGRAMAR TEMP:"
    LCDOUT $fe,$c0,"Minima = ",DEC tempMIN ,g,"C"
    PAUSE 100
    
        IF bOTONbajar=1 THEN restar1; Si presionamos el pulsador (-) nos vamos a restar
        IF bOTONsubir=1 THEN sumar1; Si presionamos el pulsador (+) nos vamos a sumar
        IF enter=1 THEN grabarA
    
GOTO grabar1

restar1:

    GOSUB soltar ;programa antirrebote de tecla
    IF tempMIN < 9 THEN grabar1 ; Limite minimo para la temperatura minima
    tempMIN= tempMIN -1 ; Restamos el valor de temMin
    
    GOTO grabar1
     
sumar1:

    GOSUB soltar
    IF tempMIN > 18 THEN grabar1 ; Limite maximo para la temperatura minima
    tempMIN= tempMIN + 1 ; Sumamos el valor de temMin
    
GOTO grabar1

grabarA:

    GOSUB soltar
    ; Grabamos el valor de la temperatura minima programada en la memoria EEPROM
    WRITE 0,tempMIN ;escribir en la dirección 0 de la EEPROM

grabar2: 

; Aqui vamos a programar la temperatura Minima

    LCDOUT $fe, 1, $fe, 2, "PROGRAMAR TEMP:"
    LCDOUT $fe,$c0,"Maxima = ",dec tempMAX ,g,"C"
    PAUSE 100
    
        IF bOTONbajar=1 THEN restar2
        IF bOTONsubir=1 THEN sumar2
        IF enter=1 THEN grabarB
        
GOTO grabar2

restar2:

    GOSUB soltar
    IF tempMAX < 24 THEN grabar2 ; Limite minimo para la temperatura maxima
    tempMAX= tempMAX -1
    
GOTO grabar2

sumar2:

    GOSUB soltar
    IF tempMAX > 40 THEN grabar2 ; Limite maximo para la temperatura maxima
    tempMAX= tempMAX + 1
    
GOTO grabar2

grabarB:

    GOSUB soltar
    ; Grabamos el valor de la temperatura minima programada en la memoria EEPROM
    WRITE 1,tempMAX;escribir en la dirección 1 de la EEPROM
    
GOTO inicio

soltar: ;programa antirrebote de tecla

soltar2:

    IF bOTONbajar=1 THEN soltar2
    IF bOTONsubir=1 THEN soltar2
    IF enter=1THEN soltar2
    PAUSE 100
    
RETURN

DOWNLOAD THE CODE AND SIMULATION HERE:

0/Leave a comment/Comments

Hello! We're so glad you've made it this far and are reading this article on Edeptec.

This form is an open space for you: you can leave a comment with your questions, suggestions, experiences, or simply your opinion on the topic discussed.

» Did you find the information helpful?
» Do you have any personal experiences you'd like to share?
» Do you have any topics you'd like to see covered in future articles?

Remember that this space is for learning and sharing, so we encourage you to participate respectfully and constructively. Your comments can help other readers who are on the same path, whether in electronics, programming, sports, or technology.

Thank you for being part of this learning community! Your participation is what makes this project grow.