     }
     delay(100);
   }
-
-  sleepNow();
+  attachInterrupt(digitalPinToInterrupt(3), record, RISING);
 }
 
 void loop() {
-  digitalWrite(ledPin, HIGH);
+  if (dorecored == true) {
+    digitalWrite(ledPin, HIGH);
+    int microStatus = digitalRead(microPin);
+    int nanoStatus  = digitalRead(nanoPin);
 
-  int microStatus = digitalRead(microPin);
-  int nanoStatus  = digitalRead(nanoPin);
+    rangeStatus = microStatus << 1;
+    rangeStatus = rangeStatus + nanoStatus;
 
-  rangeStatus = microStatus << 1;
-  rangeStatus = rangeStatus + nanoStatus;
+    int16_t results;
+    float multiplier = 0.125F;
+    //results = ads.readADC_Differential_0_1();
+    results = ads.getLastConversionResults_no_delay();
 
-  int16_t results;
-  float multiplier = 0.125F;
-  results = ads.readADC_Differential_0_1();
+    payload.data1 = results * multiplier ;
+    payload.data2 = rangeStatus;
 
-  /*
-  Serial.print("noOfWakeup : ");
-  Serial.print(noOfWake);
-  Serial.print(" : counterForloop : ");
-  Serial.print(counterForloop);
-  Serial.print(" : rangeStatus : ");
-  Serial.print(rangeStatus);
-  Serial.print(" : results : ");
-  Serial.print(results * multiplier);
-  Serial.print(" mA ----> ");
-  */
+    payload._salt = recordNo ;
+    payload.volt = 3300;
 
-  /*
-  if (counterForloop > (counterForloop_old + 10)) {
-    checkRecordBttn();
+    ads.readADC_Differential_0_1_no_delay();
+    
+    radio.write(&payload , sizeof(payload));
+    
+    digitalWrite(ledPin, LOW);
+  } else {
+    digitalWrite(ledPin, LOW);
   }
-  */
-
-  payload.data1 = results * multiplier ;
-  payload.data2 = rangeStatus;
-
-  payload._salt = noOfWake ;
-  //payload.volt = readVcc();
-  payload.volt = 3300;
-
-  /*
-  Serial.print(payload.data1);
-  Serial.print(" : data2 : ");
-  Serial.println(payload.data2);
-  */
-  
-  //if ( rangeStatus == 1 || rangeStatus == 3 || rangeStatus == 2 ) {
-  //if ( rangeStatus != 0 ) {
-  
-    //radio.powerUp();
-    radio.write(&payload , sizeof(payload));
-    //radio.powerDown();
-  //}
-
-  digitalWrite(ledPin, LOW);
-  counterForloop++;
-  //delay(30);
 }
-
-int readVcc() {
-  adc_enable();
-  // Read 1.1V reference against AVcc
-  // set the reference to Vcc and the measurement to the internal 1.1V reference
-#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
-  ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
-#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
-  ADMUX = _BV(MUX5) | _BV(MUX0);
-#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
-  ADMUX = _BV(MUX3) | _BV(MUX2);
-#else
-  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
-#endif
-
-  delay(2); // Wait for Vref to settle
-  ADCSRA |= _BV(ADSC); // Start conversion
-  while (bit_is_set(ADCSRA, ADSC)); // measuring
-
-  uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH
-  uint8_t high = ADCH; // unlocks both
-
-  long result = (high << 8) | low;
-
-  result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
-  adc_disable();
-
-  return (int)result; // Vcc in millivolts
-}
-

RF24 radio(CE_PIN, CSN_PIN);
Adafruit_ADS1115 ads(0x48);

// analogPin 3 / 2 / 1 / int 0
const int wakeupPin = 2;
const int recordPin = 17;
const int nanoPin   = 16;
const int microPin  = 15;
const int ledPin    = 14;

int rangeStatus;
volatile unsigned long counterForloop;
volatile unsigned long counterForloop_old;
volatile boolean checkRangenow;
volatile int noOfWake;

void checkRange() {
  checkRangenow = true;
}

void wakeUp() {
  noOfWake++;
  counterForloop_old = counterForloop;
  checkRangenow = true;
  //detachInterrupt(digitalPinToInterrupt(2));
  radio.powerUp();
  checkRecordBttn();
}

void sleepNow() {
  radio.powerDown();
  digitalWrite(ledPin, LOW);
  attachInterrupt(digitalPinToInterrupt(2), wakeUp, FALLING);
  LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
}

void checkRecordBttn() {
  attachInterrupt(digitalPinToInterrupt(2), sleepNow, FALLING);
}

void setup() {
  //Serial.begin(115200);

  delay(20);
  adc_disable();

  pinMode(recordPin, INPUT_PULLUP);
  pinMode(wakeupPin, INPUT_PULLUP);
  pinMode(microPin, INPUT_PULLUP);
  pinMode(nanoPin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);

  int microStatus = digitalRead(microPin);
  int nanoStatus  = digitalRead(nanoPin);

  radio.setPayloadSize(11);
  radio.openWritingPipe(pipes[2]);
  radio.stopListening();
  //radio.powerDown();

  payload._salt = 0;
  payload.devid = DEVICE_ID;

  ads.setGain(GAIN_ONE);
  ads.begin();
  ads.readADC_Differential_0_1_no_delay();

  for (int k = 0; k < 10; k = k + 1) {
    if (k % 2 == 0) {
