how to use if statments for sensors

im making a programmbale robot car for my college project and I want my robot to stop after the sensors are activated. the sensors are two switches connected at the front of the robot. When the robot comes in contact with an obstacle the switches get pushed by the object at which the motors should stop.

I have tried to use if statments to achieve this but have had no success in doing so. Can someone perhaps show me a way which this could be achieved. the pin which is connected to the sensors is digital pin 1. the pins connected to the motors are pins 11, 5 which drive the robot forward and 6, 3 reverse the motors.

Please post your best attempt at using if statements and say exactly what it does wrong.

BTW you don't want to use Pin1 because on almost all Arduinos connecting things to that will mess up program loading and the use of the Serial Monitor.

Steve

I have tried to use if statments to achieve this but have had no success in doing so.

Have a few more tries. (They’re free)
Or post what you tried here.

Your call.

if switch == 0 or 1 analogWrite motor 0

don't use pin 1.