#define RECEIVER1 2
#define RECEIVER2 6 //
#define BUZZER1 8 //
#define BUZZER2 9
void setup() {
Serial.begin(9600);
Serial.println("TEST TEST");
pinMode(RECEIVER1, INPUT);//define detect input pin
pinMode(RECEIVER2, INPUT);
pinMode(BUZZER1, OUTPUT);//define ACTION output pin
pinMode(BUZZER2, OUTPUT);
}
void loop() {
int detected = digitalRead(RECEIVER1);// read Laser sensor
if( detected == HIGH)
{
digitalWrite(BUZZER1,HIGH);// set the buzzer ON
Serial.println("NO LASER 1");
}else{
digitalWrite(BUZZER1,LOW); // Set the buzzer OFF
Serial.println("LASER DETECTED 1");
int detected = digitalRead(RECEIVER2);
if( detected == HIGH)
{
digitalWrite(BUZZER2,HIGH);// set the buzzer ON
Serial.println("NO LASER 2");
}else{
digitalWrite(BUZZER2,LOW); // Set the buzzer OFF
Serial.println("LASER DETECTED 2");
}
}
delay(200);
}
hi, I'm working on my 1st Arduino project, and I have 10 pairs of KY-008 Laser Transmitter + Laser Receiver Sensor Modules. I have written the code, but it doesn't work as intended. Arduino won't check if the 2nd receiver is a "hit", unless the 1st receiver is a "hit." So, basically, it won't go to and check the value for receiver 2, unless the receiver 1 is exposed to the light from the transmitter.
and the 2nd question - is there any way to tell which transmitter is hitting the receive or not. I can obviously number number the receivers but how can I know which transmitter is hitting let's say receiver #1 ?
Thanks in advance, sorry if my question is super basic. I'm just starting (by the way it's an Arduino Uno R3 original that I'm using).