#define in1 9       //PWM Motors
#define in2 10      //PWM Motors
#define in3 4       //External lights
#define in4 5       //External lights
#define pinPir 6    //PIR sensor
#define pinRele 8   //Color lights
#define pinHallE1 0 //Hall Effect Up
#define pinHallE2 1 //Hall Effect Down

int valHallE1 = 0;
int valHallE2 = 0;
int statusPir = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  pinMode(pinRele, OUTPUT);
  pinMode(pinPir, INPUT);
  digitalWrite(in4, LOW);
  analogWrite(in1, 0);
  analogWrite(in2, 0);
  digitalWrite(pinRele, HIGH);
  //digitalWrite(in3, HIGH);
  //digitalWrite(in4, LOW);
}

void loop() {

  statusPir = digitalRead(pinPir);
  //Serial.println(statusPir);
  //conditions
  if(statusPir == 1){ //Movement detected
    Serial.println("Sensor activado");
    //digitalWrite(pinRele, HIGH); //Turn on color lights
    valHallE1 = analogRead(pinHallE1);  
    while(valHallE1 > 507){ //while not detect variation on Hall Efect 1 then move motors up
      analogWrite(in1, 255);
      analogWrite(in2, 0);
      valHallE1 = analogRead(pinHallE1);
    }
    analogWrite(in1, 0); //Stop motors
    //digitalWrite(pinRele, LOW); //Turn off color lights
    delay(100);
  }
  
  if(statusPir == 0) {
    Serial.println("Sensor desactivado");
    //digitalWrite(in3, HIGH); //Turn on white lights
    valHallE2 = analogRead(pinHallE2);  
    while(valHallE2 > 498){ //while not detect variation on Hall Efect 2 then move motors down
      analogWrite(in1, 0);
      analogWrite(in2, 140);
      valHallE2 = analogRead(pinHallE2);
    }
    analogWrite(in2, 0); //Stop motors
    //digitalWrite(in3, LOW); //Turn off white lights
    delay(100);
  }
  delay(100);
}
