please help me so the dc motor can be stopped with 2 different limite switches
I use the L298N bridge and dc motor 12v
byte sensorpir = 8;
byte in1 = 2;
byte in2 = 3;
byte led = 13;
I'm guessing that "limite switch" means microswitch (something like this with a common (CO), normally open (NO) and normally closed (NC) pin, image: https://www.wiltronics.com.au/wp-content/uploads/products/ultramini-micro-switch-lever.jpg ). In such a case, I am assuming your application is that you want the motor to be able to go to a "clockwise most position" or an "anticlockwise most position" then stop at whichever end it has just been told to go to, it doesn't involve much programming at all, just some different wiring. Don't use your switches as inputs, that's great for some things but wastes arduino pins in these circumstances. Instead wire up pin D0 (it could be any pin but I'll use zero throughout this post) to go to CO on one of your switches, then have NC on that switch connected to "input 1" on the L298N, position this switch to be located such that a part of the thing which the motor is moving will strike this switch when at the most clockwise position. Then wire pin D1 of the arduino (again could be any pin, but for consistency I'll use 1) to CO on the other switch and NC of that switch to "input 2" of the driver chip. output 1 of the L298 should go to the pin on the motor which gets 12V when the motor runs clockwise, output 2 should go to the pin of the motor which goes to gnd when the motor runs clockwise. wire "enable A" of the driver chip to pin3,5,6,9,10 or 11 on your arduino, you can PWM on these pins to allow the motor to run at diferent speeds.
Edit the code that you've shown such that d0 is your "high to go clockwise" pin and d1 is your "high to go anticlockwise" pin. At that point your code as it stands ought to get the motor swinging back and forth (the 5 second delay should be set to a value larger than the time it takes the motor to complete the motion), make sure to make d3,5,6,9,10 or 11 go high before you want the motor to move, you can also use analogWrite on these pins to do PWM and control motor speed. In your code you want to set the enable pin high straight after the place where you set the led to high and the place where you set the led to low. 255 will be full speed, 0 will be no motion, the motor will probably stop moving somewhere around 50 and not move at below this, but depending on exact specifications of the motor it may stop at a lower or higher analog value.
so true ,,,
I want to move the motor clockwise then counterclockwise
so help me to fix it
move the motor clockwise then counterclockwise
If the Arduino program is to do that, the program should have code that reads the limit switches and performs the direction change.
There are many tutorials on line for how to wire and read switches using Arduino.