Implement GRBL

Good evening!
I am Felipe and build a plotter using as a controller the arduino uno + CNC shield V3 + two drivers A4988a coreXY movement with two step motors moving the car in the guides. The firmware is grbl and I send the code through the PuTTY serial or Bcnc, everything works perfectly.

In parallel I tested a firmware for LDR control which also worked perfectly on arduino uno too.

Now I need my hardware with GRBL to be implemented with LDR control so that when I need to read the LDR sensor, it will sequence to XY if not it repeats Z servo movement (Gcode M3S90 and M5) until the sensor read correctly for XY motion sequence
I tried to activate an analog input without success and neither tried to use the digital feedback because I understand that I do not need to activate anything external but inside on the firmware for XY motion sequence.
Thanks, if anyone can help me.

//Sensor de luz com LDR

int ledPin = 7; //Led no pino 7
int ldrPin = 0; //LDR no pino analígico 8
int ldrValor = 0; //Valor lido do LDR

void setup() {
pinMode(ledPin,OUTPUT); //define a porta 7 como saída
Serial.begin(9600); //Inicia a comunicação serial
}

void loop() {
///ler o valor do LDR
ldrValor = analogRead(ldrPin); //O valor lido será entre 0 e 1023

//se o valor lido for maior que 500, liga o led
if (ldrValor>= 800) digitalWrite(ledPin,HIGH);
// senão, apaga o led
else digitalWrite(ledPin,LOW);

//imprime o valor lido do LDR no monitor serial
Serial.println(ldrValor);
delay(100);
}