Pointy Windmill-o-meter (incredibly inaccurate voltmeter!)

Hi all,

I've been hanging around this forum for a while, and never felt that I had much to contribute. I hope I do now!!

The following project was designed for "Windmill Workshops" to meet STEM, 'process & control' and energy/environment/renewable topics in schools.

The PICAXE simply measures the voltage that the motor generates, and adjusts the servo accordingly.

All the best,
Craig.

[video=vimeo;116488405]https://vimeo.com/116488405[/video]

Picaxe Windmillometer_schem.jpg

Code:
'============ ServoPointer.bas ============

'This programme is designed to read a small voltage via the ADC
'and operate a servo to act as a pointer.
'Thus creating an incredibly large, and inaccurate voltmeter!
'Code written by Craig Marston, from ideas shared on www.picaxeforum.co.uk
'inspired by R.J. Hackett and his "Evil Genius Guide to Picaxe" book


'=== Constants ===            DON'T BUGGER ABOUT WITH THESE SETTINGS!
symbol ADCval = b0            ;the analogue value read from the windmill
symbol pointy = b1            ;the value sent to the servo
symbol b1L = b2                ;declaring symbols for the variables
symbol b1H = b3                ;to make them easier to understand
symbol ADCrange = b4            ;For 8-bit this will be 255, which is set later!
symbol Rout = b5                ;Output range of the servo as set later  

' NOTE: Anything that has "CONFIGURE" in the comments is for tweeking!

'=== Initialisation ===
servo C.2, 155                  'CONFIGURE - start servo, pin 2, central-ish position. Required prior to servopos command
fvrsetup FVR1024                'set to 1.024  V
adcconfig %011                'set FVR (Fixed Voltage Reference) as the ADC +Vref, 0V for -Vref

'=== Variables ===
b1L = 80                    'CONFIGURE - the servo's lowest value, tweek for each individual device
b1H = 235                    'CONFIGURE - the servo's highest value, tweek for each individual device
ADCrange = 255                'input range of the ADC which is 2^8 (i.e. 256 steps)
Rout = b1H - b1L                'output range EQUATION determined by b1H & b1L
 
'=== Directives ===
#picaxe 08M2                 'specifies the processor used
#terminal 4800                'open terminal window to see what's occurring on the computer


'=== The Main Programme ===
main:
    readadc C.1, ADCval        'read the voltage (ADC value 0-255) into variable b0
    ADCval = ADCval * 1         'CONFIGURE - increase sensitivity by multiplying the ADC value if required
    ADCval = 255 - ADCval        'inverses the ADC reading otherwise the servo rotates the wrong way!
    pause 50                'calm down a bit - slight pause between readings
    pointy = Rout * ADCval / ADCrange + b1L    'EQUATION (affine transform) to convert the full 8-bit range of the ADC (256) to the smaller servo range (around 150 or so)
    if ADCval <> b6 then        'update the position only if there's a change between the two variables
    gosub MoveThen            'go to the subroutine "pointer" if the above statement is true
    endif                    'end the "if" procedure
    b6 = ADCval                'update variable b6 from the ADC value currently in variable b0  
    sertxd (#ADCval,cr,lf)         'send ADCval to Terminal Window
    goto main                'start the procedure all over again!


MoveThen:
    servopos C.2, pointy        'servo position as determined by the value in variable b1
    return                'return to the main procedure
 
Last edited by a moderator:
Top