The motor speed is reduced ( trough gears ) the gate being not heavy at all. Power off and tryed with 3 kilo no movement.
/* This Arduino Schetch wil open (in the morning) and close ( in the evening ) the gate from a chicken barn.
It makes use of an LDR sensor to measure the ligth intensity
The sketch is to control a stepper motor with ULN2003 driver board
controlled by Arduino UNO with use of the AccelStepper library for: acceleration and deceleration.
The driver board is from Phoenix Contact with the ULN 2003 driver chip
Modified by Ben Bakker 25-november 2021 */
/* This Arduino Schetch wil open (in the morning) and close ( in the evening ) the gate from a chicken barn.
It makes use of an LDR sensor to measure the ligth intensity
The sketch is to control a stepper motor with ULN2003 driver board
controlled by Arduino UNO with use of the AccelStepper library for: acceleration and deceleration.
The driver board is from Phoenix Contact with the ULN 2003 driver chip
Modified by Ben Bakker 25-november 2021 */
#include <AccelStepper.h> // Include the AccelStepper library:
// Motor pin definitions:
#define motorPin1 9 // IN1 on the ULN2003 driver
#define motorPin2 10 // IN4 on the ULN2003 driver
#define motorPin3 11 // IN3 on the ULN2003 driver
#define motorPin4 12 // IN2 on the ULN2003 driver
#define MotorInterfaceType 8 // Define the AccelStepper interface type;
// type 8 means 4 wire motor in half step mode:
// Initialize the pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper library for stepper motor:
AccelStepper stepper = AccelStepper(MotorInterfaceType, motorPin1, motorPin3, motorPin2, motorPin4);
const int startPin = A2; // Read the value of the LDR
const int sensorPin1 = 2; // Read the sensor ( read contact sensor ) (gate in closed position), for safety after power reset.
// when the power for whatever reason is reset, the system is trying to re close the gate.
// when the gate is already in the closed position, this creates mechanical problems.
const int sensorPin2 = 3; // Read the sensor ( reed contact sensor ) (gate in open position), for safety after power reset.
// when the power for whatever reason is reset, the system is trying to re open the gate.
// when the gate is already in the open position, this creates mechanical problems.
void setup(){
stepper.setMaxSpeed(256); // maximum speed if more then 768 stepmotor becomes noisy
stepper.setAcceleration(200); // Set the maximum acceleration in steps per second^2:
Serial.begin(115200); // Set Serial port Baudrate to 115200
pinMode(startPin, INPUT_PULLUP); // Make pin A2 input with internal pullup, LDR
pinMode(sensorPin1, INPUT_PULLUP); // Make pin 2 input with internal pullup
pinMode(sensorPin2, INPUT_PULLUP); // Make pin 3 input with internal pullup
} // End of Setup
void loop (){
if (analogRead(startPin) <=400){ // Run steppermotor 5800 steps forward
stepper.moveTo(5800); // 5880 steps are needed for 3,8 revolution for a distance of 38 cm
stepper.runToPosition(); // Run to position with set speed and acceleration:
delay(1000); // To make it less sensative for small interuptions
// Power on steppermotor stayes consuming 0.5 Amp
if (analogRead(startPin) >= 600){ // reverse direction, run back to original position:
delay(100); // Not needed but avoids contact bouncing in case of mechanical contacts
stepper.moveTo(0); // Steps back 5800 steps to come back to start position
stepper.runToPosition(); // Run back to start position with set speed and acceleration:
delay(1000); // To make it less sensative for very small interuptions
} // End of closing the gate ( down )
} // End of Loop
}
// Power on steppermotor stayes consuming 0.5 Amp
#include <AccelStepper.h> // Include the AccelStepper library:
// Motor pin definitions:
#define motorPin1 9 // IN1 on the ULN2003 driver
#define motorPin2 10 // IN4 on the ULN2003 driver
#define motorPin3 11 // IN3 on the ULN2003 driver
#define motorPin4 12 // IN2 on the ULN2003 driver
#define MotorInterfaceType 8 // Define the AccelStepper interface type;
// type 8 means 4 wire motor in half step mode:
// Initialize the pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper library for stepper motor:
AccelStepper stepper = AccelStepper(MotorInterfaceType, motorPin1, motorPin3, motorPin2, motorPin4);
const int startPin = A2; // Read the value of the LDR
const int sensorPin1 = 2; // Read the sensor ( read contact sensor ) (gate in closed position), for safety after power reset.
// when the power for whatever reason is reset, the system is trying to re close the gate.
// when the gate is already in the closed position, this creates mechanical problems.
const int sensorPin2 = 3; // Read the sensor ( reed contact sensor ) (gate in open position), for safety after power reset.
// when the power for whatever reason is reset, the system is trying to re open the gate.
// when the gate is already in the open position, this creates mechanical problems.
void setup(){
stepper.setMaxSpeed(256); // maximum speed if more then 768 stepmotor becomes noisy
stepper.setAcceleration(200); // Set the maximum acceleration in steps per second^2:
Serial.begin(115200); // Set Serial port Baudrate to 115200
pinMode(startPin, INPUT_PULLUP); // Make pin A2 input with internal pullup, LDR
pinMode(sensorPin1, INPUT_PULLUP); // Make pin 2 input with internal pullup
pinMode(sensorPin2, INPUT_PULLUP); // Make pin 3 input with internal pullup
} // End of Setup
void loop (){
if (analogRead(startPin) <=400){ // Run steppermotor 5800 steps forward
stepper.moveTo(5800); // 5880 steps are needed for 3,8 revolution for a distance of 38 cm
stepper.runToPosition(); // Run to position with set speed and acceleration:
delay(1000); // To make it less sensative for small interuptions
// Power on steppermotor stayes consuming 0.5 Amp
if (analogRead(startPin) >= 600){ // reverse direction, run back to original position:
delay(100); // Not needed but avoids contact bouncing in case of mechanical contacts
stepper.moveTo(0); // Steps back 5800 steps to come back to start position
stepper.runToPosition(); // Run back to start position with set speed and acceleration:
delay(1000); // To make it less sensative for very small interuptions
} // End of closing the gate ( down )
} // End of Loop
}
// Power on steppermotor stayes consuming 0.5 Amp
...