JachuPL

Arduino "Bagiety jusz jado"

Nov 22nd, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. unsigned int cntr = 0;              //moevement detected count
  2. bool bBuzzer = false;                   //state of buzzer
  3. bool bStanDiodyNieb = false;    //state of blue LED
  4. bool bStanDiodyCzer = false;    //state of red LED (NOT THE TEST ONE!)
  5. void setup()
  6. {
  7.     Serial.begin(9600);         //messages over Serial
  8.     pinMode(8, OUTPUT);         //blue LED
  9.     pinMode(9, OUTPUT);         //red LED
  10.     pinMode(10, INPUT);         //PIR HC-SR501 OUT pin as an input for Arduino
  11.     pinMode(11, OUTPUT);        //TEST LED
  12.     bStanDiodyNieb = true;      //at the beginning blue LED will be ON
  13.     bStanDiodyCzer = false;     //at the beginning red LED will be OFF
  14.     bBuzzer = true;             //buzzer will buzz if blue light is turned on
  15. }
  16.  
  17. void loop()
  18. {
  19.     if (digitalRead(10) == HIGH)    //if HC-SR501 detected a movement
  20.     {
  21.         Serial.print("Wykryto ruch po raz ");   //send message on Serial port, it will show how many times a movement has been detected
  22.         Serial.print(++cntr);
  23.         Serial.println("!");
  24.         digitalWrite(11, HIGH);                 //turn on TEST LED (it won't blink!)
  25.         while(digitalRead(10) == HIGH)          //until there's a signal from HC-SR501
  26.         {
  27.             //toggle state of blue LED, red LED and buzzer
  28.             bStanDiodyNieb = !bStanDiodyNieb;
  29.             bStanDiodyCzer = !bStanDiodyCzer;
  30.             bBuzzer = !bBuzzer;
  31.             delay(80);                                      //wait 80ms
  32.             digitalWrite(8, bStanDiodyNieb ? HIGH : LOW);   //either turn on or off blue LED and Buzzer (as they're connected on a breadboard)
  33.             digitalWrite(9, bStanDiodyCzer ? HIGH : LOW);   //either turn on or off red LED (note that while blue LED is on, red is OFF, and while red is ON, blue is OFF)
  34.         }
  35.     }
  36.     else //or turn off blue LED, buzzer, red LED and TEST LED
  37.     {
  38.         digitalWrite(8,LOW);
  39.         digitalWrite(9,LOW);
  40.         digitalWrite(11, LOW);
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment