I am trying to get my optical limit switches to work. I have listed what I have below. Think that I have found out how to hook one up to my arduino but I don't quite know how to see if it is working.
I have an Arduino Mega 2560 and plan on using a pin above 13 because the lower ones are used for a working stepper and some other things.
The optical switch that I have is:
Opto Interrupter IRT9608-F [SEN020] - $1.50 : iStore, Make Innovation Easier
I tried using this code but didn't have any luck.
#define optOutPin 51
#define optInPin 53
void setup()
{
Serial.begin(9600);
pinMode(optOutPin, OUTPUT);
pinMode(optInPin, INPUT);
}
void loop()
{
int val1;
int val2;
digitalWrite(optOutPin, HIGH);
//digitalWrite(optInPin, HIGH);
val1 = digitalRead(optOutPin);
val2 = digitalRead(optInPin);
Serial.println(optOutPin);
Serial.println(optInPin);
Serial.println(val1);
Serial.println(val2);
if(val2==HIGH)
{
Serial.println("HIGH");
}
else
{
Serial.println("LOW");
}
delay(1000);
}
Can anyone please help me?