hi there,
my aim create code controls stepper motors speed , duration while simultaneously reading potentiometers' value through lcd display.
i have access iic/i2c serial 2.5" lcd 1602 display module, load cell amplifier of made myself simulate potentiometer on output side, byj48 stepper motor , uln2004 motor driver.
what want add functionality motor build 7rpm 35rpm on 5 seconds, displaying on lcd.
then motor amount of turns, lets 10 , want lcd count down 10 0 progresses.
i want use second line of lcd display show feedback 'potentiometer' in form of units such volts.
finally once motor has stopped want arduino average feedback 'potentiometer' during course of test , display average on lcd display.
i getting there, not have knowledge complete it.
i have mechanical , electrical know-how no idea on programming front.
pleassseee helpppp.
my aim create code controls stepper motors speed , duration while simultaneously reading potentiometers' value through lcd display.
i have access iic/i2c serial 2.5" lcd 1602 display module, load cell amplifier of made myself simulate potentiometer on output side, byj48 stepper motor , uln2004 motor driver.
what want add functionality motor build 7rpm 35rpm on 5 seconds, displaying on lcd.
then motor amount of turns, lets 10 , want lcd count down 10 0 progresses.
i want use second line of lcd display show feedback 'potentiometer' in form of units such volts.
finally once motor has stopped want arduino average feedback 'potentiometer' during course of test , display average on lcd display.
i getting there, not have knowledge complete it.
i have mechanical , electrical know-how no idea on programming front.
pleassseee helpppp.
code: [select]
/*
connect lcd:
vcc -> 5v,
gnd -> gnd,
sda -> a4,
scl -> a5
connect 24byj-48 stepper motor:
in1 -> d8
in2 -> d9
in3 -> d10
in4 -> d11
vcc ... 5v prefer use external 5v source
gnd
connect load cell amplifier if potentiometer:
5v -> 5v
gnd -> gnd
out -> a0
*/
////////////////////////////////////////////////////////////////////////////////
// include libraries
#include <wire.h>
#include <lcd.h>
#include <liquidcrystal_i2c.h>
////////////////////////////////////////////////////////////////////////////////
// declare variables motor pins
int in1 = 8; // blue - 28byj48 pin 1
int in2 = 9; // pink - 28byj48 pin 2
int in3 = 10; // yellow - 28byj48 pin 3
int in4 = 11; // orange - 28byj48 pin 4
// red - 28byj48 pin 5 (vcc)
int steps = 0;
boolean direction = true;
unsigned long last_time;
unsigned long currentmillis ;
int steps_left = 4096;
long time;
// declare variables lcd display
#define i2c_addr 0x27
#define backlight_pin 3
#define en_pin 2
#define rw_pin 1
#define rs_pin 0
#define d4_pin 4
#define d5_pin 5
#define d6_pin 6
#define d7_pin 7
liquidcrystal_i2c lcd(i2c_addr, en_pin, rw_pin, rs_pin, d4_pin, d5_pin, d6_pin, d7_pin, backlight_pin, positive);
lcd *mylcd = &lcd;
// declare variables load cell amplifier
int sensor_pin = 0; // center pin of potentiometer
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
// declare motor pins outputs
pinmode(in1, output);
pinmode(in2, output);
pinmode(in3, output);
pinmode(in4, output);
serial.begin(9600);
// begin lcd display, welcome , dispaly speed , rotation
lcd.begin(16, 2); // initialize lcd
lcd.home (); // go home
lcd.print("welcome back-to-back capstan test machine");
lcd.home(); // clear screen
lcd.print("speed:"); // display speed
lcd.setcursor(10, 0); // go end of line 1
lcd.print("n/min"); // display rotations per minute
delay(1000);
lcd.home(); // clear screen
lcd.setcursor(0, 0); // go beginning again
lcd.print("turns left:"); // remaining test time count down
}
////////////////////////////////////////////////////////////////////////////////
void loop()
{
while (steps_left > 0) {
currentmillis = micros();
if (currentmillis - last_time >= 1000) {
stepper(1);
time = time + micros() - last_time;
last_time = micros();
steps_left--;
}
}
serial.println(time);
serial.println("wait...!");
delay(2000);
direction = !direction;
steps_left = 4096;
}
///////////////////////////////////////////////////////////////////////////////
// set pins uln2003 high in sequence 1 4
void stepper(int xw) {
(int x = 0; x < xw; x++) {
switch (steps) {
case 0:
digitalwrite(in1, low);
digitalwrite(in2, low);
digitalwrite(in3, low);
digitalwrite(in4, high);
break;
case 1:
digitalwrite(in1, low);
digitalwrite(in2, low);
digitalwrite(in3, high);
digitalwrite(in4, high);
break;
case 2:
digitalwrite(in1, low);
digitalwrite(in2, low);
digitalwrite(in3, high);
digitalwrite(in4, low);
break;
case 3:
digitalwrite(in1, low);
digitalwrite(in2, high);
digitalwrite(in3, high);
digitalwrite(in4, low);
break;
case 4:
digitalwrite(in1, low);
digitalwrite(in2, high);
digitalwrite(in3, low);
digitalwrite(in4, low);
break;
case 5:
digitalwrite(in1, high);
digitalwrite(in2, high);
digitalwrite(in3, low);
digitalwrite(in4, low);
break;
case 6:
digitalwrite(in1, high);
digitalwrite(in2, low);
digitalwrite(in3, low);
digitalwrite(in4, low);
break;
case 7:
digitalwrite(in1, high);
digitalwrite(in2, low);
digitalwrite(in3, low);
digitalwrite(in4, high);
break;
default:
digitalwrite(in1, low);
digitalwrite(in2, low);
digitalwrite(in3, low);
digitalwrite(in4, low);
break;
}
////////////////////////////////////////////////////////////////////////////////
// display load cell value
int sensorvalue = analogread(sensor_pin);
// set cursor second row, first column
lcd.setcursor(0, 1);
float voltage = sensorvalue * (5.0 / 1023.0);
lcd.print(voltage);
lcd.print(" ");
delay (100);
////////////////////////////////////////////////////////////////////////////////
setdirection();
}
}
void setdirection() {
if (direction == 1) {
steps++;
}
if (direction == 0) {
steps--;
}
if (steps > 7) {
steps = 0;
}
if (steps < 0) {
steps = 7;
}
}
and not cross-post, cross-posting wastes time.
duplicate deleted.
Arduino Forum > Using Arduino > Project Guidance > Mech Eng student need help with programming for thesis. PLEASE
arduino
Comments
Post a Comment