Using a short to prevent program form running

I am playing with the MotorShield and servo motors. The moment I switch on, everything starts running. Is it possible to set something up so that when two pins are shorted, nothing happens? Basically an if statement in the loop tests to see if the short is active or not. I don't want to put switches on each sero as I am only testing things.

You could do this in setup() , check the pin if it is High then check it again. When it goes Low the allow the code to proceed in usual way.

Cool, that gave me the following idea

void setup()
{    
    pinMode(13, OUTPUT);
    digitalWrite(13,HIGH);
 
}
void loop()
{
    if (digitalRead(13)==LOW) {
      //  The actual program....
    }

So now all I need to do is to ground pin 13 and nothing runs.

Just need to confirm that grounding out pin 13 won't damage the board.

abasel:
Just need to confirm that grounding out pin 13 won't damage the board.

It certainly will damage the board, since you've configured pin 13 as an output. If you configure it as an input, it would do what you want.

PeterH:

abasel:
Just need to confirm that grounding out pin 13 won't damage the board.

It certainly will damage the board, since you've configured pin 13 as an output. If you configure it as an input, it would do what you want.

Specifically, you need to configure it as INPUT_PULLUP.

Thanks for all of this but I am still battling to picture it all.

void setup()
{    
    pinMode(13, INPUT_PULLUP);
 
}

and then in the loop

void loop()
{
    if (digitalRead(13)==LOW) {
      //  The actual program....
    }

So If I remove the link nothing happens. Just not sure what I jumper pin 13 to

Still learning so probably speaking gibberish :slight_smile:

abasel:
Thanks for all of this but I am still battling to picture it all.

void setup()

{    
   pinMode(13, INPUT_PULLUP);

}

This line tells the Arduino to make Pin 13 an INPUT and it connects a resistor internally to 5V (VCC). So if nothing is connected to the pin, it is "pulled up" to a HIGH. If the pin is connected to GND then the pin will be "pulled down" to a LOW.

The key is the "_PULLUP". Without that resistor, the pin's value would randomly float between a HIGH and LOW.

abasel:
and then in the loop

void loop()

{
   if (digitalRead(13)==LOW) {
     //  The actual program....
   }

As I said above, when the pin is connected to GND, the pin goes LOW, so then the if-statement becomes TRUE and begins to execute.

Jiggy-Ninja:
Specifically, you need to configure it as INPUT_PULLUP.

Not needed with the code posted, since that does a digitalWrite(pin, HIGH) which will enable the internal pull-up for input pins.

PeterH:

Jiggy-Ninja:
Specifically, you need to configure it as INPUT_PULLUP.

Not needed with the code posted, since that does a digitalWrite(pin, HIGH) which will enable the internal pull-up for input pins.

Well, no. Since the code posted configured the pin as an OUTPUT...

Which is why I suggested that it needed to be configured as an INPUT, and with that change would work as intended i.e. with the pull-up resistor enabled by the digitalWrite() call.