Problema codice

#include <HX711.h>
#define LED1 2
#include <SD.h>
#include <SPI.h>
#define PULSANTE 9

File myFile;
const int pinCS = 10;
HX711 cell(5, 4);

int val = 0;
volatile byte stato = LOW;
long lastBlink = millis();
int ledState = LOW;
float zero;
float lecture;
float attuale;
int potentiometerPin = A0;
int value = 0;
int potentiometer = 0;
int spostamento = 0;
int delta_spostamento = 0;
int spostamentoprec = 0;

void debug() {

  value = analogRead(potentiometerPin); // leggo valore potenziometro
  attuale = cell.read();
  lecture = attuale - zero;

  if ( value - potentiometer >= 0 ) {

    spostamento = spostamento  + (value - potentiometer);
    delta_spostamento = spostamento - spostamentoprec;
    if ( lecture < 0 ) lecture = lecture * (-1);

  } else {

    spostamento = spostamento + (potentiometer - value);
    delta_spostamento = spostamento - spostamentoprec;
    if ( lecture < 0 ) lecture = lecture * (-1);

  }

  potentiometer = value;
  spostamentoprec = spostamento;
  zero = attuale;

  Serial.print(delta_spostamento);
  Serial.print(",");
  Serial.println(lecture);

  myFile = SD.open("test.txt", FILE_WRITE);

  if (myFile) {

    myFile.print(millis());
    myFile.print(",");
    myFile.print(delta_spostamento);
    myFile.print(",");
    myFile.println(lecture);
    myFile.close(); // close the file

  } else {

    Serial.println("error opening test.txt");
    blinkErorr(6);

  }

}

void setup() {
  Serial.begin(9600);
  pinMode(pinCS, OUTPUT);
  pinMode(LED1, OUTPUT );
  pinMode(LED_BUILTIN, OUTPUT);

  if (!SD.begin()) { // Initialize SD card
    Serial.println("Could not initialize SD card."); // if return value is false, something went wrong.  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
    blinkErorr(4);
  }

  if (SD.exists("test.txt")) { // if "file.txt" exists, fill will be deleted
    Serial.println("test exists.");
    if (SD.remove("test.txt") == true) {
      Serial.println("Successfully removed file.");
    } else {
      Serial.println("Could not removed file.");
      blinkErorr(5);
    }
  }

  attachInterrupt( digitalPinToInterrupt(2), debug, HIGH );
  Serial.println( "Setup Done" );
  zero = cell.read();
  potentiometer = analogRead(potentiometerPin);
  pinMode(PULSANTE, INPUT);
}


void loop() {
  val = digitalRead(PULSANTE);
  digitalWrite( LED1, ledState );
  if ((val != HIGH)) {
    if ( millis() - lastBlink == 40) {
      lastBlink = millis();
      if ( ledState == LOW )
        ledState = HIGH;
      else
        ledState = LOW;
    }
  } else if (val == HIGH) {
    ledState = LOW;
  }
}

void blinkErorr(int num) {
  for (x = 0; x < num; x++) {
    delay(500);
    digitalWrite(LED_BUILTIN, LOW);
    delay(500);
    digitalWrite(LED_BUILTIN, HIGH);
  }
}

Ho inserito una funzione per far lampeggiare il led integrato sul pin 13 quando si incontra un errore.
Non avendo le librerie del sensore non ho potuto verificare se il programma compila.
Quando non hai il PC collegato è inutile mettere il debug sulla seriale, meglio far lampeggiare un led o ancora meglio un display a 7 segmenti per visualizzare stati o errori.