Advices required for Soap dispenser / sanitizer code


+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    571

    Default Advices required for Soap dispenser / sanitizer code

    Hi ! Both of my dispensers stopped working. So I thought of making a module with PIC. However, I encounter problems when implementing the function @Sleep in the program. I need your advice .... Thansk !
    Code:
    @ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON 
    
    DEFINE OSCCAL_1K 1
    DEFINE OSC  4
    
    CMCON    = 7
    TRISIO   = %00000001
    INTCON   = 0 
    IOC      = 0
    GPIO     = 0
    ANSEL    = %00110001
    
    GIE  var intcon.7   ' global interrupt enable 1=on ; 0=off
    GPIE var intcon.3   ' port change interrupt enable 1=0n ; 0=off
    GPIF var intcon.0   ' port change interrupt flag bit
    
    
    DataW 		var word
    last_b_level 	var byte          	
    b_level 	var byte
    b_cnt 		var byte
    b_act 		var byte
    
    GIE=0
    GPIE=1
    IOC.0=1   ' int-on-change for GPIO.0 enabled
    
    
    Clear
    
    GPIO.2 = 0
    ADCON0 = %10000001
    Pauseus 100            			' Wait for channel to setup
    
    ;============================================================================
    
    Main: 
    
        ADCON0.1 = 1			' Start conversion
    @ SLEEP
    	While ADCON0.1=1:Wend		' Wait for conversion
    	DataW.HighByte=ADRESH		' Read variable from ADC and save
    	DataW.LowByte=ADRESL
    
    if DataW < 600 then  
    b_level=1
        if b_level=last_b_level then                 
            b_cnt=b_cnt+1
            pauseus 50
               if b_cnt > 10 then b_act = 1      'TO AVOID FALSE READING
        endif
    
        last_b_level=b_level                              
    endif
    
    if b_act = 1 then gosub comanda
    goto main
    
    ;============================================================================
    
    comanda:
              
    GPIO.2 = 1
    PAUSE 4000
    GPIO.2 = 0
    
    b_act=0
    last_b_level=0
    b_cnt=0 
    GPIF=0  'Clear or change interrupt flag
    Return
    
    END
    It's the first test ... simulating IR detector by resistor and reading the ADC.
    Name:  dispenser_schematic.jpg
Views: 146
Size:  83.0 KB

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,976

    Default Re: Advices required for Soap dispenser / sanitizer code

    I think you have it a bit mixed up!

    First, a voltage divider like that will not trigger IOC reliable or at all.

    Second, in case of an interrupt what should the program do? You do not have an ISR to jump to.

    Third, read the manual regarding the On Interrupt command to make a ISR subroutine.

    The main idea is to make a digital input with preferably internal pull-up enabled. Then, an external trigger on that input will start PIC and jump to ISR.

    In the ISR, you can recheck the input to make sure the trigger was real and then set the output for 4 sec. Then clear Interrupt flag, reset the output and go to sleep again.

    Ioannis

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    1,733

    Default Re: Advices required for Soap dispenser / sanitizer code

    i assume you intend the button to cause an ioc interrupt to occur when pressed.
    it wont because any i/p pin set as analog will always read as low so a pin change event
    will never occur
    why would use adc to react to a button anyway ?
    This is more entertaining than Free to Air TV

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,976

    Default Re: Advices required for Soap dispenser / sanitizer code

    I can only guess that it is not a clear 0-5 volt state.

    And that is why he simulates the trigger pulse with the two resistors. All the way wrong approach...

    Ioannis

  5. #5
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    571

    Default Re: Advices required for Soap dispenser / sanitizer code

    Thank you for the answers. The 2 resistors and the button simulate a photodiode, whose resistance increases when it is no longer illuminated by the IR emitting diode (communication is interrupted by the hand interposed on the route). There is NO button !

  6. #6

    Default Re: Advices required for Soap dispenser / sanitizer code

    At work, we make a product that detects hand motion to light up a string of LED's. You can use a FET to drive the soap pump motor. We use the ADC in a 12F675 to detect fluctuations from a 5528 LDR. ADC has 47K pull down resistor, other side of LDR to B+.

  7. #7
    Join Date
    May 2013
    Location
    australia
    Posts
    1,733

    Default Re: Advices required for Soap dispenser / sanitizer code

    IF you use the comparator its as simple as this.it won't re-arm itself until hand is removed

    Name:  ldr_sw.png
Views: 105
Size:  16.4 KB


    Code:
    #config
       __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _BODEN_ON 
    #endconfig
    DEFINE OSCCAL_1K 1
    DEFINE OSC  4
    
    CMCON    = %00001110
    TRISIO   = %111011
    
    vrcon=$88    ;about vcc on 2
     ANSEL=1
    tmp var byte
    Main: 
    intcon=$40
    pir1=0
    PIE1=8
    asm   
     SLEEP
     nop
    endasm 
    if  CMCON.6 then
    gpio.2=1
    pause 1000
    gpio.2=0
    endif
    goto main
    END
    Last edited by richard; - 12th September 2020 at 12:25.
    This is more entertaining than Free to Air TV

  8. #8
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    571

    Default Re: Advices required for Soap dispenser / sanitizer code

    Thank you very much ! I think this is what I need ! I will tested and post the results. Regards !

Similar Threads

  1. Thermistor based temperature reading short code required
    By asifiqbal in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 12th November 2014, 09:18
  2. Cash dispenser
    By tigerflow in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 2nd June 2009, 10:40
  3. Help Required for Newbie
    By Moz in forum General
    Replies: 7
    Last Post: - 13th August 2004, 00:05
  4. Help Required
    By lester in forum Forum Requests
    Replies: 2
    Last Post: - 19th July 2003, 22:16

Posting Permissions

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