打印
[DemoCode下载]

GP2Y1010AU0F

[复制链接]
631|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
gp, AC, AD, dc, IO
gp2y1010au_appl_e.pdf (320.78 KB)
NUC230_240 GP2Y1010AU0F.zip (420.38 KB)
使用ADC及GPIO控制GP2Y1010AU0F
公式及原理參考
http://www.howmuchsnow.com/arduino/airquality/
測試得到的資料和空氣品質對照:

3000 + = 很差

1050-3000 = 差

300-1050 = 一般

150-300 = 好

75-150 = 很好

0-75 = 非常好
沙发
天灵灵地灵灵| | 2017-4-6 13:45 | 只看该作者
空气质量检测的方案?

使用特权

评论回复
板凳
huangcunxiake| | 2017-4-6 19:50 | 只看该作者
下载学习学习。

使用特权

评论回复
地板
huangcunxiake| | 2017-4-6 19:50 | 只看该作者
#include <stdio.h>
#include "NUC230_240.h"
/*
PIN DEFINE
Sharp pin 1 (V-LED)   => 5V (connected to 150ohm resister)
Sharp pin 2 (LED-GND) => GND pin
Sharp pin 3 (LED)     => PA1 pin
Sharp pin 4 (S-GND)   => GND pin
Sharp pin 5 (Vo)      => PA0 pin
Sharp pin 6 (Vcc)     => 5V
*/

/*---------------------------------------------------------------------------------------------------------*/
/* Define global variables and constants                                                                   */
/*---------------------------------------------------------------------------------------------------------*/
volatile uint32_t g_u32AdcIntFlag;


void ADC_IRQHandler(void)
{
          PA2=PA2^1;
    g_u32AdcIntFlag = 1;
    ADC_CLR_INT_FLAG(ADC, ADC_ADF_INT); /* clear the A/D conversion flag */
}

/*---------------------------------------------------------------------------------------------------------*/
/* MAIN function                                                                                           */
/*---------------------------------------------------------------------------------------------------------*/
int main(void)
{
   int32_t  i32ConversionData;
       
float calcVoltage,dustDensity;
    /* Unlock protected registers */
    SYS_UnlockReg();   
            /* Enable ADC module clock */
    CLK_EnableModuleClock(ADC_MODULE);
    SystemCoreClockUpdate();  

        /* ADC clock source is 22.1184MHz, set divider to 7, ADC clock is 22.1184/7 MHz */
    CLK_SetModuleClock(ADC_MODULE, CLK_CLKSEL1_ADC_S_HIRC, CLK_CLKDIV_ADC(11));

        /* Disable the GPA0 - GPA3 digital input path to avoid the leakage current. */
    GPIO_DISABLE_DIGITAL_PATH(PA, 0x1);
  
        /* Configure the GPA0 ADC analog input pins */
    SYS->GPA_MFP &= ~(SYS_GPA_MFP_PA0_Msk ) ;
    SYS->GPA_MFP |= SYS_GPA_MFP_PA0_ADC0  ;
    SYS->ALT_MFP1 = 0;
       
        /* Set the ADC operation mode as single, input mode as single-end and enable the analog input channel 2 */
            ADC_Open(ADC, ADC_ADCR_DIFFEN_SINGLE_END, ADC_ADCR_ADMD_SINGLE, 0x1 << 0);

            /* Power on ADC module */
            ADC_POWER_ON(ADC);

            /* Clear the A/D interrupt flag for safe */
            ADC_CLR_INT_FLAG(ADC, ADC_ADF_INT);

            /* Enable the ADC interrupt */
            ADC_EnableInt(ADC, ADC_ADF_INT);
            NVIC_EnableIRQ(ADC_IRQn);

       
       
    /* Configure PA.1 as Output mode*/
    GPIO_SetMode(PA, BIT1, GPIO_PMD_OUTPUT);
    PA1=1;
                while(1)
                {
                                   
            
                        PA1=0; // power on the LED       
      g_u32AdcIntFlag = 0;
                        CLK_SysTickDelay(250); /* Reset the ADC interrupt indicator and Start A/D conversion */
      ADC_START_CONV(ADC);                       
                  CLK_SysTickDelay(3200);
      /* Wait ADC interrupt (g_u32AdcIntFlag will be set at IRQ_Handler function)*/
      while(g_u32AdcIntFlag == 0);
                               /* Get the conversion result of the ADC channel 0 */
                        i32ConversionData = ADC_GET_CONVERSION_DATA(ADC, 0);
                        PA1=1;
                         // 0 - 5V mapped to 0 - 1023 integer values
// recover voltage
calcVoltage = (float)i32ConversionData * (5.0 / 1024.0);
// linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/
                        dustDensity = 0.17 * calcVoltage - 0.1;
                        printf("Dust Density: ");
      printf("%.2f",dustDensity * 1000); // ???????????????( ug/m3 )
      printf(" ug/m3 \n\r");
                        CLK_SysTickDelay(100000);
                }
               
}

