    
   stateArmed = digitalRead(buttonArmed);
   if(stateArmed == HIGH) {
-    digitalWrite(ledPinArmed, HIGH);
-    root["sensorArmed"] = true;
-    root["currentLatitude"] = "-23.566999";
-    root["currentLongitude"] = "-46.6338";
+    lockCar();
   }
 
   stateDisarmed = digitalRead(buttonDisarmed);
   if(stateDisarmed == HIGH && root["sensorArmed"]) {
-    digitalWrite(ledPinArmed, LOW);
-    digitalWrite(ledPinDisarmed, HIGH);
-    root["triggeredAlarm"] = true;
+    unlockCar();
   }
 
   if(root["sensorArmed"] && root["triggeredAlarm"]) {
     tone(buzzerAlarm, 2000);
 
     if(stateArmed == HIGH) {
-      tone(buzzerAlarm, 3000);
-      delay(500);
-      tone(buzzerAlarm, 4000);
-      delay(500);
-      tone(buzzerAlarm, 3000);
-      delay(500);
-      noTone(buzzerAlarm);
-      digitalWrite(ledPinDisarmed, LOW);
-      root["triggeredAlarm"] = false;
-      root["sensorArmed"] = true;
+      resetAlarm();
     }
   }
 

  root["currentLongitude"] = "";
}

void loop() { 
  if (Serial.available() > 0) {
    // read the incoming byte:

    if(incomingByte == 76) {
      // SEND L(OKED)
      if(!root["sensorArmed"]) {
        lockCar();
      }
    } else if(incomingByte == 85) {
      // SEND U(NLOCKED)
      if(root["sensorArmed"]) {
        unlockCar();
      }
    } else if(incomingByte == 82) {
      // SEND R(ESET)
      if(root["sensorArmed"] && root["triggeredAlarm"]) {
        resetAlarm();
      }
    }
  
