Advertisement
icstation

Human Body Infrared Smoke Temperature Alarm System with Ardu

Nov 18th, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.38 KB | None | 0 0
  1. Human Body Infrared Smoke Temperature Alarm System with Arduino, for more details: http://www.instructables.com/id/Human-Body-Infrared-Smoke-Temperature-Alarm-System/
  2.  
  3.  
  4. the code is as following:
  5. the receiving part:
  6.  
  7. /**
  8. @brief nRF905 RX Demo, by elechouse.
  9. */
  10. #include <NRF905.h>
  11. #include <SPI.h>
  12. #include <LiquidCrystal_I2C.h>
  13. #include <Wire.h>
  14.  
  15. #define BUF_LEN 32
  16. #define CONF_LEN 10
  17.  
  18. #define NRF905_CSN 4
  19. int num[10]={0};
  20. int count=0;
  21. int count_dis=0;
  22. unsigned char table[10]={'0','1','2','3','4','5','6','7','8','9'};
  23. unsigned char write_config_buf[CONF_LEN]={
  24. 0x76, //CH_NO,868.4MHZ
  25. 0x0E, //output power 10db, resend disable, Current Normal operation
  26. 0x44, //4-byte address
  27. 0x20,0x20, //receive or send data length 32 bytes
  28. 0xCC,0xCC,0xCC,0xCC, //receiving address
  29. 0x58, //CRC enable,8bit CRC,external clock disable,16MHZ Oscillator
  30. };
  31.  
  32. unsigned char rx_buf[BUF_LEN]= {0};
  33. unsigned char read_config_buf[CONF_LEN];
  34. unsigned char rx_address[4]= {0xcc,0xcc,0xcc,0xcc};
  35.  
  36. void putstring(unsigned char *str)
  37. {
  38. while(*str){
  39. Serial.write(*str++);
  40. }
  41. }
  42.  
  43. LiquidCrystal_I2C lcd(0x27,16,2);
  44. void setup()
  45. {
  46. //num[0]=12;
  47. char i;
  48. pinMode(13, OUTPUT);
  49.  
  50. pinMode(22,INPUT);
  51. pinMode(23,INPUT);
  52. pinMode(24,INPUT);
  53.  
  54. lcd.init(); // initialize the lcd
  55. // Print a message to the LCD.
  56. lcd.backlight();
  57.  
  58. lcd.setCursor(0,0);
  59. lcd.print("HELLO!");
  60.  
  61. pinMode(10, OUTPUT); // make sure SPI works
  62. pinMode(NRF905_CSN,OUTPUT);
  63. nrf905=NRF905(NRF905_CSN);
  64.  
  65. /** pin/port configuration */
  66. nrf905.init();
  67.  
  68. /** register configuration */
  69. // user self-defined configuration
  70. // nrf905.write_config(write_config_buf);
  71.  
  72. /**
  73. default configuration, need to specify frequency
  74. choose Z-Wave frequency band, support :
  75. US 908.42Mhz
  76. EUROPE 868.42MHz
  77. AFRICA 868.42MHz
  78. CHINA 868.42MHz
  79. HK 919.82MHz
  80. JAPAN 853.42MHz
  81. AUSTRALIA 921.42MHz
  82. NEW_ZEALAND 921.42MHz
  83. BRASIL 921.42MHz
  84. Russia 896MHz
  85. */
  86. nrf905.write_config(CHINA);
  87.  
  88. /** read register configuration, check register value written */
  89. nrf905.read_config(read_config_buf);
  90.  
  91. /** serial communication configurate */
  92. Serial.begin(9600);
  93.  
  94. /** test configuration */
  95. for(i=0; i<CONF_LEN; i++){
  96. Serial.print(read_config_buf[i],HEX);
  97. Serial.print(' ');
  98. }
  99.  
  100. }
  101.  
  102. void loop()
  103. {
  104.  
  105. nrf905.RX(rx_buf);
  106. //putstring(rx_buf);
  107. if(*rx_buf)
  108. {if(rx_buf[0]!='K')
  109. {
  110.  
  111. if(count==10)
  112. count=0;
  113. num[count]=((int)rx_buf[0]-48)*10+((int)rx_buf[1]-48);
  114. //num[0]=12;
  115. count++;
  116. digitalWrite(13,HIGH);
  117. delay(10);
  118. digitalWrite(13,LOW);
  119. }
  120. Serial.write( '*');;
  121. //Serial.write(table[num[1]/10]);
  122. //Serial.write( table[num[1]%10]);
  123. // Serial.write(rx_buf[0]/10);
  124. // Serial.write( rx_buf[0%10]);
  125. }
  126. rx_buf[0]=0;
  127. rx_buf[1]=0;
  128. keyscan();
  129.  
  130. }
  131.  
  132. void keyscan()
  133. {
  134. if(digitalRead(22) == LOW)
  135. {
  136. count_dis=0;
  137. //xianshishuzu
  138. lcd.setCursor(0,0);
  139. lcd.print("num:T");
  140. //lcd.print((char)table[count_dis/10]);
  141. lcd.print((char)table[count_dis%10]);
  142.  
  143. lcd.setCursor(12,1);
  144. lcd.print((char)table[num[count_dis]/10]);
  145. lcd.print((char)table[num[count_dis]%10]);
  146. while(!digitalRead(22));
  147. }
  148.  
  149. if(digitalRead(23) == LOW)
  150. {
  151. count_dis++;
  152. if(count_dis==10)
  153. count_dis=0;
  154. //xianshishuzu
  155. lcd.setCursor(0,0);
  156. lcd.print("num:T");
  157. //lcd.print((char)table[count_dis/10]);
  158. lcd.print((char)table[count_dis%10]);
  159.  
  160. lcd.setCursor(12,1);
  161. lcd.print((char)table[num[count_dis]/10]);
  162. lcd.print((char)table[num[count_dis]%10]);
  163. while(!digitalRead(23));
  164. }
  165. if(digitalRead(24) == LOW)
  166. {
  167. //xianshishuz
  168. num[count_dis]=0;
  169. count_dis++;
  170. if(count_dis==10)
  171. count_dis=0;
  172. lcd.setCursor(0,0);
  173. lcd.print("num:T");
  174. //lcd.print((char)table[count_dis/10]);
  175. lcd.print((char)table[count_dis%10]);
  176.  
  177. lcd.setCursor(12,1);
  178. lcd.print((char)table[num[count_dis]/10]);
  179. lcd.print((char)table[num[count_dis]%10]);
  180. while(!digitalRead(24));
  181. }
  182. }
  183.  
  184.  
  185. the sending part:
  186. /**
  187. @brief nRF905 TX Demo, by elechouse.
  188. */
  189.  
  190. #include <Wire.h>
  191. #include <NRF905.h>
  192. #include <SPI.h>
  193. #include <LiquidCrystal_I2C.h>
  194.  
  195. #define BUF_LEN 32
  196. #define CONF_LEN 10
  197.  
  198. #define TrigPin 8
  199. #define EchoPin 9
  200.  
  201. #define NRF905_CSN 4
  202.  
  203. unsigned char table[10]={'0','1','2','3','4','5','6','7','8','9'};
  204.  
  205. unsigned char tx_buf[BUF_LEN]= "";
  206.  
  207. unsigned char read_config_buf[CONF_LEN];
  208.  
  209. byte tx_address[4]= {0xcc,0xcc,0xcc,0xcc};
  210.  
  211. int num=0;
  212. char flag=0;
  213.  
  214. LiquidCrystal_I2C lcd(0x27,16,2);
  215. void setup()
  216. {
  217. unsigned char i;
  218. pinMode(A1,INPUT);
  219. pinMode(A2,INPUT);
  220. pinMode(A3,INPUT);
  221. pinMode(9,INPUT);
  222. pinMode(13, OUTPUT);
  223.  
  224. lcd.init(); // initialize the lcd
  225. // Print a message to the LCD.
  226. lcd.backlight();
  227.  
  228. lcd.setCursor(0,0);
  229. lcd.print("HELLO!");
  230.  
  231. pinMode(10, OUTPUT); // make sure SPI works
  232. pinMode(NRF905_CSN,OUTPUT);
  233. nrf905=NRF905(NRF905_CSN);
  234.  
  235. nrf905.init();
  236. /** register configuration */
  237. // user self-defined configuration
  238. // nrf905.write_config(write_config_buf);
  239.  
  240. /**
  241. default configuration, need to specify frequency
  242. choose Z-Wave frequency band, support :
  243. US 908.42Mhz
  244. EUROPE 868.42MHz
  245. AFRICA 868.42MHz
  246. CHINA 868.42MHz
  247. HK 919.82MHz
  248. JAPAN 853.42MHz
  249. AUSTRALIA 921.42MHz
  250. NEW_ZEALAND 921.42MHz
  251. BRASIL 921.42MHz
  252. Russia 896MHz
  253. */
  254. nrf905.write_config(CHINA);
  255. nrf905.read_config(read_config_buf);
  256.  
  257. Serial.begin(9600);
  258.  
  259. for(i=0; i<10; i++)
  260. {
  261. Serial.print(read_config_buf[i],HEX);
  262. Serial.print(' ');
  263. }
  264.  
  265. tx_buf[12] = '0';
  266. }
  267.  
  268. void loop()
  269. {
  270. keyscan();
  271. num_send();
  272. delay(15);
  273.  
  274. }
  275.  
  276. void keyscan()
  277. {
  278. if(digitalRead(A1) == LOW)
  279. {
  280. flag=0;
  281. //xainshicall
  282. lcd.setCursor(0,0);
  283. lcd.print("num:");
  284. lcd.print((char)table[num/10]);
  285. lcd.print((char)table[num%10]);
  286. lcd.setCursor(9,1);
  287. lcd.print("call ");
  288. while(!digitalRead(A1));
  289. }
  290. if(digitalRead(A2) == LOW)
  291. {
  292. num++;
  293. lcd.setCursor(0,0);
  294. lcd.print("num:");
  295. lcd.print((char)table[num/10]);
  296. lcd.print((char)table[num%10]);
  297. while(!digitalRead(A2));
  298. }
  299. if(digitalRead(A3) == LOW)
  300. {
  301. num--;
  302. lcd.setCursor(0,0);
  303. lcd.print("num:");
  304. lcd.print((char)table[num/10]);
  305. lcd.print((char)table[num%10]);
  306. while(!digitalRead(A3));
  307. }
  308. if(digitalRead(9) == LOW)
  309. {
  310. flag=1;
  311. lcd.setCursor(0,0);
  312. lcd.print("num:");
  313. lcd.print((char)table[num/10]);
  314. lcd.print((char)table[num%10]);
  315.  
  316. //xianshicalling
  317. lcd.setCursor(9,1);
  318. lcd.print("calling");
  319. while(!digitalRead(9));
  320. }
  321. }
  322.  
  323. void num_send()
  324. {
  325. if(flag==1)
  326. {
  327. flag=0;
  328.  
  329. tx_buf[0]=table[num/10];
  330. tx_buf[1]=table[num%10];
  331. nrf905.TX(tx_buf);
  332. }
  333. if(flag==0)
  334. {
  335. tx_buf[0]='K';
  336. tx_buf[1]=1;
  337. nrf905.TX(tx_buf);
  338. delay(10);
  339. }
  340. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement