# help with microswitches

i have a motor that turns a spindle and i want it to: start when i press the button (motor start turning) untill microswitch (switchl) is reached then go back the other way untill microswith(switchr) is reached and then send a signal back and wait for the start again.

motor1 is the start and motor 2 is to change the direction the other way. i have no idea how to start on this and how to make it work but its my final school project.

``````int motor1 = 6;
int motor2 = 7;
int switchl = 8;
int switchr = 9;
int START = 5;
int STOP = 8;
int SIGUIT = 9;
int SIGIN = 10;

void setup()
{

pinMode(motor1, OUTPUT);
pinMode(motor2, OUTPUT);
pinMode(switchl, OUTPUT);
pinMode(switchr, OUTPUT);
pinMode(START, INPUT);

}

}
``````

Only 1/10 for that software . ...Start by looking at how you can connect the microswitches to digital inputs and use the IDE examples for digital inputs.

Then have a look at H bridges for motor control and how to make the motor go in different directions . Then look how to combine , getting the inputs from the switches to determine motor direction.

This is a school project the idea is to learn how to do it . Have a proper go then get back to us .

Sorry but you’'ll have to put in a bit more effort than this. Why would your limit switches be on OUTPUT pins? There are lots of examples in that IDE that read a switch and do something so try some of those.

At least put in some code to read the switches even if you have to put some dummy code in for the motor code until you work out how that works. What motor driver are you using that works with only 2 pins? What signals does it need on each. A link to a datasheet might help us to help you.

Steve

stenl: i have no idea how to start on this and how to make it work but its my final school project.

At the risk of seeming pedantic, you didn't actually say why you're posting. Do you want advice or full working code and a full circuit diagram and bill of materials, or what?

I Don't want to be rude here - but what have you been doing the rest of the term?

Every programming / design class I ever took had us reading switches and controlling outputs in a few hours. The code looks like you just showed up in class a few minutes ago, programming classes build each session on the last one, you need to go back to the start, sorry not much for shortcuts,

You did not add much information here.

I mostly want to know how you are driving the motor. You can't just power one side and then the other. Neither will be connected to ground, so no power. Also almost all motors pull way to much current for arduino pins.

You need an h bridge to accomplish what you want to do. None of us know though. This is because you did not provide a schematic.

Also, I learned how to do this in a 2 hour field trip earlier this year. As a middle schooler.

Hi, Welcome to the Forum. Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Also what motor driver, and type of switches you are using?

In you bit of code you seem to have pins 8 and 9 assigned to two different events.

Thanks... Tom... :)