#include <Stepper.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
const float BETA = 3950;
const int stepsPerRevolution = 200;
float currentSpeed;
// change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup()
{
lcd.init();
lcd.backlight();
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
}
void loop()
{
int analogValue = analogRead(A0);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
float motorSpeed = (54*(celsius)) - 1290;
if(celsius >= 25 && celsius <=35)
{
if(currentSpeed <= motorSpeed)
{
myStepper.setSpeed(motorSpeed);
myStepper.step(stepsPerRevolution);
currentSpeed = motorSpeed;
}
else if(currentSpeed >= motorSpeed )
{
myStepper.setSpeed(motorSpeed);
myStepper.step(stepsPerRevolution);
currentSpeed = motorSpeed;
}
}
// step one revolution in one direction:
//myStepper.step(stepsPerRevolution);
//delay(500);
// step one revolution in the other direction:
//myStepper.step(-stepsPerRevolution);
//delay(500);
Serial.print(" Temp: ");
Serial.println(celsius);
Serial.print (" MotorSpeed: ");
Serial.println(motorSpeed);
Serial.print(" CurrentSpeed:");
Serial.println(currentSpeed);
}