LM35 sensor de temperatura (datasheet). Actualmente en muchos países la intensidad de calor solar alcanza niveles muy altos, esto puede llegar hacer insoportable. Debido a esta situación es que en las oficias o casas se necesita un sistema de control de temperatura como por ejemplo: aire acondicionado.
El chip LM35 es un sensor de temperatura y es el ideal para para los proyectos de medición y control de temperatura ambiente. Además, este sensor es de bajo coste, requiere pocos componentes adicionales para su uso, rango de medición aceptable y fácil manipulación y/o control. Su rango de medición es de -55°c hasta +125°c, posee un factor de escala lineal de +10mV/°C, una precisión de 0.5°C y puede operar a +4Vdc hasta +30Vdc.
El sensor de luz LDR (resistencia dependiente de luz – datasheet), también conocidos como foto-resistencias. Esta resistencia varia dependiendo de la intensidad de luz y puede utilizarse en proyectos donde se necesite medir si es de día o noche y poder así activar relay.
CARACTERÍSTICAS LM35
- Directamente calibrada en grados Celsius (centígrados)
- Lineal + 10 mV / ° C Factor de Escala
- 0,5 ° C Precisión asegurada (a 25 ° C)
- Rango de medición -55°C a 150°C
- Funciona con 4Vdc a 30Vdc
APLICACIONES DEL SENSOR LM35
- Fuentes de alimentación.
- Gestión de baterías.
- HVAC.
- Accesorios.
APLICACIONES DE LDR
- Regulador de luz automático.
- Control de luz nocturna.
- Control de luz de interiores y exteriores.
- Colorímetro.
- Densidad de toner.
CIRCUITO DE CONEXIÓN PIC16F1829 CON LM35 Y LDR
EJEMPLO LM35 + LDR CON PIC16F1829
En el siguiente ejemplo se muestra como leer el sensor LM35 y una foto-resistencia a través del ADC del microcontrolador y estos 2 valores se mostrarán en un display 7 segmentos controlador con el driver max7219.
Código principal MAIN.
#define _XTAL_FREQ 32000000
#include
#include "fuses.h"
#include "max7219.h"
#include "adc.h"
unsigned char lm35[4];
unsigned char ldr[4];
void main(void) {
OSCCON = 0b11110010; // PLLEN=1(x4), IRCF=8Mhz, SCS=OSC_INTERNAL
adc_Config(10);
max7219_Config();
max7219_WriteDp(1,1);
max7219_WriteDp(1,5);
while (1) {
//Sensor de Luz LDR
float luz = adc_Read(1);
luz = luz * 5.0 / 1023.0;
ldr[0] = ((char) luz) / 10;
ldr[1] = ((char) luz) % 10;
luz = (luz - (char) luz)*100;
ldr[2] = ((char) luz) / 10;
ldr[3] = ((char) luz) % 10;
max7219_WriteDigito(4, ldr[0]);
max7219_WriteDigito(5, ldr[1]);
max7219_WriteDigito(6, ldr[2]);
max7219_WriteDigito(7, ldr[3]);
//Temperatura LM35
float temp = adc_Read(0);
temp = temp * 500.0 / 1023.0;
lm35[0] = ((char) temp) / 10;
lm35[1] = ((char) temp) % 10;
temp = (temp - (char) temp)*100;
lm35[2] = ((char) temp) / 10;
lm35[3] = ((char) temp) % 10;
max7219_WriteDigito(0, lm35[0]);
max7219_WriteDigito(1, lm35[1]);
max7219_WriteDigito(2, lm35[2]);
max7219_WriteDigito(3, lm35[3]);
__delay_ms(20);
}
return;
}
Librería ADC.
#ifndef ADC_H
#define ADC_H
unsigned char resol = 8;
void adc_Config(unsigned char);
unsigned int adc_Read(unsigned char);
void adc_Config(unsigned char _resol) {
//ADC SETUP
if (_resol == 8) {
ADCON1bits.ADFM = 0;
} else if (_resol == 10) {
ADCON1bits.ADFM = 1;
} else {
return;
}
resol = _resol;
ADCON1bits.ADCS = 0b110;
ADCON1bits.ADNREF = 0;
ADCON1bits.ADPREF = 0;
ADCON0bits.ADON = 1;
}
unsigned int adc_Read(unsigned char channel) {
if (channel > 11 || (resol != 8 && resol != 10)) {
return 1;
}
if (channel < 3) {
ANSELA |= 1 << channel;
TRISA |= 1 << channel;
} else if (channel < 4) {
channel += 1;
ANSELA |= 1 << channel;
TRISA |= 1 << channel;
} else if (channel < 8) {
channel -= 4;
ANSELC |= 1 << channel;
TRISC |= 1 << channel;
} else if (channel < 10) {
channel -= 2;
ANSELC |= 1 << channel;
TRISC |= 1 << channel;
} else if (channel < 12) {
channel -= 6;
ANSELB |= 1 << channel;
TRISB |= 1 << channel;
}
ADCON0bits.CHS = channel;
__delay_ms(1);
ADCON0bits.GO = 1;
while (ADCON0bits.GO);
if (resol == 8) {
return ADRESH;
} else if (resol == 10) {
return ((ADRESH << 8) + ADRESL);
}
return 1;
}
#endif /* ADC_H */
Librería MAX7219.
#ifndef MAX7219_H
#define MAX7219_H
#define pinDIN_TRIS TRISBbits.TRISB5
#define pinCLK_TRIS TRISBbits.TRISB7
#define pinLOAD_TRIS TRISBbits.TRISB6
#define pinDIN_LAT LATBbits.LATB5
#define pinCLK_LAT LATBbits.LATB7
#define pinLOAD_LAT LATBbits.LATB6
// MAX7219 Registers
#define MAX7219_NOP 0x00
#define MAX7219_DIG1 0x01
#define MAX7219_DIG2 0x02
#define MAX7219_DIG3 0x03
#define MAX7219_DIG4 0x04
#define MAX7219_DIG5 0x05
#define MAX7219_DIG6 0x06
#define MAX7219_DIG7 0x07
#define MAX7219_DIG8 0x08
#define MAX7219_DECODE 0x09
#define MAX7219_INTENSITY 0x0A
#define MAX7219_SCAN_LIMIT 0x0B
#define MAX7219_SHUTDOWN 0x0C
#define MAX7219_TEST 0x0F
static const unsigned char digitos[10] = {
// XABCDEFG
0b01111110, // 0
0b00110000, // 1
0b01101101, // 2
0b01111001, // 3
0b00110011, // 4
0b01011011, // 5
0b01011111, // 6
0b01110000, // 7
0b01111111, // 8
0b01111011 // 9
};
unsigned char enable_dp = 0, digit_dp = 0;
void max7219_Config(void);
void max7219_Intensity(unsigned char);
void max7219_WriteDigito(unsigned char, unsigned char);
void max7219_WriteDp(unsigned char, unsigned char);
void max7219_WriteBits(unsigned int);
void max7219_WriteComando(unsigned char, unsigned char);
void max7219_Config(void) {
pinDIN_TRIS = 0;
pinCLK_TRIS = 0;
pinLOAD_TRIS = 0;
pinDIN_LAT = 0;
pinCLK_LAT = 0;
pinLOAD_LAT = 1;
max7219_WriteComando(MAX7219_SHUTDOWN, 0x00);
max7219_WriteComando(MAX7219_TEST, 0x00);
max7219_WriteComando(MAX7219_INTENSITY, 0x0F);
max7219_WriteComando(MAX7219_SCAN_LIMIT, 0x07);
max7219_WriteComando(MAX7219_SHUTDOWN, 0x01);
}
void max7219_WriteDigito(unsigned char digit, unsigned char valorDeDigito) {
volatile unsigned int temporal = 0;
volatile unsigned int dp = 0;
if (digit > 7) {
return;
}
if ((digit_dp)&(1 << digit)) {
dp = 0x80;
} else {
dp = 0;
}
temporal = digit + 1;
temporal = temporal << 8;
temporal = temporal & 0x0F00;
temporal = temporal | (digitos[valorDeDigito] + dp);
max7219_WriteBits(temporal);
}
void max7219_Intensity(unsigned char value) {
if (value < 16) {
max7219_WriteComando(MAX7219_INTENSITY, value);
}
}
void max7219_WriteDp(unsigned char en, unsigned char numDigit) {
if (en) {
digit_dp |= 1 << numDigit;
} else {
digit_dp &= ~(1 << numDigit);
}
}
void max7219_WriteBits(unsigned int valor) {
volatile unsigned int temporal = 0;
volatile unsigned char c = 0;
pinLOAD_LAT = 0;
for (c = 0; c < 16; c++) {
temporal = 1;
temporal = (temporal << (15 - c));
if ((temporal & valor) != 0) {
pinDIN_LAT = 1;
} else {
pinDIN_LAT = 0;
}
pinCLK_LAT = 1;
__delay_us(1);
pinCLK_LAT = 0;
}
pinLOAD_LAT = 1;
}
void max7219_WriteComando(unsigned char comando, unsigned char valorDeComando) {
volatile unsigned int temporal = 0;
temporal = comando;
temporal = temporal << 8;
temporal = temporal & 0x0F00;
temporal = temporal | valorDeComando;
max7219_WriteBits(temporal);
}
#endif /* MAX7219_H */
Librería FUSES
#ifndef FUSES_H
#define FUSES_H
// CONFIG1
#pragma config FOSC = INTOSC // Oscillator Selection (INTOSC oscillator: I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = OFF // MCLR Pin Function Select (MCLR/VPP pin function is digital input)
#pragma config CP = ON // Flash Program Memory Code Protection (Program memory code protection is enabled)
#pragma config CPD = ON // Data Memory Code Protection (Data memory code protection is enabled)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
#pragma config IESO = ON // Internal/External Switchover (Internal/External Switchover mode is enabled)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable (Fail-Safe Clock Monitor is enabled)
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = ON // PLL Enable (4x PLL enabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LVP = ON // Low-Voltage Programming Enable (Low-voltage programming enabled)
#endif /* FUSES_H */
Deja una respuesta
Lo siento, debes estar conectado para publicar un comentario.