-->
Page 1 of 4

CONNECTING SHARP GP2Y1010AU0F to ADC

PostPosted: Sat Jan 30, 2016 10:16 am
by pomelo
Guys,
i'm just starting with it, please be patient.

I plan to make a small indoor Air Quality meter with the WAVESHARE sharp module: (https://botland.com.pl/index.php?controller=attachment&id_attachment=1286).

I plug it into 3.3 ,GND, A0 and D6.

Everything seems to work fine, but the ADC raw values do not exceed: RAW Analog: 114

I read that ESP has 1.0V on ADC, the sensor has 5.0V - how can i make it work ? Is it possible to be done with software only, without any additional hardware?

Serial Output:
Code: Select allRAW Analog: 45 miliVOLT: 2016.99 DUST ug/m3: 403.40
RAW Analog: 44 miliVOLT: 1963.28 DUST ug/m3: 392.66
RAW Analog: 41 miliVOLT: 1802.15 DUST ug/m3: 360.43
RAW Analog: 40 miliVOLT: 1748.44 DUST ug/m3: 349.69
RAW Analog: 43 miliVOLT: 1909.57 DUST ug/m3: 381.91
RAW Analog: 38 miliVOLT: 1641.02 DUST ug/m3: 328.20
RAW Analog: 35 miliVOLT: 1479.88 DUST ug/m3: 295.98
RAW Analog: 36 miliVOLT: 1533.59 DUST ug/m3: 306.72
RAW Analog: 36 miliVOLT: 1533.59 DUST ug/m3: 306.72
...
RAW Analog: 115 miliVOLT: 5776.76 DUST ug/m3: 1155.35
RAW Analog: 114 miliVOLT: 5723.05 DUST ug/m3: 1144.61
RAW Analog: 114 miliVOLT: 5723.05 DUST ug/m3: 1144.61
RAW Analog: 115 miliVOLT: 5776.76 DUST ug/m3: 1155.35
RAW Analog: 89 miliVOLT: 4380.27 DUST ug/m3: 876.05
RAW Analog: 113 miliVOLT: 5669.34 DUST ug/m3: 1133.87
RAW Analog: 90 miliVOLT: 4433.98 DUST ug/m3: 886.80
RAW Analog: 72 miliVOLT: 3467.19 DUST ug/m3: 693.44


The sheets say max ug/m3 is 500, however i get 1133 and i believe it can be caused by the ADC as the code works perfectly on Arduino UNO..

Code below, taken from WaveShare and modified to fit ESP pins.

Code: Select all/*********************************************************************************************************
*
* File                : DustSensor
* Hardware Environment:
* Build Environment   : Arduino
* Version             : V1.0.5-r2
* By                  : WaveShare
*
*                                  (c) Copyright 2005-2011, WaveShare
*                                       http://www.waveshare.net
*                                       http://www.waveshare.com   
*                                          All Rights Reserved
*
*********************************************************************************************************/
#define        COV_RATIO                       0.2            //ug/mmm / mv
#define        NO_DUST_VOLTAGE                 400            //mv
#define        SYS_VOLTAGE                     5000           


/*
I/O define
*/
const int iled = 13;                                            //drive the led of sensor
const int vout = A0;                                            //analog input

/*
variable
*/
float density, voltage;
int   adcvalue;

/*
private function
*/
int Filter(int m)
{
  static int flag_first = 0, _buff[10], sum;
  const int _buff_max = 10;
  int i;
 
  if(flag_first == 0)
  {
    flag_first = 1;

    for(i = 0, sum = 0; i < _buff_max; i++)
    {
      _buff[i] = m;
      sum += _buff[i];
    }
    return m;
  }
  else
  {
    sum -= _buff[0];
    for(i = 0; i < (_buff_max - 1); i++)
    {
      _buff[i] = _buff[i + 1];
    }
    _buff[9] = m;
    sum += _buff[9];
   
    i = sum / 10.0;
    return i;
  }
}


void setup(void)
{
  pinMode(iled, OUTPUT);
  digitalWrite(iled, LOW);                                     //iled default closed
 
  Serial.begin(9600);                                         //send and receive at 9600 baud
  Serial.print("*********************************** WaveShare ***********************************\n");
}

void loop(void)
{
  /*
  get adcvalue
  */
  digitalWrite(iled, HIGH);
  delayMicroseconds(280);
  adcvalue = analogRead(vout);
  digitalWrite(iled, LOW);
 
 // adcvalue = Filter(adcvalue);
 
  /*
  covert voltage (mv)
  */
  voltage = (SYS_VOLTAGE / 1024.0) * adcvalue * 11;
 
  /*
  voltage to density
  */
  if(voltage >= NO_DUST_VOLTAGE)
  {
    voltage -= NO_DUST_VOLTAGE;
   
    density = voltage * COV_RATIO;
  }
  else
    density = 0;
   
  /*
  display the result
  */

   Serial.print("RAW Analog: "+String(adcvalue)+" miliVOLT: "+String(voltage)+" DUST ug/m3: "+String(density)+"\n");

 
 
  delay(1000);
}

























Re: CONNECTING SHARP GP2Y1010AU0F to ADC

PostPosted: Sat Jan 30, 2016 10:39 am
by pomelo
pomelo wrote:Guys,
i'm just starting with it, please be patient.

I plan to make a small indoor Air Quality meter with the WAVESHARE sharp module: (https://botland.com.pl/index.php?controller=attachment&id_attachment=1286).

I plug it into 3.3 ,GND, A0 and D6.

Everything seems to work fine, but the ADC raw values do not exceed: RAW Analog: 1145

I read that ESP has 1.0V on ADC, the sensor has 5.0V - how can i make it work ? Is it possible to be done with software only, without any additional hardware?

Serial Output:
Code: Select allRAW Analog: 45 miliVOLT: 2016.99 DUST ug/m3: 403.40
RAW Analog: 44 miliVOLT: 1963.28 DUST ug/m3: 392.66
RAW Analog: 41 miliVOLT: 1802.15 DUST ug/m3: 360.43
RAW Analog: 40 miliVOLT: 1748.44 DUST ug/m3: 349.69
RAW Analog: 43 miliVOLT: 1909.57 DUST ug/m3: 381.91
RAW Analog: 38 miliVOLT: 1641.02 DUST ug/m3: 328.20
RAW Analog: 35 miliVOLT: 1479.88 DUST ug/m3: 295.98
RAW Analog: 36 miliVOLT: 1533.59 DUST ug/m3: 306.72
RAW Analog: 36 miliVOLT: 1533.59 DUST ug/m3: 306.72
...
RAW Analog: 115 miliVOLT: 5776.76 DUST ug/m3: 1155.35
RAW Analog: 114 miliVOLT: 5723.05 DUST ug/m3: 1144.61
RAW Analog: 114 miliVOLT: 5723.05 DUST ug/m3: 1144.61
RAW Analog: 115 miliVOLT: 5776.76 DUST ug/m3: 1155.35
RAW Analog: 89 miliVOLT: 4380.27 DUST ug/m3: 876.05
RAW Analog: 113 miliVOLT: 5669.34 DUST ug/m3: 1133.87
RAW Analog: 90 miliVOLT: 4433.98 DUST ug/m3: 886.80
RAW Analog: 72 miliVOLT: 3467.19 DUST ug/m3: 693.44


The sheets say max ug/m3 is 500, however i get 1133 and i believe it can be caused by the ADC as the code works perfectly on Arduino UNO..

Code below, taken from WaveShare and modified to fit ESP pins.

Code: Select all/*********************************************************************************************************
*
* File                : DustSensor
* Hardware Environment:
* Build Environment   : Arduino
* Version             : V1.0.5-r2
* By                  : WaveShare
*
*                                  (c) Copyright 2005-2011, WaveShare
*                                       http://www.waveshare.net
*                                       http://www.waveshare.com   
*                                          All Rights Reserved
*
*********************************************************************************************************/
#define        COV_RATIO                       0.2            //ug/mmm / mv
#define        NO_DUST_VOLTAGE                 400            //mv
#define        SYS_VOLTAGE                     5000           


/*
I/O define
*/
const int iled = 13;                                            //drive the led of sensor
const int vout = A0;                                            //analog input

/*
variable
*/
float density, voltage;
int   adcvalue;

/*
private function
*/
int Filter(int m)
{
  static int flag_first = 0, _buff[10], sum;
  const int _buff_max = 10;
  int i;
 
  if(flag_first == 0)
  {
    flag_first = 1;

    for(i = 0, sum = 0; i < _buff_max; i++)
    {
      _buff[i] = m;
      sum += _buff[i];
    }
    return m;
  }
  else
  {
    sum -= _buff[0];
    for(i = 0; i < (_buff_max - 1); i++)
    {
      _buff[i] = _buff[i + 1];
    }
    _buff[9] = m;
    sum += _buff[9];
   
    i = sum / 10.0;
    return i;
  }
}


void setup(void)
{
  pinMode(iled, OUTPUT);
  digitalWrite(iled, LOW);                                     //iled default closed
 
  Serial.begin(9600);                                         //send and receive at 9600 baud
  Serial.print("*********************************** WaveShare ***********************************\n");
}

void loop(void)
{
  /*
  get adcvalue
  */
  digitalWrite(iled, HIGH);
  delayMicroseconds(280);
  adcvalue = analogRead(vout);
  digitalWrite(iled, LOW);
 
 // adcvalue = Filter(adcvalue);
 
  /*
  covert voltage (mv)
  */
  voltage = (SYS_VOLTAGE / 1024.0) * adcvalue * 11;
 
  /*
  voltage to density
  */
  if(voltage >= NO_DUST_VOLTAGE)
  {
    voltage -= NO_DUST_VOLTAGE;
   
    density = voltage * COV_RATIO;
  }
  else
    density = 0;
   
  /*
  display the result
  */

   Serial.print("RAW Analog: "+String(adcvalue)+" miliVOLT: "+String(voltage)+" DUST ug/m3: "+String(density)+"\n");

 
 
  delay(1000);
}

























Re: CONNECTING SHARP GP2Y1010AU0F to ADC

PostPosted: Sat Jan 30, 2016 10:46 am
by martinayotte
The ADC of ESP is really 0-1V range (0-1023 value).
If your sensor is outputting different range, ESP can still read low values, but as soon the sensors will output something higher, the read value will be saturated to 1023.
So, it is suggested to add 2 resistors to provide simple voltage divider.

Re: CONNECTING SHARP GP2Y1010AU0F to ADC

PostPosted: Sat Jan 30, 2016 10:56 am
by pomelo
martinayotte wrote:The ADC of ESP is really 0-1V range (0-1023 value).
If your sensor is outputting different range, ESP can still read low values, but as soon the sensors will output something higher, the read value will be saturated to 1023.
So, it is suggested to add 2 resistors to provide simple voltage divider.



Thank you very much.

How can i check if my ESP is really returning 0-1023 ?