CR2450无线照明传感器

要制造一种包含气压计,温度计,湿度计或全部装在一个瓶子中,由220V供电的无线传感器不是问题。但是,用电池或蓄电池为这种设备供电已经很有趣了。好吧,如果它是碟形锂电池(平板电脑)-通常会很凉爽,因为该设备会变得非常紧凑。
使用“药丸”的唯一障碍是其容量小。但即使在“平板电脑”中,也有相当合适的标本,例如CR2450,标称容量为550-610 mAh。
由于在制造该设备时,我已经有现成的室内和室外温度和湿度传感器,因此我决定基于BH1750制作照明传感器并将其放置在阳台上,并为其配备DS18B20温度传感器。
由于我的所有窗户都朝南,因此室外温度和湿度传感器会受到阳光的严重影响,因此必须通过从Internet接收的天气数据来补偿这种影响,将来,我计划使用有关照明水平的信息来计算补偿。
为了最大程度地减少传感器消耗的能量,决定:
1.拒绝使用成品的Arduinki,而直接将ATmega 328P-PU微控制器与8MHz石英一起使用。我拒绝使用内部RC生成器,因为由于外部温度的显着变化,工作频率不稳定。
2.使用LowPower库并为控制器启用LowPower.powerDown省电模式(SLEEP_8S,ADC_OFF,BOD_OFF)
。3.在测量之前,立即从微控制器的数字输出为DS18B20传感器供电并打开DS18B20传感器的电源
4.分别使用节能模式radio.powerDown()和Light.configure(BH1750_ONE_TIME_HIGH_RES_MODE)直接给无线电模块和BH1750供电。
配备了USBasp编程器,

我要求控制器和引导加载程序提供保险丝。我组装了一个原型,绘制了测试草图并测量了消耗的电流:在睡眠模式下,电流为14μA,在从传感器获取读数的模式下为3-4 mA,在通过nRF24传输到气象站的数据模式为16-18 mA。考虑到我决定每3分钟从传感器读取一次读数,然后每10分钟发送一次读数,因此该传感器非常经济。
为了制造最终设备,使用了一块面包板和金属丝MGTF。结果就是发生了什么:

为了监视电池状态,我们使用了ATmega的内置功能,本文对此进行了详细介绍
引导加载程序和保险丝的刷新过程在此处 和此处详细介绍
在疯子网站上 借用了创建自主传感器的一般想法

传感器已经第二个月躺在窗台的阳台上(并且正在工作),可以正确发送数据。电源控制报告说,在此期间,电源电压从首次打开时的3.05V下降到2.98V。但是,白天,当阳光温暖阳台时,电压可能会上升到3.00V。我期待寒冷的天气,让我们看看所选电池在低温下如何显示自己。
在选定的睡眠模式持续时间下,事实证明传感器在24小时内仅唤醒492-495秒。

该设备是完整的,但不幸的是到目前为止没有外壳,我找不到合适的



增加了03/20/2016。
6 , . -24, 2,5280V.
( ) 4 + .


资源
#include <LowPower.h>
#include <SPI.h>
#include <RF24Network.h>   
#include <RF24.h>          
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <BH1750.h>
/////// lass AVG //////////////////////////////////////////////////////////
class AVG {
  #define DEPTH_AVG 10
  private :
     int depth;
     long *mas;
     int cur;
     boolean first;
  public :
     boolean fDebug;  

