Integrating a LDR sensor with an IR sensor for remote control

Hi,

So my project is basically I’m using a UNO board with a BTS7960 43A High Power Motor Driver board to control a motor. I want to control the motor with IR remote which is no problem as I have figured out how to do that using the usual switch commands as shown below.

void loop() **
{
** if (irrecv.decode(&results)) // have we received an IR signal?

** {**
** translateIR();**
** irrecv.resume(); // receive the next value**
** } **
}
void translateIR() // takes action based on IR code received
// describing Remote IR codes
{
** switch(results.value)**
** {**
** case 0: //change zero to your IR remote UP button number**
** lcd.clear();**
** lcd.print(“UP”);**
** break;**

** default:**
** lcd.clear();**
** lcd.print(" other button ");**
** }**
** delay(500); // Do not get immediate repeat**

But what I also want to do is add two trip lasers which I will use a Light sensor in order to act as limit switch to stop the motor when it reaches a certain point and trips the laser. I’m assuming you would add the trip condition to the switch statement as an additional “case” but not sure how to integrate it with the IR ‘cases’ in the code as the switch statement in the IR case is just looking for a remote code. Below is sort of the code I want to integrate into a switch ‘case’ but haven’t had any luck on working out the best way to do it.

Thanks

short Detect = analogRead(Rec); //Constanly reading the module value

if(Detect < 500) //The Max value is 760, if someone passes it goes below that (every value lower than 700 can do the work)
detection = true; //The detection is triggered

if(detection==true)
{
do certain task
}

Please post your code using code tags. It will make it easier for members to assist you.

boostn1005:
I'm assuming you would add the trip condition to the switch statement as an additional "case" but not sure how to integrate it with the IR 'cases' in the code as the switch statement in the IR case is just looking for a remote code.

Incorrect assumption. The switch/case statement is for when you want to compare an integer value against a list of integer constants. Your current switch statement is used to compare the received and decoded IR value to a list of useful vslues.
Other actions, such as responding to changes in an analog input, would generally be done in loop() while waiting for a new IR signal to be decoded. That would be before or after the "if (irrecv.decode(&results))" statement. You could put the code in loop() or have loop() call a function to check the analog inputs.