Automated Blind Project - advice and guidance needed please

StAndrewsBB

New Member
Dear Members

I am new to Picaxe and have embarked on a project to help develop my understanding and knowledge. I am using the trainer T4 to model the automation of a roller blind for the home. I have chosen to use a stepper motor to drive the system. I have also chosen to determine the limits of movement via 2 slotted opto switches and small holes in the blind material one at either extreme of movement.

I am able to model a 2 state system in which the stepper motor drives in one direction when the light level measured by LDR is low until a switch is activated and in the reverse direction when the light level is high until a second switch is activated.

However, I would like to extend this system to 3 states, the intermediate state representing a middle light level. I've approached this by splitting the light levels and driving the motor one way or the other depending on the middle light level and stopping when both switches are activated (which I would achieve by having two small holes in the blind in the centre position).

My code works fine for the 2 state system but doesn't work for the 3 state system. I haven't currently got sufficient Picaxe knowledge to know what is wrong and whether I am fundamentally approaching this from the wrong angle.

Here is my code. I would appreciate any guidance anyone can give - with many thanks!

(Please accept my apologies if this is a trivial exercise but I guess we all have to start somewhere!)
Code:
dirsB=%11111111
	
main:
	readadc C.0,b0
	if b0>10 and b0<80 then OPEN ;dark and blind fully open
	if b0>220 and b0<250 then CLOSE ;bright sunshine blind fully closed
	if b0>100 and b0<110 then CLOSEMID ; normal light and blind closes to mid way
	if b0>190 and b0<200 then OPENMID ; normal light and blind opens to mid way
	goto main

OPEN:
	do until pinC.7 = 1
	pinsB=%00001100
	pause 10
	pinsB=%00000101
	pause 10
	pinsB=%00000011
	pause 10
	pinsB=%00001010 
	pause 10
	loop
	goto main
CLOSE:
	do until pinC.6 = 1
	pinsB=%00001010
	pause 10
	pinsB=%00000011
	pause 10
	pinsB=%00000101
	pause 10
	pinsB=%00001100 
	pause 10
	loop
	goto main
	
CLOSEMID:
	do until pinC.6 = 1 and pinC.7 = 1
	pinsB=%00001010
	pause 10
	pinsB=%00000011
	pause 10
	pinsB=%00000101
	pause 10
	pinsB=%00001100 
	pause 10
	loop
	goto main

OPENMID:
	do until pinC.7 = 1 and pinC.6 = 1
	pinsB=%00001100
	pause 10
	pinsB=%00000101
	pause 10
	pinsB=%00000011
	pause 10
	pinsB=%00001010 
	pause 10
	loop
	goto main
 
Last edited by a moderator:

hippy

Technical Support
Staff member
Welcome to the PICAXE forum.

It may help to explain what your project does and what it doesn't do, how it doesn't behave as would be expected.

One issue could be in using the same pins to determine when the blinds are in the mid position as well as in the open or closed position. An attempt to move from the mid positions will have pinC.7=1 and pinC.6=1 so both the open and close routines will determine the blinds are in the position desired as soon as they are entered, will not actually make any movement.
 

premelec

Senior Member
@StAndrewsBB - there was a long thread on automatic blinds some years ago on this forum - use advanced search function and you may find it is of interest to you - good luck!
 

StAndrewsBB

New Member
Dear hippy

Thanks very much for your attention to my issue. Of course you are right and your comment has enabled me to solve the problem by approaching it slightly differently. I'll no doubt have a few issues along the way as I learn the Picaxe system but hopefully I'll improve!

Thanks again.
 

hippy

Technical Support
Staff member
Glad to hear you have resolved the problem.

I am guessing you have two 'mid' routines so you can step down from open and up from closed. One thing worth checking is what happens when the blind is closed, and then the light level changes to that which would cause the CloseMid routine to execute rather than OpenMid. The blind will be down and then you might start stepping down to reach the middle which will try to push the blinds past the end point. There could be a similar problem if the blind is open and you then call OpenMid. Your code rewrite might have also solved that problem but it is worth checking.

One solution to that problem is 'finite state machine' coding though it can also be done by using variables as flags. If you do need help or advice with that or anything else do please ask.
 
Top