How to soft start motor if window opens and how to soft close window ? Sketch is attached and working.
windows_3pcs.ino (5.86 KB)
How to soft start motor if window opens and how to soft close window ? Sketch is attached and working.
windows_3pcs.ino (5.86 KB)
What type of motor ?
How is it controlled ?
How is it powered ?
Please post your code here as advised in read this before posting a programming question
Sry. Motor is dc. Car windshield motor and driver is L298N.
Soft start should be as simple as slowly ramping up the PWM duty cycle.
Soft stop is probably a lot more difficult because the system needs to know {a} that it is approaching the stop position and {b} that it has actually reached the stop position.
Maybe you could use a pair of micro-switches. The first one signals "start slowing down" and the second one signals "we have arrived". Keep in mind that it would be easy to reduce the motor power to the point where the motor stalls before it reaches the final stop position and might need an extra burst of power for the final few millimetres.
Maybe you could have a speed sensor and the Arduino could use a PID system to hold the system at the required speed. Then the deceleration code should alter the required speed rather than manipulating the PWM directly.
...R
Hi,
Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Thanks......Tom...
Circuit is in sketch.I do not have end switches.All process open and close windows is time. Today i do not measure really opening time. In sketch this time is delay(6000); for full open window. From this 6 sec i can reserve for soft start 2 sec and 4 sec for full opening. This time i want to test in greehouse. My windows at the moment opening manually.
From this 6 sec i can reserve for soft start 2 sec and 4 sec for full opening.
There is a "gotcha" in your plan. Soft start/stop will mean that it takes longer to open and close the window and the opening and closing times are likely to be different, but you could tune the times based on experiments.
If the windows are pulled open by a wire from the central post of your greenhouse, as it appears to be in your photo, then at least you will have quite a tolerance in motor run times without stalling the motor.
What sort of power will the motors be running on ?
I understand that the method of opening and closing the windows may just be the way you want to do it but why not make the entire movement slow? You may also want to keep in mind that the output of a wiper motor has alot of torque. So you may want to include some kind of buffer in your drive system to prevent breakage if the drive goes too far. - Scotty
insippo:
Circuit is in sketch.I do not have end switches.
IMHO something will eventually break if you don't use limit switches. And it probably won't take that long before that happens.
Limit switches go some way to provide some of the intelligence that your brain provides when you do it manually.
If you remain unconvinced try opening and closing the windows manually without
...R
Soft start for open window. I use this for close too .
//Window 1
if (tempC >= 16 && X == 0) { // if temp => +16 1. window opens
Serial.println("Temp is +16C. Open window 1.");
digitalWrite(win1MotorA, HIGH); // motor direction if need other direction change
digitalWrite(win1MotorB, LOW); // motor direction if need other direction change
analogWrite(win1Speed, 155);
delay(100);
analogWrite(win1Speed, 165);
delay(100);
analogWrite(win1Speed, 175);
delay(100);
analogWrite(win1Speed, 185);
delay(100);
analogWrite(win1Speed, 195);
delay(100);
analogWrite(win1Speed, 205);
delay(100);
analogWrite(win1Speed, 215);
delay(00);
analogWrite(win1Speed, 225);
delay(100);
analogWrite(win1Speed, 235);
delay(100);
analogWrite(win1Speed, 245);
delay(100);
analogWrite(win1Speed, 255); // motor full speed
delay(6000); // time for motor full speed
analogWrite(win1Speed, 200); // slower speed for opens window
delay(3000); // time for slow open
analogWrite(win1Speed, 0); // motor stop
digitalWrite(win1MotorA, LOW); // motor 1 pin A LOW, full stop
Serial.println("Window 1 is open.");
X = 1;
analogWrite(win1Speed, 155);
delay(100);
analogWrite(win1Speed, 165);
delay(100);
analogWrite(win1Speed, 175);
delay(100);
analogWrite(win1Speed, 185);
delay(100);
analogWrite(win1Speed, 195);
delay(100);
analogWrite(win1Speed, 205);
delay(100);
analogWrite(win1Speed, 215);
delay(00);
analogWrite(win1Speed, 225);
delay(100);
analogWrite(win1Speed, 235);
delay(100);
analogWrite(win1Speed, 245);
delay(100);
Could more neatly be done with a for loop
for (int speed = 155; speed <= 245; speed += 10)
{
analogWrite(win1Speed, speed);
delay(100);
}
or more smoothly
for (int speed = 155; speed <= 245; speed++)
{
analogWrite(win1Speed, speed);
delay(10);
}
yesss. Thank you.
The L298N probably won't be able to handle the current required by that motor. I would recommend one of these drivers.
This motor A is ~1,5. Started at 2,5A. If soft start i do not know but ja can measure after work. Motor open window ~25 sec. On the table this driver did not become hot. First time i think use this l298n in bridged mode. On the table in home works well I try today and make video too.
These Pololu drivers price is too high. maybe Aliexpress sell these too.
Hi,
scottyjr:
I understand that the method of opening and closing the windows may just be the way you want to do it but why not make the entire movement slow? You may also want to keep in mind that the output of a wiper motor has alot of torque. So you may want to include some kind of buffer in your drive system to prevent breakage if the drive goes too far. - Scotty
Robin2:
IMHO something will eventually break if you don't use limit switches. And it probably won't take that long before that happens.Limit switches go some way to provide some of the intelligence that your brain provides when you do it manually.
If you remain unconvinced try opening and closing the windows manually without
- seeing at what is happening
- hearing what is happening
- feeling what is happening
...R
I agree about limit switches.
You have the control power with the ,what model arduino?, controller to do so much.
From the picture you are driving the motor as a winch from the centre pole out the top, am I correct?
Thanks.. Tom...
The main thing about ramping up the velocity is (assuming PWM has a linear relationship to window speed) the total distance travelled by a motor during a linear speed ramp is equal to half the distance it would have travelled if it were going at full speed the whole time (this just follows from calculus).
So if your window opens in 25 sec, and you want the soft start and end to be 2 seconds long, then you need 2 sec start, 23 sec full speed, 2 sec slow down.
the code is
// ramp up
starttime = millis();
currentspeed = 0;
targetspeed;
while(millis()-starttime < 2000) {
targetspeed = 255 * (millis()-starttime)/2000.0;
if(currentspeed != targetspeed) {
analogWrite(A0, targetspeed);
currentspeed = targetspeed;
}
}
// full speed
analogWrite(A0, 255);
currentspeed = 255;
starttime = millis();
while(millis()-starttime < 23000L) {
; // do nothing
}
// ramp down
starttime = millis();
while(millis()-starttime < 2000L) {
targetspeed = 255 - (255 * (millis()-starttime)/2000.0);
if(currentspeed != targetspeed) {
analogWrite(A0, targetspeed);
currentspeed = targetspeed;
}
}
// stop
analogWrite(A0, 0);
Of course, of you need this to be cooperative then it needs some tweaking
If you want the motion to have zero jerk, then the ramp needs to be a cubic rather than linear. The cubic is defined by start time (0), end time (2000 in our example), start value (0), end value(255), and a start and end acceleration of zero.
That is, the acelleration is proportional to t * (end time - t), and so the PWM value is proportional to -1/3 t^3 + 1/2t^2*end_time . The proportion is adjusted so that the pwm value at the end of the ramp is 255. It might be easier to treat the ramp time as always being 1, of course, and the target velocity as being 1.
This gives us simply PWM = 6 ( -1/3 t^3 + 1/2 t^2), or t * t * (3 - 2*t) * 255. By symmetry, the total distance travelled over this time will again be half the distance that it would have travelled going at full speed.
So:
while(millis()-starttime < 2000) {
double t = (millis()-starttime)/2000.0;
targetspeed = 255 * t * t * (3 - 2*t);
if(currentspeed != targetspeed) {
analogWrite(A0, targetspeed);
currentspeed = targetspeed;
}
}
I should try this out to see if it works
I feel you all are complicating what should be a rather simple solution.
Looks like you have 3 vents to open and close. I would find three identical air cylinders on Ebay that give you the stroke length needed to open and close the vents. If you can use the vent weight or spring loading to close the vents, you can use single action cylinders.
Then get a small air compressor and run plastic tubing to the air cylinders. When the compressor starts, the cylinders will extend slowly and stay extended. The compressor will stop when it's tank pressure reaches the limit switch setting.
To lower the vents, turn off the compressor and use a solenoid valve to release all the air pressure.
The Arduino can control the air compressor using a relay. and it can control the air release with a solenoid valve.
The mechanical installation is up to you!
Paul
I have only one 80W solar panel for greenhouse electricity and 60ah battery. Air valve with compressor i cant use.
This soft start not working with l298n. I use this bridged mode. All is ok but one question. How to set up limit switch for close ? This is problem.Installation is not problem but code. I use Arduino Nano. Arduino close window and be busy control limit switch in pin 13, sample pin. For open i can use time but for close cant. 1 time for full close needed maybe 1 sec, other 2 sec.
For close needed program interrupt but how ? I do not know.
This is my code. in morning window opened good.
#include <OneWire.h>
#include <DallasTemperature.h>
#define win1MotorA 4
#define win1MotorB 5
#define win1Speed 6
#define win2MotorA 7
#define win2MotorB 8
#define win2Speed 9
#define win3Speed 10
#define win3MotorA 11
#define win3MotorB 12
// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// Arduino 1-Wire Address Finder
DeviceAddress thermometer = { 0x28, 0xC8, 0xDC, 0x51, 0x07, 0x00, 0x00, 0x72 };
int X = 0;
void setup(void)
{
pinMode (win1MotorA, OUTPUT);
pinMode (win1MotorB, OUTPUT);
pinMode (win2MotorA, OUTPUT);
pinMode (win2MotorB, OUTPUT);
pinMode (win1Speed, OUTPUT);
pinMode (win2Speed, OUTPUT);
digitalWrite (win1MotorA, LOW);
digitalWrite (win1MotorB, LOW);
digitalWrite (win2MotorA, LOW);
digitalWrite (win2MotorB, LOW);
digitalWrite (win1Speed, LOW);
digitalWrite (win2Speed, LOW);
// start serial port
Serial.begin(9600);
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(thermometer, 10);
}
void printlnTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
Serial.println("Error getting temperature");
} else {
Serial.println("C: ");
Serial.println(tempC);
}
//Window 1
if (tempC >= 18 && X == 0) { // if temp => +18C window 1 opens
Serial.println("Temp is +22C. Open window 1.");
digitalWrite(win1MotorA, HIGH); // motor direction if need other direction change
digitalWrite(win1MotorB, LOW); // motor direction if need other direction change
digitalWrite(win2MotorA, HIGH); // motor direction if need other direction change
digitalWrite(win2MotorB, LOW); // motor direction if need other direction change
analogWrite(win1Speed, 255); // motor full speed
analogWrite(win2Speed, 255);
delay(25000); // time for open window
analogWrite(win1Speed, 200); // slower speed for open window
analogWrite(win2Speed, 200);
delay(4000); // time for slow open
analogWrite(win1Speed, 0); // motor stop
analogWrite(win2Speed, 0);
digitalWrite(win1MotorA, LOW); // motor 1 pin A LOW, full stop
digitalWrite(win2MotorA, LOW);
Serial.println("Window 1 is open.");
X = 1;
}
if (tempC <= 16 && X == 1) { // if temp <= 16 window 1 closes
Serial.println("Temp is +21C. Close window 1.");
X = 0;
digitalWrite(win1MotorA, LOW);
digitalWrite(win1MotorB, HIGH);
digitalWrite(win2MotorA, LOW);
digitalWrite(win2MotorB, HIGH);
analogWrite(win1Speed, 255); // motor full speed
analogWrite(win2Speed, 255);
delay(13000); // time for motor open window
analogWrite(win1Speed, 150); // slow speed for close
analogWrite(win2Speed, 150);
delay(3000); // time for slow close
analogWrite(win1Speed, 0); // motor stop
analogWrite(win2Speed, 0);
digitalWrite(win1MotorB, LOW); // motor 1 pin B LOW, full stop
digitalWrite(win2MotorB, LOW);
Serial.println("Window 1 is closed.");
}
}
void loop(void)
{
Serial.print("Getting temperatures...\n\r");
sensors.requestTemperatures();
Serial.print("Temperature is: ");
printlnTemperature(thermometer);
Serial.print("\n\r");
delay(1000);
}