PROPORTIONAL CONTROL STEPPER WITH IR DISTANCE

STEPPER IR pr uln

The code can be downloaded at:

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/STEPPER%20WITH%20IR%20SENSOR.zip

#include <AccelStepper.h>

#define HALFSTEP 8

// Motor pin definitions
#define motorPin1 12 // IN1 on the ULN2003 driver 1
#define motorPin2 11 // IN2 on the ULN2003 driver 1
#define motorPin3 10 // IN3 on the ULN2003 driver 1
#define motorPin4 9 // IN4 on the ULN2003 driver 1

// Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper with 28BYJ-48
AccelStepper stepper(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
#define ANALOG_IN A0

void setup()
{
stepper.setMaxSpeed(1000);
}

void loop()
{
// Read new position
int analog_in = analogRead(ANALOG_IN);
stepper.moveTo(analog_in*5);
stepper.setSpeed(2000);
stepper.runSpeedToPosition();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s