Stepper motor+ Lcd + relay + temperature sensor
i newbie in programming. have searched alot didnt come solution problem. these things mentioned in title arduino mega 2560. have written code, not complete have encountered problem dont know how right
here code:
you can see in void loop there delay of 1000 before "if" statement. delay temperature refresh on lcd after interval of 1000. problem want let stepper move in direction until condition met delay stepper takes 1 step in 1 second very slow. have tried remove interval, motor moves little faster refresh rate of temperature on lcd quick cant read being displayed.
please me.
here code:
code: [select]
/*-----( import needed libraries )-----*/
#include <wire.h>
#include <liquidcrystal_i2c.h>
#include <stepper.h>
/*-----( declare constants )-----*/
/*-----( declare objects )-----*/
// set lcd address 0x27 20 chars 4 line display
liquidcrystal_i2c lcd(0x27,20,4);
/*-----( declare variables )-----*/
float tempc;
int temppin = a7;
int relay1 = 43;
int relay2 = 45;
//int relay3 = 47;
//int relay4 = 49;
//declare variables motor pins
int motorpin1 = 8; // blue - 28byj48 pin 1
int motorpin2 = 9; // pink - 28byj48 pin 2
int motorpin3 = 10; // yellow - 28byj48 pin 3
int motorpin4 = 11; // orange - 28byj48 pin 4
// red - 28byj48 pin 5 (vcc)
int motorspeed = 1200; //variable set stepper speed
int count = 0; // count of steps made
int countsperrev = 512; // number of steps per full revolution
int lookup[8] = {b01000, b01100, b00100, b00110, b00010, b00011, b00001, b01001};
//////////////////////////////////////////////////////////////////////////////
void setup() /*----( setup: runs once )----*/
{
serial.begin(9600);
pinmode(relay1, output);
pinmode(relay2, output);
//pinmode(relay3, output);
//pinmode(relay4, output);
//declare motor pins outputs
pinmode(motorpin1, output);
pinmode(motorpin2, output);
pinmode(motorpin3, output);
pinmode(motorpin4, output);
lcd.init(); // initialize lcd
// print our characters on lcd
lcd.backlight(); //backlight on if under program control
lcd.setcursor(3,0);
lcd.print("welcome");
delay(500);
lcd.setcursor(0,1);
lcd.print("genset control");
delay(500);
lcd.setcursor(0,2);
lcd.print("==================");
delay(2000);
lcd.clear();
lcd.setcursor(0,0); //start @ character 3 on line 0
lcd.print("t w=");
lcd.setcursor(10,0);
lcd.print("t o=");
//lcd.setcursor(0,2);
//lcd.print("abc");
//lcd.setcursor(0,3);
//lcd.print("abc");
}/*--(end setup )---*/
void loop() /*----( loop: runs )----*/
{
{
tempc = analogread(temppin); //read value sensor
tempc = (5.0 * tempc * 100.0)/1024.0; //convert analog data temperature
serial.print((byte)tempc); //send data computer
lcd.setcursor(4,0);
lcd.print(tempc);
delay(1000);
if (tempc < 26.00) {
digitalwrite(relay2, high);
digitalwrite(relay1, low);
clockwise(); }
else {
digitalwrite(relay1, high);
digitalwrite(relay2, low);
anticlockwise(); }
// when characters arrive on serial port...
if (serial.available()) {
// wait bit entire message arrive
delay(100);
// clear screen
lcd.clear();
// read available characters
while (serial.available() > 0) {
// display each character lcd
lcd.write(serial.read());
}
}
}
}/* --(end main loop )-- */
//////////////////////////////////////////////////////////////////////////////
//set pins uln2003 high in sequence 1 4
//delay "motorspeed" between each pin setting (to determine speed)
void anticlockwise()
{
for(int = 0; < 8; i++)
{
setoutput(i);
delaymicroseconds(motorspeed);
}
}
void clockwise()
{
for(int = 7; >= 0; i--)
{
setoutput(i);
delaymicroseconds(motorspeed);
}
}
void setoutput(int out)
{
digitalwrite(motorpin1, bitread(lookup[out], 0));
digitalwrite(motorpin2, bitread(lookup[out], 1));
digitalwrite(motorpin3, bitread(lookup[out], 2));
digitalwrite(motorpin4, bitread(lookup[out], 3));
}
/* ( end ) */
you can see in void loop there delay of 1000 before "if" statement. delay temperature refresh on lcd after interval of 1000. problem want let stepper move in direction until condition met delay stepper takes 1 step in 1 second very slow. have tried remove interval, motor moves little faster refresh rate of temperature on lcd quick cant read being displayed.
please me.
have @ blink without delay example clues on how eliminate calls "delay".
Arduino Forum > Using Arduino > Programming Questions > Stepper motor+ Lcd + relay + temperature sensor
arduino
Comments
Post a Comment