       lcd.print("Check WiFi");
     }
   }
-  lastKeyStroke = millis(); //start considering keystrokes as soon as setup() is finished
+  if (!bootError) { //if there is no error during boot, initialize the ultrasonic sensor and the keystrokes
+    pinMode(US_GROUND, OUTPUT); //be careful here not to cause reverse connection of power and ground
+    pinMode(US_VCC, OUTPUT);
+    digitalWrite(US_GROUND, LOW);
+    digitalWrite(US_VCC, HIGH);
+    sonar.attach(TRIG_PIN, ECHO_PIN); //initialize the presence detecting ultrasonic sensor (SR04)
+    lastKeyStroke = millis(); //start considering keystrokes as soon as setup() is finished
+  }
 }
 
 void loop() {

const unsigned short DEBUG = OFF; //debug information on Serial
boolean bootError = false;
const unsigned short MAX_VALIDATION_EFFORTS = 5; //max amount of efforts to try and reconnect to the network if you have failed in setup()

void setup() {
  keyboard.begin(DataPin, IRQpin);

  if (screenOn && (millis() > lastKeyStroke + SCREEN_TIMEOUT)) { //if the screen is ON, then check whether the last key stroke occured more than SCREEN_TIMEOUT milliseconds ago
    screenOn = false;
    lcd.setBacklight(LOW); //turn the screen's backlight off to decrease power consumption
  }
  if (!screenOn && (millis() > lastMeasurement + US_INTERVAL)) {
    if (sonar.getMedianDistance()) { //if something was detected, turn the screen on, use median distance, so to filter out false positive results
      screenOn = true;
      lcd.setBacklight(HIGH);
      lastKeyStroke = millis(); //pretend there was a keystroke, so the screen will stay on for some time, after detecting movement
    }
    lastMeasurement = millis();
  }
  if (keyboard.available()) {
    lastKeyStroke = millis(); //record when keyboard was used last
