Sensors will no read after wake up from sleep mode

I’m having a problem with using sleep mode, with Uno
My project consists of a DHT22 reading temp and humidity and a Max 9814 microphone which i have setup to read frequency.
I’ve setup a sim800L to connect the project to thingspeak, this is all working fine, until I wanted to enable a sleep mode to save on battery.
I attached a RTC to my uno, to enable an interrupt to wake the uno but when it wakes my sensors are not being read, I feel that the ADC has not restarted fast enough but I cant figure out where to put the delay to give it more time or maybe I need to manually call for the ADC to be turned back on.
Here is the code I’m using

#include <SoftwareSerial.h>
#include "LowPower.h"
SoftwareSerial gprsSerial(7,4);
#include <String.h>
#include <DHT.h> 
#define DHTPIN 8       // DHT-22 Output Pin connection
#define DHTTYPE DHT22   // DHT Type is DHT 22 (AM2302)
 
DHT dht(DHTPIN, DHTTYPE);
#include "arduinoFFT.h"
 
#define SAMPLES 64             //SAMPLES-pt FFT. Must be a base 2 number. Max 128 for Arduino Uno.
#define SAMPLING_FREQUENCY 500 //Ts = Based on Nyquist, must be 2 times the highest expected frequency.
 
arduinoFFT FFT = arduinoFFT();
 
unsigned int samplingPeriod;
unsigned long microSeconds;

double vReal[SAMPLES]; //create vector of size SAMPLES to hold real values
double vImag[SAMPLES]; //create vector of size SAMPLES to hold imaginary values

// Use pin 2 as wake up pin
const int wakeUpPin = 2;

void wakeUp()
{
}
 
void setup()
{
  // Configure wake up pin as input.
    // This will consumes few uA of current.
  pinMode(wakeUpPin, INPUT_PULLUP);
  delay(50); 
  gprsSerial.begin(9600);               // the GPRS baud rate   
  Serial.begin(9600);
  dht.begin();
  samplingPeriod = round(1000000*(1.0/SAMPLING_FREQUENCY)); //Period in microseconds 
  delay(1000);
    
  
}
 
void loop()
{
      // Allow wake up pin to trigger interrupt on low.
    attachInterrupt(0, wakeUp, LOW);
    // Enter power down state with ADC and BOD module disabled. Wake up when wake up pin is low
  Serial.println("Sleep for 8s....");
  delay(100);
    // Enter power down state with ADC and BOD module disabled.
    // Wake up when wake up pin is low.
    LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); 
    
     // Disable external pin interrupt on wake up pin.
    

      // Do something here
  if (wakeUpPin,LOW) {
      // Woke up from an interrupt

  }
  
  else {
      // Woke up from sleep
  }
      
      float h = dht.readHumidity();
      float t = dht.readTemperature();
    
      /*Sample SAMPLES times*/
    for(int i=0; i<SAMPLES; i++)
    {
        microSeconds = micros();    //Returns the number of microseconds since the Arduino board began running the current script. 
     
        vReal[i] = analogRead(1); //Reads the value from analog pin 0 (A0), quantize it and save it as a real term.
        vImag[i] = 0; //Makes imaginary term 0 always

        /*remaining wait time between samples if necessary*/
        while(micros() < (microSeconds + samplingPeriod))
        {}
          //do nothing
        
    }
 
    /*Perform FFT on samples*/
    FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
    FFT.Compute(vReal, vImag, SAMPLES, FFT_FORWARD);
    FFT.ComplexToMagnitude(vReal, vImag, SAMPLES);

    /*Find peak frequency and print peak*/
    double peak = FFT.MajorPeak(vReal, SAMPLES, SAMPLING_FREQUENCY);
        
         
      Serial.print("Temperature = ");
      Serial.print(t);
      Serial.println(" °C");
      Serial.print("Humidity = ");
      Serial.print(h);
      Serial.println(" %");
      Serial.print("Frequency = ");
      Serial.print(peak);
      Serial.println(" Hz");  
      
   
  if (gprsSerial.available())
    Serial.write(gprsSerial.read());
 
  gprsSerial.println("AT");
  delay(1000);
 
  gprsSerial.println("AT+CPIN?");
  delay(1000);
 
  gprsSerial.println("AT+CREG?");
  delay(1000);
 
  gprsSerial.println("AT+CGATT?");
  delay(1000);
 
  gprsSerial.println("AT+CIPSHUT");
  delay(1000);
 
  gprsSerial.println("AT+CIPSTATUS");
  delay(2000);
 
  gprsSerial.println("AT+CIPMUX=0");
  delay(2000);
 
  ShowSerialData();
 
  gprsSerial.println("AT+CSTT=\"TM\"");//start task and setting the APN,
  delay(1000);
 
  ShowSerialData();
 
  gprsSerial.println("AT+CIICR");//bring up wireless connection
  delay(3000);
 
  ShowSerialData();
 
  gprsSerial.println("AT+CIFSR");//get local IP adress
  delay(2000);
 
  ShowSerialData();
 
  gprsSerial.println("AT+CIPSPRT=0");
  delay(3000);
 
  ShowSerialData();
  
  gprsSerial.println("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",\"80\"");//start up the connection
  delay(6000);
 
  ShowSerialData();
 
  gprsSerial.println("AT+CIPSEND");//begin send data to remote server
  delay(4000);
  ShowSerialData();
  
  String str="GET https://api.thingspeak.com/update?api_key=82QIO8FEA10U7GZQ&field1=" + String(t) +"&field2="+String(h)+"&field3="+String(peak);
  Serial.println(str);
  gprsSerial.println(str);//begin send data to remote server
  
  delay(4000);
  ShowSerialData();
 
  gprsSerial.println((char)26);//sending
  delay(5000);//waitting for reply, important! the time is base on the condition of internet 
  gprsSerial.println();
 
  ShowSerialData();
 
  gprsSerial.println("AT+CIPSHUT");//close the connection
  delay(100);
  ShowSerialData();

  delay(5000);

detachInterrupt(0);
}

void ShowSerialData()
{
  while(gprsSerial.available()!=0)
  Serial.write(gprsSerial.read());
  delay(5000); 
  
}

If anyone has an idea, that would be most helpful
Thank you

I can't help with the problem, but someone may help if you explained how you KNOW the sensors are not being read.
Paul

Not helping, but an Uno is a poor choice if battery life is important. You can put the 328P in power saving mode but how about USB-to-TTL converter that's on the board.

You might try saving the state of the ADC before going to sleep, and restoring it right after you wake up. It would be the value of the ADCSRA register.

The other possible thing is to change the RTC interrupt from LOW to FALLING just to make sure you only get one interrupt.

It may be nothing but I thought I read somewhere - possibly to do with 328p sleep modes and power saving - that you should throw away the 1st ADC reading after waking from sleep.

Please post a photo of a clear, hand drawn wiring diagram, with pins and parts labeled (including the power supply).

If the Sim800, and other peripherals are not sleeping or powered down, you are probably just wasting your time experimenting with sleep modes, especially with an Uno.

I actually figured it out late last night. I had all my measurements setups in void setup and it was going straight into loop after wake and wasn't being told to do anything.
My plan is build a PCB with just the amega328p chip, I was only doing on my testing using the uno.
Thanks for all the help tho

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.