SHARP GP2Y10 optical dust sensor


Closed Thread
Results 1 to 1 of 1
  1. #1

    Default SHARP GP2Y10 optical dust sensor

    Hello,

    I wanted to create a simple air filter/purifier for my workshop from box fan and 3M square filters.
    For that reason I wanted to measure the dust particles in air. I found some infos about that SHARP
    optical dust sensor for Arduino, but unfortunately nothing for PIC MCUs in Picbasic.
    Then I writed the code in PBP. The code is simple, use PIC16F690, 8x2 LCD and SHARP optical dust sensor.
    Here is the code, sensor wiring diagram and characteristics:


    Code:
    ;****************************************************************
    ;*  Name    : GP2Y1010AU0F SHARP dust sensor                    *
    ;*  Author  : Louis                                             *
    ;*  Notice  : Copyright (c) 2018 Louis                          *
    ;*          : All Rights Reserved                               *
    ;*  Date    : 7. 1. 2018                                        *
    ;*  Version : v1.0                                              *
    ;*  Notes   : PIC16F690                                         *
    ;****************************************************************
    
    #CONFIG
    cfg = _INTRC_OSC_NOCLKOUT
    cfg&= _WDT_ON
    cfg&= _PWRTE_OFF
    cfg&= _MCLRE_OFF
    cfg&= _CP_OFF
    cfg&= _CPD_OFF
    cfg&= _BOD_ON
    cfg&= _IESO_ON
    cfg&= _FCMEN_ON
      __CONFIG cfg
    #ENDCONFIG
    
    DEFINE OSC 4      ; Use a 4 MHZ internal clock 
    ADCON1 = 0
    ANSEL = %01000000 ; Set AN6 analog rest digital
    TRISA = %000000   ; Set RA0 - RA5 output
    TRISB = %0000     ; Set RRB4 - RB7 output
    TRISC = %00000100 ; Set RC2 input, rest output
    CM1CON0 = 0       ; Disable comparator 1
    CM2CON0 = 0       ; Disable comparator 2
    OPTION_REG.7=1    ; Disable weak pull ups
    
    DEFINE ADC_BITS 8      ; Set number of bits in result
    DEFINE ADC_CLOCK 3     ; Set clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 50 ; Set sampling time in microseconds
    
    conv1 con 19  ; 5000/256 = 19,53 decimal part
    conv2 con 35  ; fractional part
    
    ;----[ Change these to match your LCD ]---------------------------------------
     
    LCD_DB4    VAR PORTA.0
    LCD_DB5    VAR PORTA.1
    LCD_DB6    VAR PORTA.2
    LCD_DB7    VAR PORTA.4 
    LCD_RS     VAR PORTA.5 
    LCD_E      VAR PORTC.3
    LCD_Lines  CON 2 ; # of Lines on LCD, 1 or 2 (Note: use 2 for 4 lines) 
    LCD_DATAUS CON 50 ; Data delay time in us 
    LCD_COMMANDUS CON 2000  ; Command delay time in us 
    INCLUDE "LCD_AnyPin.pbp" ; Include MUST be AFTER LCD Pin assignments
    
    out var portb.6   ; Sharp LED enable pin
    dens var word     ; Final particle density in ug/m3
    adval var word    ; ADC raw data
    volts1 var word   ; First part of result in mV
    volts2 var word   ; Second part of result in mV
    
    main:
    high out          ; power on the sensor LED
    pauseus 280       ; sampling time 280us
    adcin 6,adval     ; read ADC value on AN6 pin
    pauseus 40        ; delta time
    low out           ; power off the sensor LED
    pauseus 9680      ; sleep time
    
    ;--------- ADC value to mV conversion ------------
    
    volts1 = adval * conv1  ; multiply by 19
    volts2 = adval * conv2  ; multiply by 35
    volts2 = volts2 /100
    volts1 = (volts1 + volts2)/10  ; result in mV
    if volts1<59 then volts1 = 59  ; sensor linear char. begin from 0.6V
    
    ; --------- calculate particles in ug/m3 -----------
    
    ; 0.60V = 0ug/m3 particles start of sensor linearity MIN value 
    ; 1.20V = 100ug/m3 particles 
    ; 1.77V = 200ug/m3 particles 
    ; 2.35V = 300ug/m3 particles 
    ; 2.95V = 400ug/m3 particles
    ; 3.52V = 500ug/m3 particles
    ; 3.70V = 530ug/m3 particles end of sensor linearity MAX value 
    
    let dens = ((17 * volts1) -1000)/10
    
    ;--------- display values on 8x2 LCD ----------
    
    Lcdout $fe, 1                  ; clear display
    lcdout $FE,$80,"Particle"      ; first line
    lcdout $FE,$C0, dec dens,%11100100,"g/m3"  ; second line
    if dens > 529 then   ; if the value reaches max then display message 
    lcdout $FE,$80,"MAX Over" 
    endif
    
    pause 500   ; pause 0.5 sec.
    goto main   ; jump to main
    end
    Attached Images Attached Images     

Similar Threads

  1. Sharp ir distance sensor
    By hasnannordin in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th October 2009, 22:48
  2. Sharp GP2D02
    By Alby in forum Off Topic
    Replies: 5
    Last Post: - 8th March 2009, 09:09
  3. Using a optical coder
    By debutpic in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 16th October 2007, 05:57
  4. Using the optical sensor from a ball mouse
    By lsteele in forum General
    Replies: 5
    Last Post: - 5th September 2007, 17:45
  5. GP2D15 sharp
    By chip_1 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th May 2005, 08:45

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts