   lcd.print("                ");
 
 }
+
+// Sensors
+
+void motorSwitchLeftActivated() {
+  state = MOTOR_SWITCH_DETECTED;
+  motorSwitchDetected = MOTOR_SWITCH_LEFT;
+}
+
+void motorSwitchRightActivted() {
+  state = MOTOR_SWITCH_DETECTED;
+  motorSwitchDetected = MOTOR_SWITCH_RIGHT;
+}
+
+void motorSwitchActivated() {
+  state = PUBLISHING_ENVIRONMENT_EVENT;
+  if (motorSwitchDetected == MOTOR_SWITCH_LEFT) {
+    lcdStatus("Switch Left");
+    publishDebug("Left Motor Switch Detected");
+  } else {
+    lcdStatus("Switch Right");
+    publishDebug("Right Motor Switch Detected");
+  }
+  delay(1000);
+  digitalWrite(BUILTIN_LED, LOW);
+  state = IDLE;
+}

  PUBLISHING_ENVIRONMENT_EVENT,
  TILTING_TRAY_LEFT,
  TILTING_TRAY_RIGHT,
  OTA_IN_PROGRESS
};

SystemState state = IDLE;


void loop() {

  switch (state) {
    case MOTOR_SWITCH_DETECTED:
      digitalWrite(BUILTIN_LED, HIGH);
      motorSwitchActivated();
      break;
    default:
      break;
  }

  if (isEnvironmentTimerComplete == true) {
    isEnvironmentTimerComplete = false;

