Sharp Optical Dust Sensor (GP2Y1010AU0F) measurements very inaccurate

I’m using this dust sensor and taking a measurement every time my program comes out of Sleep from the Watchdog Timer. Before sleep the values seem normal but after the first sleep and from there on out the values remain the same and don’t change even if I “poke” at the sensor. The sensor has worked before and runs perfectly in a program that just reads from the sensor alone. Any thoughts?

I attached a diagram of my setup (also using DHT22).

You do know that you're running above specification with that wiring? A single Arduino pin must not be loaded with more than 20mA, the typical power (not maximum) of the sensor for the LED and the amplifier is 21mA going up to 40mA.

Any thoughts?

It might help to see the faulty code.

I have tried it now with the power supplied from Vin but the values remain the same.

Does the datasheet of the sensor mention anything about behavior after sleep?

  1. can you post a link to the datasheet?

  2. can you try to reinitialize the sensor after a wakeup?

Datasheet ^

robtillaart, what exactly do you mean by reinitializing? I have a small delay after wakeup then I take 100 measurements then average them out.

I tell you again: show us your code! And provide links to all libraries used (if any).

There are many different ways to put an Arduino to sleep, some of them need special code after wake-up.

#include <avr/sleep.h>
#include <avr/wdt.h>
#include <avr/power.h>

for (int i = 0; i < endInterval; i++) {
      startSleep(wdtInterval);
      sleep_disable();
    }
    wakeup();
ISR(WDT_vect) {
  wdt_disable();
}

void startSleep(byte wdtInterval) {
//  Serial.begin(baudRate);
//  Serial.println("Going to Sleep");
//  Serial.end();

  noInterrupts();
  
  MCUSR = 0; //reset flags
  //WDT configuration
  WDTCSR |= 0b00011000; //WDTCSR |= (1<<WDCE) | (1<<WDE);
  //WDT settings
  WDTCSR = 0b01000000 | wdtInterval;
    //could otherwise use --> WDTO_8S; /WDTCSR = (1<<WDIE) | (1<<WDE) | (0<<WDP3) | (1<<WDP2) | (1<<WDP1) | (0<<WDP0);

  wdt_reset();
  
//  // turn off brown-out enable in software
//  MCUCR = bit (BODS) | bit (BODSE);
//  MCUCR = bit (BODS); 
  previousADCSRA = ADCSRA; //
  ADCSRA = 0; //
//  ADCSRA &= ~(1<<ADEN); //Disable ADC
//  ACSR = (1<<ACD); //Disable the analog comparator
//  DIDR0 = 0x3F; //Disable digital input buffers on all ADC0-ADC5 pins
//  DIDR1 = (1<<AIN1D)|(1<<AIN0D); //Disable digital input buffer on AIN1/0
  power_all_disable(); //
//  power_twi_disable();
//  power_spi_disable();
//  power_usart0_disable(); //Needed for serial.print
//  power_timer0_disable(); //Needed for delay and millis()
//  power_timer1_disable();
//  power_timer2_disable(); //Needed for asynchronous 32kHz operation

  set_sleep_mode(SLEEP_MODE_PWR_DOWN);

  sleep_enable();
  interrupts();
  sleep_cpu(); //go to sleep now
}

void wakeup() {
  ADCSRA = previousADCSRA; //
  power_all_enable(); //
//  power_twi_enable();
//  power_spi_enable();
//  power_usart0_enable();
//  power_timer0_enable();
//  power_timer1_enable();
//  power_timer2_enable();
//  power_adc_enable();
//   BOD is automatically restarted at wakeup
  
  Serial.begin(baudRate);
  Serial.println("Awake");
  Serial.end();
}

Well, that is part of the code, but not the part with the problem.

Keep going, you will figure this out eventually!