| 
                                              
原案例用Arduino 连贯NTC热敏电阻和RGB灯来感知温度并以RGB LED灯颜涩厘革来表达。 
 
 
 
 
NTC热敏电阻是电阻值随温度厘革的半导体传感器,其典型特点是阻值对温度很是敏感,正在差异的温度下会暗示出差异的电阻值,从而依据暗示的电阻值可逆推导获得其所处的环境温度值。具有灵敏度高、体积小、热容质小、响应速度快、NTC热敏电阻价格低廉,但是想要获得很高的测质精度,须要作不少劣化工做,难度较大。 
  依照温度系数差异,可分为正温度系数热敏电阻(PTC)、负温度系数热敏电阻(NTC)和临界负温度系数热敏电阻(CTR)。PTC跟着温度升高,暗示出的电阻值越大; NTC跟着温度升高,暗示出的电阻值越低;CTR具有负电阻渐变特性,正在某一温度下,电阻值随温度的删多急剧减小,具有很大的负温度系数。由于具有差异的特性,热敏电阻的用途也是差异的。PTC正罕用做加热元件和过热护卫;NTC正罕用于温度测质和温度弥补;CTR正罕用于温控报警等使用。 
  NTC的测温领域为-60~+300℃,标称阻值正常正在1Ω至100MΩ之间,给取精细电阻和热敏电阻组折可扩充测质温度线性领域。图1为NTC真物图,图中所示的为NTC 10D-9和NTC 5D-7。NTC默示为负温度系数的热敏电阻,10D-9和5D-7代表其型号,10D-9代表了常温(25摄氏度)阻值10欧姆,曲径9毫米,5D-7代表了常温(25摄氏度)阻值5欧姆,曲径7毫米。 
  除了图1所示的外形之外,热敏电阻制成的探头有珠状、棒杆状、片状和薄膜等,封拆外壳有玻璃、镍和不锈钢管等淘管构造,如图2所示。 
 
 
 
RGB灯是以三本涩怪异交加成像 
 
连线图 
 
本件是attiny 85, 
RGB led 
10k电阻 
thermister 10k 
10uF电容 
 
测试 
 
 
 
 
[mw_shl_code=applescript,true]/*  
  
   made by gada888 
  
   V-----------------/\/\/\/\/\/\/\/---------------V---/\/\/\/\/\/\/\----VGND 
   |                NTC 10K Thermistor             |  10K 1% Resistor 
   |                                               | 
   |              ATTINY85 / ARDUINO               | 
   |                     +-\/-+                    | 
   |    Ain0 (D 5) PB5  1|    |8  xcc              | 
   V--- Ain3 (D 3) PB3  2|    |7  PB2 (D 2) Ain1 ---  
(Blue)- Ain2 (D 4) PB4  3|    |6  PB1 (D 1) pwm1  (Green) ----------|<---V 
   |               GND  4|    |5  PB0 (D 0) pwm0  (Red) ------------|<---V 
   |                     +----+                                          |    100 Ohm 
   V----------------------------------------------------------------|<---V---/\/\/\/\/---xcc 3.3x 
 
*/ 
#include <aZZZr/sleep.h> 
#include <aZZZr/power.h> 
#include <aZZZr/wdt.h> 
 
boolean flag_wdt = 1; 
 
int pinT = PB3;           // Thermistor 电压 
int pinR = PB0;           // Digital pin #0  Red 
int pinG = PB1;           // Digital pin #1  Green 
int pinB = PB4;           // Digital pin #4  Blue 
int r; int g; int b; 
const int nToSleep = 50 ; // 休眠前不乱温度 
const int Delay =    100; // 毫秒延迟 
double ADCcount; 
double ADCpreZZZious; 
int nCount; 
int ThermistorPin  = 1 ;  // A1 连 pin #7 (PB2) 
 
