Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

Air humidity alarm

$
0
0

I decided to build an air humidity alarm so I know when to air (you can also attach a piezo buzzer, which is more recognizable in some situations). I found/use this lib.

Chip: MSP430G2452 (this I had left, I think it's overkill for this task)

--

Problem solved.

Thanks to all who helped.

To solve the problem I decided to comment out

if (millis() < _lastMillis) {
    return _lastResult; // return last correct measurement
  }
_lastMillis = millis() + 1;

in DHT22_430.cpp because I think the millis() doesn't run below LPM2. I also don't need the millis() because I already wait in interrupts (3-10 seconds, enough for this sensor which needs at least 1-2 seconds time).

I also commented out "delay(250);" and changed "delay(20);" to "delay(10);" to reduce unnecessary power consuming cycles. Tested and works.

BTW: don't forget to comment out "#define DEBUG" in DHT22_430.h (but it will give you a compile error anyway when using timer ("multiple definition of `__isr_9'")).

That's it, no further changes (if I would have made many small changes to the lib, I'd have attached the whole project as an archive file).

--

Power consumption:

  • In LPM3: 10µA
  • When fast wake-up check: ~1 - 1.5 mA
  • When the attached 5 mm 1700 mcd 120 ° 20 mA 3.2 V Nichia NSPW570DS LED (not on picture) blinks for 5ms : ~1.6 mA
#include "DHT22_430.h"

#define DHTPIN P1_4
#define LED P1_0

DHT22 mySensor(DHTPIN);
unsigned char wakeupCounter, frequency; //use unsigned char for numbers; can store 0 - 255

void setup() {
  TACCTL0 = CCIE;                     
  TACCR0 = 12000; //1 second
  TACTL = MC_1 | TASSEL_1;
 
  for (int i=0;i<16;i++) //put all pins in INPUT, helps cut power consumption
    pinMode(i,INPUT);
    
  mySensor.begin();
  pinMode(LED,OUTPUT);
  digitalWrite(LED,0);
}


void loop() {
 _BIS_SR(LPM3_bits);
  int flag = mySensor.get();
  int h = mySensor.humidityX10();
  //t = mySensor.temperatureX10();
  if (flag) {
    if(h>=490) { //49.0% humidity
      digitalWrite(LED,HIGH); //on
      delay(5);
      digitalWrite(LED,LOW); //off
      frequency=3; //blink every 3 seconds
    } else
      frequency=30; //check only every 30 seconds
  }
}

#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer0_A0 (void) {
  if(wakeupCounter % frequency == 0) { //check every 10 seconds and sleep deep meanwhile
    __bic_status_register_on_exit(LPM3_bits);
    wakeupCounter=0;
  }
  wakeupCounter++;
}

Attached Thumbnails

  • image.jpg

Viewing all articles
Browse latest Browse all 2077

Trending Articles