Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Photosensitive Timing Infrared LED Control System Based On Arduino by www.ICStation.com
- 1) When start up, the hardware initialized and the LED will flash. The 4-bit digital tube display the initialized time 23:59.
- 2)When nobody appears in the infrared induction area, the LED will not light.
- 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.
- 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.
- 5)You can set the time by the switches.
- components list:
- 1)ICStation ATMEGA2560 Mega2560 R3 Board Compatible Arduino
- http://www.icstation.com/product_info.php?products_id=3517
- 2)830 Point Solderless PCB Bread Board MB-102 Test DIY
- 3)Round White Green Superbright Bulb Light
- 4)5mm Infrared Emitting LED
- 5)TL1838 VS1838B VS1838 Universal Receiving Head
- 6)Active Buzzer Module for Arduino
- 7)Breadboard Plug Wire Cable Tire
- 8)12X12X5mm Tact Switches 4 Legs
- 9)1K ohm 1/4W 1% Accuracy Metal Film Resistor
- 10)Common Cathode 4bit Digital Tube
- 11)+5V DC power supply
- More details:http://www.instructables.com/id/Photosensitive-Timing-Infrared-LED-Control-System-/
- COde for reference:
- /*This digital tube is commen cathode*/
- //set the interface of anode
- int a = 26;
- int b = 50;
- int c = 48;
- int d = 46;
- int e = 42;
- int f = 40;
- int g = 38;
- int dp = 36;
- int ajs=4;
- int ajf=1;
- int kg = 6;
- int cs = 1;
- //set the interface of cathode
- int d4 = 34;
- int d3 = 32;
- int d2 = 30;
- int d1 = 28;
- //set the viriate
- long n = 7;
- long k = 5;
- long l = 3;
- long m = 2;
- long t = 0;
- byte duan_segs[8] = { a, b, c, d, e, f, g, dp};
- byte wei_segs[4] = { d1, d2, d3, d4 };
- byte seven_seg_digits[10][7] = { { 1,1,1,1,1,1,0 }, // = 0
- { 0,1,1,0,0,0,0 }, // = 1
- { 1,1,0,1,1,0,1 }, // = 2
- { 1,1,1,1,0,0,1 }, // = 3
- { 0,1,1,0,0,1,1 }, // = 4
- { 1,0,1,1,0,1,1 }, // = 5
- { 1,0,1,1,1,1,1 }, // = 6
- { 1,1,1,0,0,0,0 }, // = 7
- { 1,1,1,1,1,1,1 }, // = 8
- { 1,1,1,1,0,1,1 } // = 9
- };
- //the time of last opperating
- unsigned long previousMillis = 0;
- //The minimum time interval
- int INTERVAL = 1000;
- //flag represents three mode,0-stop,1-timing,2-suspend
- int flag = 1;
- //Simulation of the mouth A0
- int BUTTON = 0;
- void setup()
- {
- pinMode( 51 , OUTPUT);
- digitalWrite(51,LOW);
- digitalWrite(49,LOW);
- digitalWrite(47,HIGH);
- digitalWrite( A5 , LOW );
- Serial.begin(9600);
- pinMode( 47 , OUTPUT);
- for(int i=0;i<4;i++)
- pinMode(wei_segs[i], OUTPUT);
- for(int i=0;i<8;i++)
- pinMode(duan_segs[i], OUTPUT);
- }
- void loop()
- {
- clearLEDs();
- pickDigit(1);
- lightSegments(m%10);
- dkg();
- jianyis();
- clearLEDs();
- pickDigit(2);
- lightSegments(l%10);
- jiayis();
- clearLEDs();
- pickDigit(3);
- lightSegments(k%10);
- LED();
- clearLEDs();
- pickDigit(4);
- lightSegments(n%10);
- zs();
- jishi();
- keyScan();
- jiayif();
- jianyif();
- fmqx();
- fmqt();
- // fmqx();
- //fmqt();
- //LED();
- //keyScan();
- // jiayis();
- // jianyis();
- //jiayif();
- //jianyif();
- // zs();
- // dkg();
- }
- void pickDigit(int x) //Define pickDigit(x),the function is to open dx interface
- {
- for(int i=0;i<4;i++)
- {
- if(i == (x-1))
- digitalWrite(wei_segs[i], LOW);
- else
- digitalWrite(wei_segs[i], HIGH);
- }
- }
- //set open point
- //clear screen
- void clearLEDs()
- {
- for (int i = 0; i < 8; i++)
- digitalWrite(duan_segs[i], LOW);
- }
- // light corresponding Numbers of Digital tube
- void lightSegments(int x)
- {
- for (int i = 0; i < 7; i++)
- {
- digitalWrite(duan_segs[i], seven_seg_digits[x][i]);
- }
- }
- //keyscan
- void keyScan()
- {
- if(analogRead(BUTTON)>600)
- {
- delay(20);
- if(analogRead(BUTTON)>600)
- {
- flag++;
- if(flag>=3)
- flag=1;
- while(analogRead(BUTTON)>600);
- }
- }
- }
- //光敏红
- void LED()
- {
- Serial.print( analogRead(A2) );
- Serial.println("");
- Serial.print( analogRead(A3) );
- Serial.println("");
- if (( ( ( analogRead(A2) ) < ( 400) ) && ( ( 120 ) < ( analogRead(A3) ) ) ))
- {
- digitalWrite( A5 , HIGH );
- }
- else
- {
- digitalWrite( A5 , LOW );
- }
- }
- // The hour add 1
- void jiayis()
- { Serial.print( analogRead(A2) );
- Serial.println("");
- Serial.print( analogRead(A3) );
- Serial.println("");
- if(((analogRead(ajs)>600))&&(flag==1))
- {
- delay(20);
- if(((analogRead(ajs)>600))&&(flag==1))
- { t=0;
- l++;
- if(l==10)
- {
- m++;
- l=0;
- }
- if((m==2)&&(l==4))
- { n=0;
- k=0;
- l=0;
- m=0;
- }
- while(((analogRead(ajs)>600))&&(flag==1));
- }
- }
- }
- // the hour minus 1
- void jianyis()
- {
- if(((analogRead(ajs)>600))&&(flag==2))
- {
- delay(20);
- if(((analogRead(ajs)>600))&&(flag==2))
- { t=0;
- l--;
- if((l==-1)&&((m==1)||(m==2)))
- {
- m--;
- l=9;
- }
- if((m==0)&&(l==-1))
- {
- l=3;
- m=2;
- }
- while(((analogRead(ajs)>600))&&(flag==2));
- }
- }
- }
- //the minute add 1
- void jiayif()
- {
- if(((analogRead(ajf)>600))&&(flag==1))
- {
- delay(20);
- if(((analogRead(ajf)>600))&&(flag==1));
- { t=0;
- n++;
- if(n==10)
- {
- k++;
- n=0;
- if(k==6)
- {
- n=0;
- k=0;
- l++;
- if(l==10)
- {
- m++;
- l=0;
- }
- if((m==2)&&(l==4))
- { n=0;
- k=0;
- l=0;
- m=0;
- }
- }
- }
- while(((analogRead(ajf)>600))&&(flag==1));
- }
- }
- }
- //the minute minus 1
- void jianyif()
- {
- if(((analogRead(ajf)>600))&&(flag==2))
- {
- delay(20);
- if(((analogRead(ajf)>600))&&(flag==2));
- { t=0;
- n--;
- if(n==-1)
- {
- k--;
- n=9;
- if((k==-1))
- {
- n=9;
- k=5;
- l--;
- if(l==-1)
- {
- m--;
- l=9;
- }
- if((m==-1)&&(l==9))
- {
- l=3;
- m=2;
- }
- }
- }
- while(((analogRead(ajf)>600))&&(flag==2));
- }
- }
- }
- //the buzzer alram
- void fmqx()
- {
- if((n==0)&&(k==0)&&(l==0)&&(m==0)&&(t==0))
- {
- digitalWrite(47,LOW);
- digitalWrite(51,HIGH);
- }
- }
- //the buzzer stop
- void fmqt()
- {
- if((n==0)&&(k==0)&&(l==0)&&(m==0)&&(t==20))
- {
- digitalWrite(47,HIGH);
- }
- }
- void zs()
- { Serial.print( analogRead(A2) );
- Serial.println("");
- if((l==8)&&(m==0))
- {
- digitalWrite(51,LOW);
- }
- }
- //manual contor the light
- void dkg()
- {
- Serial.print( analogRead(A3) );
- Serial.println("");
- if((analogRead(kg)>200)&&(( ( 120 ) < ( analogRead(A3) ) )))
- {
- delay(20);
- if((analogRead(kg)>200)&&( ( 120 ) < ( analogRead(A3) ) ))
- { cs++;
- digitalWrite(49,HIGH);
- if(cs==3)
- {
- digitalWrite(49,LOW);
- cs=1;
- }
- while((analogRead(kg)>2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement