Hi All
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
}
}
11 posts - 6 participants