Check Pin

See the code in action on Tinkercad

/* 
Circuit based on diagram posted by Master Apr 12 '16 at 20:58
https://electronics.stackexchange.com/questions/228018/detect-when-a-device-has-been-connected-to-vcc
For this Example the Dip Switch #1 simulates plugging in a device into the circuit.
The serial output demonstrates the return from function and setting the bit inside of the Byte. 
The LED visually indicates that current is going through the circuit.
*/
#define checkPin 12 //Arduino digital pin used to test connectivity

//***********************************************************************************************
//** Real Bit Level Boolean Utilisation Macro Definitions                                      **
//** Created by Trevor D.BEYDAG 09 May 2016                                                    **
//** http://lab.dejaworks.com/using-real-1-bit-boolean-variable-for-arduino-memory-efficiency/ **
//** Please keep credits intact when using and/or reproducing                                  **
//***********************************************************************************************
#define TRUEbit(boolByte, bitNumber)    boolByte |= bitNumber
#define FALSEbit(boolByte, bitNumber)   boolByte &= ~(bitNumber)
#define READbit(boolByte, bitNumber)    bool(boolByte & bitNumber)

#define bit_0        1      //B00000001
#define bit_1        2      //B00000010   
#define bit_2        4      //B00000100   
#define bit_3        8      //B00001000   
#define bit_4        16     //B00010000   
#define bit_5        32     //B00100000   
#define bit_6        64     //B01000000   
#define bit_7        128    //B10000000

byte boolByte_0 = 0;        //Required Default Byte for checkDevice() function to work!
byte boolByte_1 = 0;        //B00000000 = Everything Disabled

bool checkDevice(uint8_t detectPin, byte &boolByte = boolByte_0, byte bit_ref = bit_0);

void setup() {
  Serial.begin(9600);
  pinMode(checkPin, INPUT);
}

void loop() {
  //Example using only pin to verify, displaying return value.
  Serial.print(checkDevice(checkPin));
  //Example choosing Byte and bit to modify.
  Serial.print(checkDevice(checkPin, boolByte_0, bit_0));
  //Example showing stored boolean value.
  Serial.println(READbit(boolByte_0, bit_0));  
  delay(500);
}

//checkDevice(InputPinToVerify, boolByteName, bitNumberReference);
bool checkDevice(uint8_t detectPin, byte &boolByte, byte bit_ref) {
  bool plugedIn = digitalRead(detectPin); //Read voltage on pin
  if(plugedIn == 1) {                     //IF pin is HIGH
    TRUEbit(boolByte, bit_ref);           //Store value
    return true;                          //Return value
  }
  else {                                  //IF pin is LOW
    FALSEbit(boolByte, bit_ref);          //Store value
    return false;                         //Return value
  }
}