Advertisement
icstation

Photosensitive Timing Infrared LED Control System with Ardui

Dec 29th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.74 KB | None | 0 0
  1. Photosensitive Timing Infrared LED Control System Based On Arduino by www.ICStation.com
  2. 1) When start up, the hardware initialized and the LED will flash. The 4-bit digital tube display the initialized time 23:59.
  3.  
  4. 2)When nobody appears in the infrared induction area, the LED will not light.
  5.  
  6. 3)When the intensity of environmental light is weak and somebody is appearing in the infrared induction area, the LED will light till the person leaves the infrared induction area.
  7.  
  8. 4) On 24 o’clock at midnight, the buzzer will alarm and the LED will switch to the manual control till 8 o’clock in the morning.
  9.  
  10. 5)You can set the time by the switches.
  11. components list:
  12. 1)ICStation ATMEGA2560 Mega2560 R3 Board Compatible Arduino
  13. http://www.icstation.com/product_info.php?products_id=3517
  14. 2)830 Point Solderless PCB Bread Board MB-102 Test DIY
  15.  
  16. 3)Round White Green Superbright Bulb Light
  17.  
  18. 4)5mm Infrared Emitting LED
  19.  
  20. 5)TL1838 VS1838B VS1838 Universal Receiving Head
  21.  
  22. 6)Active Buzzer Module for Arduino
  23.  
  24. 7)Breadboard Plug Wire Cable Tire
  25.  
  26. 8)12X12X5mm Tact Switches 4 Legs
  27.  
  28. 9)1K ohm 1/4W 1% Accuracy Metal Film Resistor
  29.  
  30. 10)Common Cathode 4bit Digital Tube
  31.  
  32. 11)+5V DC power supply
  33.  
  34. More details:http://www.instructables.com/id/Photosensitive-Timing-Infrared-LED-Control-System-/
  35.  
  36. COde for reference:
  37.  
  38. /*This digital tube is commen cathode*/
  39. //set the interface of anode
  40. int a = 26;
  41. int b = 50;
  42. int c = 48;
  43. int d = 46;
  44. int e = 42;
  45. int f = 40;
  46. int g = 38;
  47. int dp = 36;
  48. int ajs=4;
  49. int ajf=1;
  50. int kg = 6;
  51. int cs = 1;
  52. //set the interface of cathode
  53. int d4 = 34;
  54. int d3 = 32;
  55. int d2 = 30;
  56. int d1 = 28;
  57. //set the viriate
  58. long n = 7;
  59. long k = 5;
  60. long l = 3;
  61. long m = 2;
  62. long t = 0;
  63. byte duan_segs[8] = { a, b, c, d, e, f, g, dp};
  64. byte wei_segs[4] = { d1, d2, d3, d4 };
  65. byte seven_seg_digits[10][7] = { { 1,1,1,1,1,1,0 }, // = 0
  66. { 0,1,1,0,0,0,0 }, // = 1
  67. { 1,1,0,1,1,0,1 }, // = 2
  68. { 1,1,1,1,0,0,1 }, // = 3
  69. { 0,1,1,0,0,1,1 }, // = 4
  70. { 1,0,1,1,0,1,1 }, // = 5
  71. { 1,0,1,1,1,1,1 }, // = 6
  72. { 1,1,1,0,0,0,0 }, // = 7
  73. { 1,1,1,1,1,1,1 }, // = 8
  74. { 1,1,1,1,0,1,1 } // = 9
  75. };
  76. //the time of last opperating
  77. unsigned long previousMillis = 0;
  78. //The minimum time interval
  79. int INTERVAL = 1000;
  80. //flag represents three mode,0-stop,1-timing,2-suspend
  81. int flag = 1;
  82. //Simulation of the mouth A0
  83. int BUTTON = 0;
  84. void setup()
  85. {
  86. pinMode( 51 , OUTPUT);
  87. digitalWrite(51,LOW);
  88. digitalWrite(49,LOW);
  89. digitalWrite(47,HIGH);
  90. digitalWrite( A5 , LOW );
  91. Serial.begin(9600);
  92. pinMode( 47 , OUTPUT);
  93. for(int i=0;i<4;i++)
  94. pinMode(wei_segs[i], OUTPUT);
  95. for(int i=0;i<8;i++)
  96. pinMode(duan_segs[i], OUTPUT);
  97. }
  98.  
  99. void loop()
  100. {
  101. clearLEDs();
  102. pickDigit(1);
  103. lightSegments(m%10);
  104. dkg();
  105. jianyis();
  106.  
  107. clearLEDs();
  108. pickDigit(2);
  109. lightSegments(l%10);
  110. jiayis();
  111.  
  112. clearLEDs();
  113. pickDigit(3);
  114. lightSegments(k%10);
  115. LED();
  116.  
  117. clearLEDs();
  118. pickDigit(4);
  119. lightSegments(n%10);
  120. zs();
  121. jishi();
  122. keyScan();
  123. jiayif();
  124. jianyif();
  125. fmqx();
  126. fmqt();
  127. // fmqx();
  128. //fmqt();
  129. //LED();
  130. //keyScan();
  131. // jiayis();
  132. // jianyis();
  133. //jiayif();
  134. //jianyif();
  135. // zs();
  136. // dkg();
  137.  
  138.  
  139. }
  140.  
  141.  
  142. void pickDigit(int x) //Define pickDigit(x),the function is to open dx interface
  143. {
  144. for(int i=0;i<4;i++)
  145. {
  146. if(i == (x-1))
  147. digitalWrite(wei_segs[i], LOW);
  148. else
  149. digitalWrite(wei_segs[i], HIGH);
  150. }
  151. }
  152.  
  153. //set open point
  154.  
  155.  
  156. //clear screen
  157. void clearLEDs()
  158. {
  159. for (int i = 0; i < 8; i++)
  160. digitalWrite(duan_segs[i], LOW);
  161. }
  162.  
  163.  
  164. // light corresponding Numbers of Digital tube
  165. void lightSegments(int x)
  166. {
  167. for (int i = 0; i < 7; i++)
  168. {
  169. digitalWrite(duan_segs[i], seven_seg_digits[x][i]);
  170. }
  171. }
  172. //keyscan
  173. void keyScan()
  174. {
  175. if(analogRead(BUTTON)>600)
  176. {
  177. delay(20);
  178. if(analogRead(BUTTON)>600)
  179. {
  180. flag++;
  181. if(flag>=3)
  182. flag=1;
  183. while(analogRead(BUTTON)>600);
  184. }
  185. }
  186. }
  187. //光敏红
  188. void LED()
  189. {
  190. Serial.print( analogRead(A2) );
  191. Serial.println("");
  192. Serial.print( analogRead(A3) );
  193. Serial.println("");
  194. if (( ( ( analogRead(A2) ) < ( 400) ) && ( ( 120 ) < ( analogRead(A3) ) ) ))
  195. {
  196. digitalWrite( A5 , HIGH );
  197. }
  198. else
  199. {
  200. digitalWrite( A5 , LOW );
  201. }
  202. }
  203. // The hour add 1
  204. void jiayis()
  205. { Serial.print( analogRead(A2) );
  206. Serial.println("");
  207. Serial.print( analogRead(A3) );
  208. Serial.println("");
  209. if(((analogRead(ajs)>600))&&(flag==1))
  210. {
  211. delay(20);
  212. if(((analogRead(ajs)>600))&&(flag==1))
  213. { t=0;
  214. l++;
  215. if(l==10)
  216. {
  217. m++;
  218. l=0;
  219. }
  220. if((m==2)&&(l==4))
  221. { n=0;
  222. k=0;
  223. l=0;
  224. m=0;
  225. }
  226. while(((analogRead(ajs)>600))&&(flag==1));
  227. }
  228. }
  229. }
  230.  
  231. // the hour minus 1
  232. void jianyis()
  233. {
  234. if(((analogRead(ajs)>600))&&(flag==2))
  235. {
  236. delay(20);
  237. if(((analogRead(ajs)>600))&&(flag==2))
  238. { t=0;
  239. l--;
  240. if((l==-1)&&((m==1)||(m==2)))
  241. {
  242. m--;
  243. l=9;
  244. }
  245. if((m==0)&&(l==-1))
  246. {
  247. l=3;
  248. m=2;
  249.  
  250. }
  251. while(((analogRead(ajs)>600))&&(flag==2));
  252. }
  253. }
  254. }
  255.  
  256. //the minute add 1
  257. void jiayif()
  258. {
  259. if(((analogRead(ajf)>600))&&(flag==1))
  260. {
  261. delay(20);
  262. if(((analogRead(ajf)>600))&&(flag==1));
  263. { t=0;
  264. n++;
  265. if(n==10)
  266. {
  267. k++;
  268. n=0;
  269. if(k==6)
  270. {
  271. n=0;
  272. k=0;
  273. l++;
  274. if(l==10)
  275. {
  276. m++;
  277. l=0;
  278. }
  279. if((m==2)&&(l==4))
  280. { n=0;
  281. k=0;
  282. l=0;
  283. m=0;
  284. }
  285. }
  286. }
  287. while(((analogRead(ajf)>600))&&(flag==1));
  288. }
  289. }
  290. }
  291.  
  292. //the minute minus 1
  293. void jianyif()
  294. {
  295. if(((analogRead(ajf)>600))&&(flag==2))
  296. {
  297. delay(20);
  298. if(((analogRead(ajf)>600))&&(flag==2));
  299. { t=0;
  300. n--;
  301. if(n==-1)
  302. {
  303. k--;
  304. n=9;
  305. if((k==-1))
  306. {
  307. n=9;
  308. k=5;
  309. l--;
  310. if(l==-1)
  311. {
  312. m--;
  313. l=9;
  314. }
  315. if((m==-1)&&(l==9))
  316. {
  317. l=3;
  318. m=2;
  319. }
  320. }
  321. }
  322. while(((analogRead(ajf)>600))&&(flag==2));
  323. }
  324. }
  325. }
  326. //the buzzer alram
  327. void fmqx()
  328. {
  329. if((n==0)&&(k==0)&&(l==0)&&(m==0)&&(t==0))
  330. {
  331. digitalWrite(47,LOW);
  332. digitalWrite(51,HIGH);
  333. }
  334. }
  335. //the buzzer stop
  336. void fmqt()
  337. {
  338. if((n==0)&&(k==0)&&(l==0)&&(m==0)&&(t==20))
  339. {
  340. digitalWrite(47,HIGH);
  341. }
  342. }
  343.  
  344. void zs()
  345. { Serial.print( analogRead(A2) );
  346. Serial.println("");
  347. if((l==8)&&(m==0))
  348. {
  349. digitalWrite(51,LOW);
  350. }
  351. }
  352. //manual contor the light
  353. void dkg()
  354. {
  355. Serial.print( analogRead(A3) );
  356. Serial.println("");
  357. if((analogRead(kg)>200)&&(( ( 120 ) < ( analogRead(A3) ) )))
  358. {
  359. delay(20);
  360. if((analogRead(kg)>200)&&( ( 120 ) < ( analogRead(A3) ) ))
  361. { cs++;
  362. digitalWrite(49,HIGH);
  363. if(cs==3)
  364. {
  365. digitalWrite(49,LOW);
  366. cs=1;
  367. }
  368. while((analogRead(kg)>2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement