I am an operations manager with a small bit of an engineering background and with an upcoming engineering degree that I am going into however my company is looking to get a stepper motor to start moving after a laser trigger is broken. I did do some coding in Highschool with Arduinos however it was a while ago and I am trying to get back into it to try to get this system working so that we can catch shirts from out oven. I am using a Motorshield V2 from HiLetgo(amazon special) on a V3 Arduino Uno.
The code that I had ChatGPT write is posted after this message. I also have the motorshield libtrary installed into the arduion ide.
#include <Wire.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"
#include <utility/imumaths.h>
#include <Adafruit_MS_Stepper.h>
// Define pins
const int laserPin = A0; // Analog pin connected to the phototransistor
// Create stepper motor object
Adafruit_MS_Stepper stepper = Adafruit_MS_Stepper(200, 2); // 200 steps per revolution, motor connected to port 1
// Define thresholds and parameters
const int threshold = 500; // Change this value based on your setup
const int stepsPerRevolution = 200; // Change this to your motor's specification
const int stepSpeed = 10; // Speed of the stepper motor (higher is faster)
void setup() {
Serial.begin(9600);
// Initialize the motor shield
if (!stepper.begin()) {
Serial.println("Motor Shield not detected. Check connections.");
while (1);
}
// Set the speed of the motor
stepper.setSpeed(200);
// Set initial position
stepper.setCurrentPosition(0);
}
void loop() {
int laserValue = analogRead(1);
Serial.println(laserValue);
if (laserValue < threshold) {
// Laser is broken, move stepper motor
stepper.step(200); // Move one revolution
delay(1000); // Optional: delay to prevent continuous movement
}
}
I Do Sorry, I am trying to mainly figure out why might I be getting compiling errors for the 3rd through 5th lines because currently I am running into the problem where i get an error saying no such directory. I am using IDE 2.3.2 and both the adafruit servo driver and Motorshield V2 libraries are installed however I am still getting the compiling errors
C:\Users\joeyt\Documents\Arduino\Shirt_robot\Shirt_robot.ino:2:10: fatal error: utility/Adafruit_PWM_ServoDriver.h: No such file or directory #include "utility/Adafruit_PWM_ServoDriver.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
exit status 1
Compilation error: utility/Adafruit_PWM_ServoDriver.h: No such file or directory
Which is NOT a current controlled stepper motor driver, and won't work with most modern low impedance stepper motors. Post a link to the motor you have.
Leo..
That 30 Ohm high-impedance Adafruit motor will work with that shield.
Fine for low step rates, but don't expect torque at higher speeds from that motor. For that you need a low impedance motor with a current controlled driver and a 24volt supply.
Leo..
One of the other users I showed the code to mentioned that it was not in so it was not searching locally for the library so changing the code to this resolved the compiling problem.