In this episode we will take a look at how you can use your Arduino board to get digital and analog readings from a photo interrupter also known as an optical interrupter…
Parts List:
affiliate links
Schematic:
ARDUINO Code:
//analogRead code
int val;
int led=13;
void setup() {
Serial.begin(9600);
pinMode (led,OUTPUT);
}
void loop() {
val = (analogRead(A1));
Serial.println(val);
if (val < 500)
{
digitalWrite(led,HIGH);
}
else
{
digitalWrite(led,LOW);
}
delay(250);
}
————————————————————————————————–
//digitalRead code
int led=13;
void setup() {
pinMode (led,OUTPUT);
}
void loop() {
if (digitalRead(A1) == LOW)
{
digitalWrite(led,HIGH);
}
else
{
digitalWrite(led,LOW);
}
}