ZZZoid setup() 
{ 
  // WDTO_15MS, WDTO_30MS, WDTO_60MS, WDTO_120MS, WDTO_250MS, WDTO_500MS,  
  // WDTO_1S, WDTO_2S, WDTO_4S, WDTO_8S 
  setup_watchdog(WDTO_4S);  // 唤醉 
  sleep_disable(); 
  pinMode(pinT, OUTPUT); digitalWrite(pinT, HIGH);  
  pinMode(pinR, OUTPUT); 
  pinMode(pinG, OUTPUT); 
  pinMode(pinB, OUTPUT); 
} 
   
ZZZoid loop()  
{ 
  wdt_reset();    // pat K9 
  ADCcount = analogRead(ThermistorPin) ; 
  if (ADCcount == ADCpreZZZious) ++nCount; 
  if ( nCount > nToSleep ) 
  { // 给低电压 
    pinMode(pinR, INPUT); digitalWrite(pinR, HIGH);  // 上拉电阻 
    pinMode(pinG, INPUT); digitalWrite(pinG, HIGH); 
    pinMode(pinB, INPUT); digitalWrite(pinB, HIGH); 
    SleepLonger:    // 从头睡眠 
    pinMode(pinT, INPUT); digitalWrite(pinT, HIGH); 
      system_sleep(); 
      sleep_disable();  // 睡眠等候 WDT 触发 
      pinMode(pinT, OUTPUT); digitalWrite(pinT, HIGH); 
      delay(50); 
      // 缓冲光阳 
      for (uint8_t z=0; z<5; z++) { 
        ADCcount = analogRead(ThermistorPin) ; 
      } 
      if (abs(ADCcount - ADCpreZZZious) < 4) goto SleepLonger;   
    
    pinMode(pinR, OUTPUT); digitalWrite(pinR, HIGH); 
    pinMode(pinG, OUTPUT); digitalWrite(pinG, HIGH); 
    pinMode(pinB, OUTPUT); digitalWrite(pinB, HIGH); 
    nCount = 0; 
  } else { 
  // 261 = 32F, 447 = 64F, 537 = 75F, 575 = 82F 
  b = map(ADCcount, 261,  447, 100, 255 ); 
  g = map(ADCcount, 435,  574, 250, 100);  // 笼罩 green & blue 
  r = map(ADCcount, 575, 1023, 250,  50); 
 
  if (ADCcount > 574)              // HOT: ADCcount 跟着温度回升 
    { 
      // 显示红涩假如温度抵达设定值 
      analogWrite(pinR,   r); 
      analogWrite(pinG, 255);      // 255 = 100% High --> xcc 
      analogWrite(pinB, 255);      // 不显示蓝涩 
    } else {                       // 温度降低,蓝涩想绿涩过度 
      analogWrite(pinR, 255);      // 不显示红涩 
      analogWrite(pinG, g); 
      analogWrite(pinB, b);        // 低的温度显示深蓝 
    } 
  } 
  ADCpreZZZious = ADCcount; 
  delay(Delay); 
} 
 
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_Bx(bit)) 
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _Bx(bit)) 
//参考ATtiny85_watchdog_eVample.zip 
ZZZoid system_sleep() 
{ 
    cbi(ADCSRA,ADEN);                     
    power_all_disable ();                 
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);  
    noInterrupts ();                      
    sleep_enable(); 
    interrupts ();                        
    sleep_mode();                         
    sleep_disable();                      
    power_all_enable ();                  
    sbi(ADCSRA,ADEN);                     
} 
 
 
ZZZoid setup_watchdog(int ii) 
{ 
  byte bb; 
  int ww; 
  if (ii > 9 ) ii=9; 
  bb=ii & 7; 
  if (ii > 7) bb|= (1<<5); 
  bb|= (1<<WDCE); 
  ww=bb; 
 
  MCUSR &= ~(1<<WDRF); 
  
  WDTCR |= (1<<WDCE) | (1<<WDE); 
  
  WDTCR = bb; 
  WDTCR |= _Bx(WDIE); 
} 
   
 
ISR(WDT_ZZZect) { 
     
} 
[/mw_shl_code] 
 
 
 
     
  
                                            
                                              
                                              
                                           |