极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

12
返回列表 发新帖
楼主: eagler8

【Arduino】108种传感器系列实验(119)---HB100多普勒雷达模块

[复制链接]
 楼主| 发表于 2019-9-23 19:49:24 | 显示全部楼层
  1. /*
  2. 【Arduino】108种传感器模块系列实验(资料+代码+图形+仿真)
  3. 实验一百一十九:HB100微波雷达感应模块 10.525GHz多普勒探测器探头传感器
  4. 项目:测试HB100模块,输入改为模拟口A0,三组数据输出
  5. */

  6. #define RADAR A0 // RADAR inut is attached to A0
  7. #define MICRODELAY 100 // 100microseconds ~10000hz
  8. #define MAXINDEX 1024 // 10 bits
  9. #define TOPINDEX 1023 // 10 bits

  10. byte collect[MAXINDEX];
  11. int mean;
  12. int minimum;
  13. int maximum;
  14. int hysteresis; // 1/16 of max-min
  15. bool currentphase; // are value above mean + hysteresis;
  16. int lastnull; // index for last null passing value
  17. int prevnull; // index for previous null passing value
  18. int deltaindex;
  19. int deltadeltaindex;
  20. int index;
  21. bool phasechange = false;

  22. void setup() {
  23.   // put your setup code here, to run once:
  24.   Serial.begin(115200);
  25.   while (!Serial) {}
  26.   index = 0;
  27.   mean = 0;
  28.   maximum = 255;
  29.   minimum = 0;
  30.   hysteresis = 0;
  31.   currentphase = false;
  32.   lastnull = 0;
  33.   prevnull = 0;

  34.   Serial.print("deltadeltaindex");
  35.   Serial.print("\t");
  36.   Serial.print("deltaindex");
  37.   Serial.print("\t");
  38.   Serial.println("delta");
  39. }

  40. void loop() {
  41.   int newVal = analogRead(RADAR); // Raw reading from amplified radar
  42.   mean -= (collect[index] >> 2);
  43.   mean += (newVal >> 2);
  44.   collect[index]= newVal;
  45.   minimum = newVal < minimum ? newVal : minimum + 1;
  46.   maximum = newVal > maximum ? newVal : maximum - 1;
  47.   hysteresis = abs(maximum - minimum) >> 5;

  48.   if(newVal > (mean + hysteresis))
  49.   {
  50.     if(false == currentphase)
  51.     {
  52.       currentphase = true;
  53.       phasechange = true;
  54.     }
  55.   }
  56.   else if(newVal < (mean - hysteresis))
  57.   {
  58.     if(currentphase)
  59.     {
  60.       currentphase = false;      
  61.       phasechange = true;
  62.     }
  63.   }

  64.   if(phasechange)
  65.   {
  66.     prevnull = lastnull;
  67.     lastnull = index;

  68.     int delta = (prevnull > lastnull) ?
  69.         (lastnull - prevnull + MAXINDEX) :
  70.         (lastnull - prevnull);
  71.     deltadeltaindex = abs(deltaindex - delta);
  72.     deltaindex = delta;

  73.     Serial.print(deltadeltaindex);
  74.     Serial.print("\t");
  75.     Serial.print(deltaindex);
  76.     Serial.print("\t");
  77.     Serial.println(delta);
  78.   }
  79.   
  80.   index = index == TOPINDEX ? 0 : index + 1;
  81.   phasechange = false;
  82.   //delayMicroseconds(10);
  83. }
复制代码
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-9-23 19:51:33 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-9-23 19:53:03 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-3-29 07:51 , Processed in 0.038779 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表