/*** (C) COPYRIGHT 2014 Nuvoton Technology Corp. ***/

使用特权

评论回复
5
huangcunxiake| | 2017-4-6 19:52 | 只看该作者
The unit is amazingly sensitive. It easily sees the dust kicked up from walking on a rug or the vapors from cooking. Looking at the graphs below you can see some interesting things. First you can see that things settle down at night when people are not walking around. You can see around noon that my daughter cooked lunch. It's surprising how long it takes for the fine particles to settle down.



ApproachSet UpAn Arduino Ethernet is connected to the Sharp sensor following the schematic in the Sharp GP2Y1010AU0F Spec sheet. The LED connected to pin 2 is turned on, after 0.28ms the analog pin A0 connected to Vo is sampled. 0.04ms later, the LED is turned off and 9.680ms is waited before the 10ms sequence is repeated (Arduino Source Code).Sharp pin 1 (V-LED)   => 5V (connected to 150ohm resister)Sharp pin 2 (LED-GND) => Arduino GND pinSharp pin 3 (LED)     => Arduino pin 2Sharp pin 4 (S-GND)   => Arduino GND pinSharp pin 5 (Vo)      => Arduino A0 pinSharp pin 6 (Vcc)     => 5V
I used a small 40mm fan to help make sure air was circulated thru the Sharp sensor. This probably is not required, but since I am mounting one of the sensors outside in a radiation shield, I wanted to make sure I saw any pollen floating by.
Testing and Calibration The Pancake test :-)
When you read the Sharp GP2Y1010AU0F Spec sheet Fig. 3 shows a Dust density (mg/m^3) versus voltage graph. But the graph starts at over 0.5 VDC. Unfortunately for most of my tests, the voltage was much lower. I entered the values off the graph and calculated a linear equation to approximate the mg/m^3 values.
With the inexpensive Sharp sensor, I wanted to see how sensitive it was and I wanted to try to correlate the voltage to some meaningful metric. I tried a quick match test (blew out a match and let the smoke go over the sensor). The smoke quickly saturated the sensor. I wanted a longer term test. After seeing that the dylos sensor could see my daughter cooking lunch, I decided to do a "pan cake" test. Did you ever notice that after making pancakes in an old cast iron fry pan with butter, that the kitchen hazes up. I set up both the Dylos and Sharp sensors to capture the data to Pachube. This allowed me to compare/calibrate the sensors.
The two graphs are amazingly similar. Applying a simple offset and multiplication factor allowed the data to be overlaid.
(V-0.0356)*120000
The interesting thing is that Dylos has a chart to rate your air relative to other residential environments. The pancake test exceed these by 50X. So there is some question of how sensitive the Sharp unit is at very low particle counts.
Air Quality Chart - Small Count Reading (0.5 micron)+3000 +     = VERY POOR1050-3000  = POOR300-1050   = FAIR150-300    = GOOD75-150     = VERY GOOD0-75       = EXCELLENT

使用特权

评论回复
6
玛尼玛尼哄| | 2017-4-6 21:18 | 只看该作者
这个设备是测PM2.5的?

使用特权

评论回复
7
稳稳の幸福| | 2017-4-9 16:45 | 只看该作者
可以直接定义个曲线,用颜色变化表示污染程度。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

100

主题

295

帖子

6

粉丝