Mim527

digital project

Aug 13th, 2020 (edited)
769
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.48 KB | None | 0 0
  1. int sensorState = 0;
  2. void setup()
  3. {
  4.   pinMode(2, INPUT);
  5.   pinMode(13, OUTPUT);
  6.   Serial.begin(9600);
  7. }
  8. void loop()
  9. {
  10.   // read the state of the sensor/digital input
  11.   sensorState = digitalRead(2);
  12.   // check if sensor pin is HIGH. if it is, set the
  13.   // BUZZER on.
  14.   if (sensorState == HIGH) {
  15.     digitalWrite(13, HIGH);
  16.     Serial.println("Sensor activated!");
  17.   } else {
  18.     digitalWrite(13, LOW);
  19.   }
  20.   delay(10); // Delay a little bit to improve simulation performance
  21. }
Add Comment
Please, Sign In to add comment