Connect two pins together

My current project requires that I connect two pins together as if they have a switch between them how do I do this? The serial is for testing purposes only. Here's my current code:

int v1 = 2;
int v2 = 4;
int g1 = 3;
int g2 = 5;
int l1 = 6;
int l2 = 7;
int byteRead;

void setup() {
  Serial.begin(9600);
  pinMode(v1, OUTPUT);
  pinMode(v2, OUTPUT);
  pinMode(g1, OUTPUT);
  pinMode(v2, OUTPUT);

}

void loop() {
    byteRead = Serial.read()-48;
    Serial.println(byteRead);
    if(byteRead == 1){
      
    }
    delay(1000);
}

If you want to connect two pins together, the easiest way to do that is by using a wire. But please don't go connecting any pins together until you know what you are doing. You could end up creating a short circuit and frying your arduino.
If you want to read a value, you need to set a pin as an input, then use digitalRead() on that pin.
Also in your setup you declare v2 as an output twice. I assume one of those is supposed to be g2.

thanks for catching that (it is supposed to be g2), and when I want to connect them the circuit works so that v1 and g1 are connected and then it'll switch it so that v1 and (not included forgot to declare) l2 and v1 connect.

u can use a relay or transistor for that

Cryptoniac:
My current project requires that I connect two pins together as if they have a switch between them how do I do this? The serial is for testing purposes only. Here's my current code:

int v1 = 2;

int v2 = 4;
int g1 = 3;
int g2 = 5;
int l1 = 6;
int l2 = 7;
int byteRead;

void setup() {
  Serial.begin(9600);
  pinMode(v1, OUTPUT);
  pinMode(v2, OUTPUT);
  pinMode(g1, OUTPUT);
  pinMode(v2, OUTPUT);

}

void loop() {
    byteRead = Serial.read()-48;
    Serial.println(byteRead);
    if(byteRead == 1){
     
    }
    delay(1000);
}

Be careful there... you might damage your Arduino, What your teacher wants is to learn how Inputs and outputs works on the Arduino, and the serial part is to visualize in the serial monitor. You need to define first your input pins and your output pins, then the serial part, and finally the physical connection.

Brian_v:
Be careful there... you might damage your Arduino, What your teacher wants is to learn how Inputs and outputs works on the Arduino, and the serial part is to visualize in the serial monitor. You need to define first your input pins and your output pins, then the serial part, and finally the physical connection.

This a my own project no teacher and the reason I have no inputs declared is this needs purely outputs. I'm using the serial monitor because I'm going to change the way it gets signals later oon, but right now I want to control the project by sending a code to the outputs immediately.

May be irrelevant but, would the imaginary switches be connected in series or parallel?

Cryptoniac:
This a my own project no teacher and the reason I have no inputs declared is this needs purely outputs. I'm using the serial monitor because I'm going to change the way it gets signals later oon, but right now I want to control the project by sending a code to the outputs immediately.

Okay then, but you still need Inputs, why woud you put a switch 'between', i mean, you need to compare somehow(be this physically or programmed) if you want to know the code is doing what you want...

Honestly, I had to go and look at an ASCII table to check that 48 is actually the code for '0'. Let the compiler do this for you. I write a lot of Serial interface code and I never remember that kind of stuff.

OK, so a serial read of '0' turns the switch off? Maybe? Your original code has no way of turning it on or off, but let's suppose that '1' means "ON".

const int v1 = 2; //inputs
const int v2 = 4;
const int g1 = 3; //outputs
const int g2 = 5;
//what were the L's? I deleted them.

//byteRead doesn't need to be global. Always try to make your variables local until you discover that they do something global.

//The switch state does need to be global because it's set in one function and another needs to read that value
boolean switchState = false; //true for "on" or "connected" false for "off"

void setup() {
  Serial.begin(9600);
  pinMode(v1, INPUT_PULLUP);
  pinMode(v2, INPUT_PULLUP);
  pinMode(g1, OUTPUT);
  pinMode(g2, OUTPUT);
  while(!Serial) {
    //wait for Serial to connect, for Arduinos with 'native' USB serial
  }
  Serial.println("Switch tester version 1.0");
  Serial.print("Compiled on ");
  Serial.print(__DATE__);
  Serial.print(" at ");
  Serial.print(__TIME__);
  Serial.println();
}

void loop() {
  doSerialInput();

  setOutputs();
}

void doSerialInput() {
  if (Serial.available()) {
    char byteRead = Serial.read();
    Serial.println(byteRead);
    switch (byteRead) {
      case '0':
        switchState = false;
        break;
      case '1':
        switchState = true;
        break;
      case '\n':
      case '\r':
        //ignore newline characters
        break;
      default:
        Serial.println("Unrecognised character, use 0 (zero) for off and 1 (one) for on.");
    }
  }
}

void setOutputs() {
  if (switchState) {
    digitalWrite(g1, digitalRead(v1));
    digitalWrite(g2, digitalRead(v2));
  } else {
    //switch is off. No specification given for what to do here.
    //we could explicitly make the outputs LOW when in the off state
    //or just leave them where they were
  }
}

I don't even know what you are trying to test. What do you think connecting two outputs together is going to do?

In general, never EVER connect two digital outputs directly together. There is never a reason for it, and you risk breaking the pins output driver.

My current project requires that I connect two pins together as if they have a switch between them

Why ?

I have no inputs declared is this needs purely outputs.

If neither pin is an input the the program will be blissfully unaware that the pins are connected so why do it ?

Is there something that you have not told us ? Is something else connected to the two pins and if so, what is it ?