If I'm understanding your problem correctly, you want ledPin
to be turned on when you run your sketch, correct?
Looking at your logic in sensor()
it seems that you want ledPin
to turn off when sensorPin
is triggered. In this case it would make sense for you to set ledPin
to HIGH in your setup function.
It can look something like this:
void setup() {
pinMode(ledPin, OUTPUT);
// Setting ledPin to on by default:
digitalWrite(ledPin, HIGH);
pinMode(sensorPin, INPUT);
Serial.begin(9600);
delay(2000);
Serial.println("Available! Give command ('on' or 'off').");
}