  AVG(int d)
  {
    if( d == 0 || d > DEPTH_AVG)depth = DEPTH_AVG;
    else depth = d;
    mas = (long *)malloc(sizeof(long)*depth);
    first = true;
    cur   = 0;
    fDebug = false;
  }
  void Set(long x)
  {
    if( first )
    {
       for( int i=0; i<depth; i++ )mas[i] = x;
       cur = 0;
    }
    else
    {
    mas[cur++] = x;
    if( cur >= depth ) cur = 0; 
    }
    first = false;  
  }
  long Get()
  {
    long x=0;
    for( int i=0; i<depth; i++ )
          {
            x+=mas[i];
          }
    x/=depth;
    return(x);
  }
};
/////////////////////////////////////////////////////////////////////
#define pinPowerSensor 4    //    Pin 4
#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
BH1750 Light;
RF24 radio(/*ce*/ 9, /*cs*/ 10);
RF24Network network(radio);
//   
uint16_t this_node = 02;
// ,     
uint16_t main_node = 0;
//  
const int Chanel = 11;
int ReadCount;
int iSend     = 3;    //    
int WaitCount = 24;   //     8 .
bool allowSend = false; //   
AVG vAVG(3);
AVG tAVG(3);
AVG lAVG(3);
struct StreetMeteoSensor
{
  char    ID[5];     // 
  unsigned long UpTime;
  int   T;           //
  long  L;           //  (Lx) 
  int   V;           //   (mV)
};
struct StreetMeteoSensor sensor;
RF24NetworkHeader header(main_node, 'I');
////////////////////////////////////////////
#define DEBUG_MODE     0
////////////////////////////////////////////
void setup(void)
{
    if (DEBUG_MODE) 
  {
    Serial.begin(115200);
    //tAVG.fDebug = true;  
    //lAVG.fDebug = true;      
    Serial.println("-- START --");  
    WaitCount = 5;
  }
  for (int i = 1; i < 15; i++)  
  {
    pinMode(i, OUTPUT);
    digitalWrite(i,LOW);
  }
  digitalWrite(pinPowerSensor,HIGH);
  char ID[5] = "LTS1";
  memcpy(sensor.ID, ID, 5);  
  ReadCount = iSend;
  SPI.begin();
  delay(500);
  radio.begin();
  network.begin( Chanel, this_node );  
  sensors.begin();  
  Light.begin(BH1750_ONE_TIME_HIGH_RES_MODE);
  delay(500);
  radio.powerDown();    
  digitalWrite(pinPowerSensor,LOW);  
  Light.configure(BH1750_POWER_DOWN);
  if (DEBUG_MODE)  Serial.println("-- End SETUP --"); 
}

void loop(void)
{
  //  
 if (DEBUG_MODE) Serial.println("data read...");
  //  BH1750    , 
  Light.configure(BH1750_POWER_ON);                    //  
  Light.configure(BH1750_ONE_TIME_HIGH_RES_MODE);     //   
  digitalWrite(pinPowerSensor,HIGH);                  //    DS18B20
  sensors.setResolution(TEMP_9_BIT);   
  delay(250); 
  sensors.requestTemperatures();
  int T = sensors.getTempCByIndex(0);
  digitalWrite(pinPowerSensor,LOW);  //   DS18B20
  long L = Light.readLightLevel();  // ONE_TIME   
  int V = readVcc();  
  /////////////////////////////////////////////////////////////
  int tt = tAVG.Get();
  int vv = vAVG.Get();
  long ll = lAVG.Get();
  if (L > 0 || ll > 0 || T < tt-2 || T > tt+2 || V < vv-100/*0.1V*/) 
  { //  -    
    tAVG.Set(T);
    lAVG.Set(L);
    vAVG.Set(V); 
    allowSend = true;     //   -  
    //     0 ()
    if (ll == 0 &&  L > 0)
      lAVG.Set(L);  
  }
  ReadCount++;        
  /////////////////////////////////////////////////////////////
  if (DEBUG_MODE)
  {
    Serial.print("T= ");
    Serial.print(tAVG.Get());
    Serial.print(": ");
    Serial.print(T);    
    Serial.print("; L= ");
    Serial.print(lAVG.Get());
    Serial.print(": ");    
    Serial.print(L);    
    Serial.print("; V= ");
    Serial.print(vAVG.Get());
    Serial.print(": ");    
    Serial.print(V);        
    Serial.print("; ReadCount= ");    
    Serial.println(ReadCount);
  }  
  /////////////////////////////////////////////////////////////
  //    
  if ( ReadCount >= iSend && allowSend )
  {
    //     
    ReadCount = 0;
    allowSend = false;   
    radio.powerUp();
    delay(50);
    sensor.T = tAVG.Get();  
    sensor.L = lAVG.Get();
    sensor.V = vAVG.Get();    
    sensor.UpTime = millis()/1000;     
    network.write(header,&sensor,sizeof(sensor));
    radio.powerDown();  
  }    
  sleep();
}
//      
void sleep()
{
  if (DEBUG_MODE) {Serial.println("----- SLEEP -----");Serial.flush();}
  for (int i = 0; i < WaitCount; i++)  //   
  {
    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); 
  }
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//   
int readVcc() 
{
  int result;
  // Read 1.1V reference against AVcc
  // set the reference to Vcc and the measurement to the internal 1.1V reference
  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  delay(75); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Start conversion
  while (bit_is_set(ADCSRA,ADSC)); // measuring
  result = ADCL;
  result |= ADCH<<8;
  if (DEBUG_MODE) {Serial.print("result=");Serial.println(result);}
  result =  1125300L / result; // (Kvcc * 1023.0 * 1000) (in mV);
  return result; 
}

Source: https://habr.com/ru/post/zh-CN385129/


All Articles