NRF24L01 low power temp logger

8 years 8 months ago #2104 by rajbadri
hi
need tutorial code for low power NRF24L01 temperature logger


Thanks

Please Log in or Create an account to join the conversation.

8 years 7 months ago #2114 by EasyIoT

rajbadri wrote: hi
need tutorial code for low power NRF24L01 temperature logger


Thanks


I plan to prepare tutorial in future...

Please Log in or Create an account to join the conversation.

8 years 7 months ago #2120 by hjfabius
I've something implemented using DHT11, NRF24L01 and an Arduino Pro Mini. Let me know if you are interested and I'll share it
The following user(s) said Thank You: godfish

Please Log in or Create an account to join the conversation.

8 years 7 months ago #2123 by asm7100
i like you to shere it, and the code also :-)

//
Allan

Please Log in or Create an account to join the conversation.

8 years 7 months ago #2130 by hjfabius
Here it it. DHT11 pin is attached to arduino pin 8.
Measure is done every 30 seconds but can be easily adjusted.
#include <SPI.h>
#include <MySensor.h>  
#include <DHT.h>  
#include <avr/sleep.h>    // Sleep Modes

#define CHILD_ID_HUM 0
#define CHILD_ID_TEMP 1
#define HUMIDITY_SENSOR_DIGITAL_PIN 8
#define SLEEP_IN_MS 30000  // Sleep time between reads (in milliseconds)
//#define SLEEP_IN_MS 86400000 // 1 day


MySensor gw;
DHT dht;
int   lastBatLevel;
float lastTemp;
float lastHum;
boolean metric = true; 
MyMessage msgHum(CHILD_ID_HUM, V_HUM);
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);


void setup()  
{ 
  gw.begin();
  dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN, dht.DHT11); 

  // Send the Sketch Version Information to the Gateway
  gw.sendSketchInfo("EASYIOT_TEMP", "2.0");

  // Register all sensors to gw (they will be created as child devices)
  gw.present(CHILD_ID_HUM, S_HUM);
  gw.present(CHILD_ID_TEMP, S_TEMP);
}

void loop()      
{  
  delay(dht.getMinimumSamplingPeriod());

  float temperature = dht.getTemperature();
  if (isnan(temperature)) {
      Serial.println("Failed reading temperature from DHT");
  } else if (temperature != lastTemp) {
    lastTemp = temperature;
    gw.send(msgTemp.set(temperature, 1));
    Serial.print("Temperature: ");
    Serial.println(temperature);
  }
  
  float humidity = dht.getHumidity();
  if (isnan(humidity)) {
      Serial.println("Failed reading humidity from DHT");
  } else if (humidity != lastHum) {
      lastHum = humidity;
      gw.send(msgHum.set(humidity, 1));
      Serial.print("Humidity: ");
      Serial.println(humidity);
  }

  int batLevel = getBatteryLevel();
  if (lastBatLevel != batLevel)
  {
    lastBatLevel = batLevel;
    gw.sendBatteryLevel(batLevel);    
    Serial.print("Battery Level: ");
    Serial.println(batLevel);
    
  }

  gw.sleep(SLEEP_IN_MS); //sleep a bit
}


// Battery measure
int getBatteryLevel () 
{
  int results = (readVcc() - 2000)  / 10;   

  if (results > 100)
    results = 100;
  if (results < 0)
    results = 0;
  return results;
} // end of getBandgap


// when ADC completed, take an interrupt 
EMPTY_INTERRUPT (ADC_vect);

long readVcc() {
  long result;
  // Read 1.1V reference against AVcc
  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  delay(2); // Wait for Vref to settle
  noInterrupts ();
  // start the conversion
  ADCSRA |= _BV (ADSC) | _BV (ADIE);
  set_sleep_mode (SLEEP_MODE_ADC);    // sleep during sample
  interrupts ();
  sleep_mode (); 
  // reading should be done, but better make sure
  // maybe the timer interrupt fired 
  while (bit_is_set(ADCSRA,ADSC));
  result = ADCL;
  result |= ADCH<<8;
  result = 1126400L / result; // Back-calculate AVcc in mV

  return result;
}
The following user(s) said Thank You: rajbadri, osalval, asm7100

Please Log in or Create an account to join the conversation.

8 years 7 months ago #2132 by godfish
I would love to see it. :woohoo:

Please Log in or Create an account to join the conversation.

Time to create page: 0.209 seconds

Forum latest

  • No posts to display.