summaryrefslogtreecommitdiff
path: root/arduino_code/opto-interruptor/working_opto-interruptor
blob: 7abed554b86c7b4946f7171649d2f23cc16bfcc6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
int ledPin = 53;                // choose the pin for the LED
int inputPin = 22;               // choose the input pin
int val = 0;                    // variable for reading the pin status

void setup() {
  Serial.begin(9600);  
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare photo interrupter as input
}

void loop(){
  val = digitalRead(inputPin);  // read input value
  Serial.print(val);
  //delay(500);

  if (val == LOW) {            // check if the input is LOW    
    digitalWrite(ledPin, LOW);  // turn LED OFF
  } else {
    digitalWrite(ledPin, HIGH); // turn LED ON
  }

}