Main Menu

Contact Andrew Quinn

jaquinn@ihug.co.nz http://twitter.com/jaquinn
PICAXE 08M Motor Running Indicator PDF Print E-mail
Written by Administrator   
Wednesday, 18 April 2007 17:59
Living in the country means having certain technology/equipment/stuff that normal city living people don't have.

One of these things is a bore that supplies water for our stock.  This has a 100m (approx) pipe down into the ground and pulls the water up into a header tank.  We had a problem a few months back where the bore died due to old age/splits in the pipe and wear in the valve at the bottom of the pipe.  In reality is was probably performing worse and worse over time until it eventually got to the point where it couldn't fill the header as fast as we were draining it.

The bore is now fixed but this got me thinking.... if I had a way of tracking the pumping time each day it would show a trend and indicate in advance if there were impending problems.

While it is possible to use a hall effect sensor and monitor the current flow to the pump this was getting a lot closer to the 240v power than I wanted to get.

Instead I built a small unit based on a PICAXE 08M and an IR Diode/Sensor that monitors if the motor is running by watching for interuptions from the pump arm.

The output of the unit is a logic level signal that indicates the pump is "running" or "not running".  This signal is used by an AVR/Packet Wacker based board which collects data and makes it available for loading into a MYSQL database for later trend analysis.

The code for the PICAXE 08M is as follows:

' Bore Pump Running Monitor
'
' Checks for regular breaks of the IR bream and provides a running/not running status
' via the status output pin
'
' Pin Assignments:
' 0 = (Out) Serial
' 1 = (Out) Pump running (1=running, 0 = not running)
' 2 = (Out) PWM
' 3 = (In) IR Status
' 4 = (Out) Mode Indicator (1 = setup, 0 = monitoring)

' Constants

symbol C_RUNNING = 1
symbol C_NOTRUNNING = 0
symbol C_AIMTIME = 30
symbol C_WARNTIME = 30
symbol C_SLEEPTIME = 30
symbol P_MODE = 4
symbol P_IR = 3
symbol P_STATUS = 1

' Variable Usage

symbol RUNTRIGGERCOUNT = b1

#picaxe 08m

main:
        ' Configure PWM Pin 2 for 40000hz PWM Output

        pwmout 2 , 24, 50

        ' Initial state is not running until we decide if it is

        low P_STATUS
        RUNTRIGGERCOUNT = 0

        ' First wait until the IR signal is received so we know the installation
        ' is ok and future interupts for loss of signal is caused by the pump arm
        ' breaking the beam

        low P_MODE
startloop:
        if pin3 = 0 then startloop2
       
        ' IR Signal so Mode indicator on and count trigger until the limit is reached

        high P_MODE
        RUNTRIGGERCOUNT = RUNTRIGGERCOUNT + 1
        pause 150
        if RUNTRIGGERCOUNT <= C_AIMTIME then startloop
        goto startloop3

startloop2:
        ' No IR Signal so Mode indicator off and reset trigger count
                       
        low P_MODE
        RUNTRIGGERCOUNT = 0
        goto startloop
       
startloop3:
        ' Tell the installer that the aim should be ok and we are waiting to check
        ' it stays valid for 5 seconds before initializing interupts
   
        RUNTRIGGERCOUNT = 0

startloop4:
        pause 100
        toggle P_MODE
       
        ' If IR lost then restart sequence

        if pin3 = 0 then startloop2

        ' Keep checking while we tell the user

        RUNTRIGGERCOUNT = RUNTRIGGERCOUNT + 1
        if RUNTRIGGERCOUNT < C_WARNTIME then startloop4

mainloop:
        setint %00000000, %00001000
        sleep C_SLEEPTIME
        if RUNTRIGGERCOUNT > 0 then mainloop2
        low P_STATUS
        goto mainloop

mainloop2:
        high P_STATUS
        RUNTRIGGERCOUNT = 0
        goto mainloop

interrupt:
        RUNTRIGGERCOUNT = RUNTRIGGERCOUNT + 1
        setint %00000000, %00001000
        return

The PICAXE code does three things:
  1. It uses PWM to generate the 40000hz signal to modulate an IR LED.
  2. It monitors the output from the IR sensor to determine if the beam is aligned/broken.
  3. It uses an LED to provides an aiming function for initial installation.
All with less than 80 bytes of code... pretty cool eh!