Following suggestions I've ordered a module from e-bay based on an L298N controller, which should work as under testing the 540 motor was drawing 0.7A and these things are rated at 2A.
I'm now working on the light detection side of the circuit. Basically the idea is to automatically open a door at dawn (wife now keeps chickens !). So when the light level reaches or exceeds a threshold, the motor runs, opening the door until the door hits a micro switch which then changes a pin status which then turns off the motor.
I've purchased a 16k-33K LDR from Maplin ( http://www.maplin.co.uk/p/16k-33k-oh...resistor-n57ay ) and connected that from the 5v line to GPIO.0 and covering the LDR makes the associated LED on my development board go out, and increase in brightness due to ambient light or when a bright torch is shon on the LDR. So the resistance is varying based on the light level, so far so good. Now the issue I'm having is that having set the ACD to 8 bits this should give me a 0 - 254 range of values... but in testing to get the motor to run at various values, these are not what I would expect.
Here's the test code:
If I put in <1 for the argument, the motor runs even with the LDR covered. If I put in >1 the motor won't run unless I shine the torch directly on the LDR. I'm sitting here in ambient light with the sun shining in the window so the motor should be running.Code:ASM __CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF endasm ' Hardware configuration ' ====================== TRISIO = %001111 ADCON0 = %10000001 ANSEL = %00110011 DEFINE ADC_BITS 8 DEFINE ADC_SAMPLEUS 50 CMCON0=7 Motor1 var GPIO.4 Motor2 var GPIO.5 ADChannel0 var word GPIO = 0 ' clear all output Pause 50 ' internal oscillator settle time main: low Motor1 low Motor2 adcin 0,adchannel0 ' Read AN0 If adchannel0 >2 then high Motor1 Low Motor2 pause 5000 low Motor1 low Motor2 endif goto main
Any ideas as to what I'm doing wrong ?
Bookmarks