#define stepPerRev 800 // 800 FOR BIG Motor to TRAVEL 0.4mm,
(Adjustable, different motors have different step sizes, and increase to increase travel distance.)
void setup() {
// put your setup code here, to run once:
pinMode(2, OUTPUT); // DIR+
pinMode(3, OUTPUT); // PUL+
}
void loop() {
// put your main code here, to run repeatedly:
for (int i = 0; i < 1*stepPerRev; i++) {
digitalWrite(2, HIGH); // CONTROL DIRECTION OF MOTOR
digitalWrite(3, LOW);
digitalWrite(3, HIGH);
delayMicroseconds(1000); // CONTROL SPEED OF MOTOR
}
delay(1000); // PAUSE FOR 1000 Milliseconds
for (int i = 0; i < 1*stepPerRev; i++) {
digitalWrite(2, LOW); // CONTROL DIRECTION OF MOTOR
digitalWrite(3, LOW);
digitalWrite(3, HIGH);
delayMicroseconds(100); // CONTROL SPEED OF MOTOR
}
delay(1750); // PAUSE FOR 1750 Milliseconds
while(1){ // This while loop stops the code from looping so
} // delete this to run continuously
}
// Email yuj025@ucsd.edu if you have any questions. (Email account may expire after 2024)
____________________________________________________________________________________________________________________________
____________________________________________________________________________________________________________________________
#define stepPerRev 2427 // 2427 FOR SMALL TRAVEL 1 mm.
(Adjustable, different motors have different step sizes, and increase to increase travel distance.)
void setup() {
// put your setup code here, to run once:
pinMode(2, OUTPUT); // DIR+
pinMode(3, OUTPUT); // PUL+
}
void loop() {
// put your main code here, to run repeatedly:
for (int i = 0; i < 1*stepPerRev; i++) { // 32000 is for max loop size.
digitalWrite(2, HIGH); // CONTROL DIRECTION OF MOTOR
digitalWrite(3, LOW);
digitalWrite(3, HIGH);
delayMicroseconds(100); // CONTROL SPEED OF MOTOR, ALL > 50
}
delay(1750); // Adjustable.
while(1){ // This while loop stops the code from looping so
} // delete this to run continuously
}
// Email yuj025@ucsd.edu if you have any questions. (Email account may expire after 2024)
DIR+ to pin 3
PUL+ to pin 2
B- to orange
B+ to yellow
A- to black
A+ to brown
// Daniel Acosta
// daacosta@ucsd.edu or daacosta.mae@gmail.com
// MAE 156 - Cohu Pin Project
// UCSD - Winter 2024
// This code is used to run the force inspection subsystem.
// 1) It will read the load applied to a Futek S-Beam Load Cell.
// 2) It will read that value to a digital display.
// 3) A motor controller will also move the entire load cell 0.4mm
// Inspiration for the code has been taken from example codes
// shared by Arduino and board Manufacturers.
// Resource from SparkFun:
// https://learn.sparkfun.com/tutorials/load-cell-amplifier-hx711-breakout-hookup-guide/all
//Defining all things for SparkFun Load Cell Amplifier compatibility:
#include "HX711.h"
// Define Calibration Factor for load cell:
#define cal_factor -62500 // Change to calibrate readings
#define Dout 3 // Dout Pin
#define CLK 2 // CLK Pin
HX711 scale;
// Defining all things for 1602 Serial LCD Module Display:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // Defining I2C address and size of LCD
// Defining everything to run motor controller:
#define stepPerRev 4000 // Defines the travel of the motor, changing depending on motor.
const int DirP = 8;
const int PulP = 9;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
// Initializing SparkFun AMP:
scale.begin(Dout, CLK);
scale.tare(); // tares load cell upon start up
scale.set_scale(cal_factor); // Setting Calibration factor
Serial.println("Readings");
// Initializing LCD:
lcd.init();
lcd.backlight();
// Initializing Motor Controller:
pinMode(DirP, OUTPUT);
pinMode(PulP, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println("Going Back");
for (int i = 0; i < 1 * stepPerRev; i++) {
digitalWrite(DirP, HIGH); // CONTROL DIRECTION OF MOTOR
digitalWrite(PulP, LOW);
digitalWrite(PulP, HIGH);
delayMicroseconds(100); // CONTROL SPEED OF MOTOR
}
float x = scale.get_units(); // 1 of 3 differnt measuring points
Serial.print(x, 2); // I believe the last number is the amount if float it returns.
Serial.println("gF");
Serial.println();
float y = scale.get_units(); // 2 of 3 differnt measuring points
Serial.print("Y = ");
Serial.println(y, 2);
delay(2000);
float z = scale.get_units(); // 3 of 3 differnt measuring points
Serial.print("Z = ");
Serial.println(z, 2);
Serial.println("Going Foward");
for (int i = 0; i < 1 * stepPerRev; i++) {
digitalWrite(DirP, LOW); // CONTROL DIRECTION OF MOTOR
digitalWrite(PulP, LOW);
digitalWrite(PulP, HIGH);
delayMicroseconds(100); // CONTROL SPEED OF MOTOR
}
delay(1500); // PAUSE FOR 1750 Milliseconds
lcd.setCursor(0, 0);
lcd.print("Force:");
lcd.setCursor(7, 0);
lcd.print(y, 3);
lcd.setCursor(14, 0);
lcd.print("gF");
// If statement for checking inspection!
if ( y > 30.0 || y < 20.0) {
lcd.setCursor(0, 1);
lcd.print("Fail Inspection!");
}
else {
lcd.setCursor(0, 1);
lcd.print("Pass Inspection!");
}
}
#define stepPerRev 1818
const int buttonPin1 = 9; // the number of the pushbutton pin
const int buttonPin2 = 10;
const int buttonPin3 = 13;
const int buttonPin4 = 12;
const int buttonPin5 = 11;
const int in1 = 6; // the number of the LED pin
const int in2 = 7;
const int Pump = 8;
const int Right = 2;
const int Left = 3;
int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
void setup() {
// put your setup code here, to run once:
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT) ;
pinMode(Pump, OUTPUT) ;
pinMode(Right, OUTPUT) ;
pinMode(Left, OUTPUT) ;
// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
pinMode(buttonPin5, INPUT);
}
void loop() {
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
buttonState5 = digitalRead(buttonPin5);
// Linear Slider Control
// Check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState1 == HIGH) {
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);}
if (buttonState2 == HIGH) {
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
}
// Pump Control
if (buttonState3== HIGH) {
digitalWrite(8, HIGH); }
else
digitalWrite(8, LOW);
// Stepper Motor Control
if (buttonState4 == HIGH) {
for (int i=0 ; i < stepPerRev; i++) {
digitalWrite(2, HIGH); // CONTROL DIRECTION OF MOTOR
digitalWrite(3, LOW);
digitalWrite(3, HIGH);
delayMicroseconds(50); // MOTOR SPEED
}
delay(1000) ;
}
if (buttonState5 == HIGH) {
for (int i=0 ; i < stepPerRev; i++) {
digitalWrite(2, LOW); // CONTROL DIRECTION OF MOTOR
digitalWrite(3, LOW);
digitalWrite(3, HIGH);
delayMicroseconds(50); // MOTOR SPEED
}
delay(1000) ;
}
}