How to get the Arduino to close a circuit

I haven't built the circuit but this is what I think the code should look like. Remember I'm very green lol.


//Closes a circuit on a hacked keyboard to type a letter

#define SENSOR 2 //the input pin where the PIR sensor is connected
#define TRANSISTOR 4 //the output pin where the BASE pin for the transistor is connected

int val = 0; //the state of the input pin

void setup() {
pinMode (SENSOR, INPUT); //sets SENSOR as an input
pinMode (TRANSISTOR, OUTPUT); //sets the TRANSISTOR as an output
}

void loop () {
val = digitalRead(SENSOR); //read the state of the SENSOR and store it

//check if the sensor has been tripped and is sending any voltage

if (val == HIGH) {
digitalWrite(TRANSISTOR, HIGH); //send voltage to TRANSISTOR
} else {
digitalWrite(TRANSISTOR, LOW); //do not send any voltage to TRANSISTOR
}
}