I have to automate window shade with two stepper motors. One on the top and other on the bottom. The speeds of the motors depends on the radius of the roll the steppers are attached to.
The window shade has two different shades of different thickness.
#include <AccelStepper.h>
int stepd=0,stepu=0;
int x=0,y=0,z=0; //pointers to know track the movement
float t1=0.33,t2=0.45; //thickness of the blinds
int motordDirPin = 9;
int motordStepPin = 10;
AccelStepper stepperd(1, motordStepPin, motordDirPin);
int motoruDirPin = 3;
int motoruStepPin = 5;
AccelStepper stepperu(1, motoruStepPin, motoruDirPin);
int motorSpeed = 8000, layerd,layeru;
float speedu=2000,speedd=1000,rratio,radiusd=23,radiusu=12; //actual radii are 23mm and 12mm
int rounds,current=0,flag1=1,inp;
void radcal0();
void radcal1();
void setup()
{
Serial.begin(9600);
stepperd.setMaxSpeed(motorSpeed);
stepperu.setMaxSpeed(motorSpeed);
}
void loop()
{
int n=18;
inp=Serial.read();
if(inp=='0')
{
stepd=(int)17825/radiusd; // explained below
stepu=(int)17825/radiusu;
rratio=(float)stepu/stepd;
speedu= (speedd*rratio);
rounds=0;
stepperd.move(-stepd);
stepperu.move(-stepu);
radcal0();
}
else if(inp=='1')
{
stepd=(int)17825/radiusd;
stepu=(int)17825/radiusu;
flag1=0;
rratio=(float)stepu/stepd;
speedu= (speedd*rratio);
rounds=1;
stepperd.move(stepd);
stepperu.move(stepu);
radcal1();
}
stepperd.setSpeed(speedd);
stepperu.setSpeed(speedu);
layeru=stepu/800; //since 800 steps are completing a revolution
layerd=stepd/800;
stepperu.runSpeedToPosition();
stepperd.runSpeedToPosition();
}
void radcal0(){
if(x<10){
radiusd+=(layerd*t1); // since the radius of the rolls will chage when one layer of cloth is rolled onto it
radiusu-=(layeru*t2);
x++;
}
}
void radcal1()
{
if(x<10 && x>0){
radiusu+=(layeru*t2);
radiusd-=(layerd*t1);
x--;
}
}
my calculations are:
Height of the window =1.4 m
I want to release 10%of the total length of the cloth
10% of 1.4 = 140mm
800steps=1 revolution=2pir circumference
x steps = 140mm
thus, x = 800140/(2pi*radius)
x = 17825/radius
When m implementing this, hardly 1% of the cloth is shifting.
Can someone help me out? I hope m clear. I know I explained it terribly.