The circuit I created controls a motor and a heater.
Here's my problem;
The loop stops until the engine completes one lap.
And whe the engine completes one lap, it stops for a very, very short period of time and then turns again, and this happens continuously.
How to make the rotation of the motor smooth?
I'm a beginner in Arduino. I would be very glad if there is understanding and a simple explanation
Program;
#include <Wire.h>
#include <LiquidCrystal.h>
#include <Thermistor.h>
#include <NTC_Thermistor.h>
#include <SmoothThermistor.h>
#include <Stepper.h>
// Motor kontrolü için pin tanımlamaları
const int motorPins[] = {6, 7, 8, 9}; // IN1, IN2, IN3, IN4 pinleri
const int stepsPerRevolution = 200; // Motorun bir devirde attığı adım sayısı
Stepper myStepper(stepsPerRevolution, motorPins[0], motorPins[1], motorPins[2], motorPins[3]);
// Potansiyometre ve motor hızı için pin tanımlamaları
const int potPin = A1; // Motor Hız Kontrol Potu
int potValue = 0; // Potansiyometre değeri
int motorSpeed = 0; // Motor hızı
// LCD bağlantıları
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Termistör için pin tanımlamaları
#define SENSOR_PIN A0
#define REFERENCE_RESISTANCE 8000
#define NOMINAL_RESISTANCE 100000
#define NOMINAL_TEMPERATURE 25
#define B_VALUE 3950
#define SMOOTHING_FACTOR 5
Thermistor* thermistor = NULL;
const int role = 10; // Rölenin bağlandığı pin
const float lowerThreshold = 209; // Alt sıcaklık eşiği
const float upperThreshold = 210; // Üst sıcaklık eşiği
void setup() {
Serial.begin(9600);
// LCD'yi başlat
lcd.begin(16, 2);
pinMode(role, OUTPUT);
// Termistörü başlat
Thermistor* originThermistor = new NTC_Thermistor(
SENSOR_PIN,
REFERENCE_RESISTANCE,
NOMINAL_RESISTANCE,
NOMINAL_TEMPERATURE,
B_VALUE
);
thermistor = new SmoothThermistor(originThermistor, SMOOTHING_FACTOR);
}
void loop() {
// Potansiyometre değerini oku
potValue = analogRead(potPin);
// Potansiyometre değerini motor hızına map'le
motorSpeed = map(potValue, 0, 1023, 80, 370);
// Motor hızını ayarla
myStepper.setSpeed(motorSpeed);
// Motoru bir devirde döndür
myStepper.step(stepsPerRevolution);
// Sıcaklık ölçümü
const double celsius = thermistor->readCelsius();
const double kelvin = thermistor->readKelvin();
const double fahrenheit = thermistor->readFahrenheit();
if (celsius < lowerThreshold)
{
digitalWrite(role, HIGH); // Röleyi aç (ısıtıcıyı çalıştır)
}
else if (celsius > upperThreshold)
{
digitalWrite(role, LOW); // Röleyi kapat (ısıtıcıyı durdur)
}
// Motor hızını LCD ekranın 2. satırında göster
lcd.setCursor(0, 1);
lcd.print("MotorHizi:");
lcd.print(motorSpeed);
lcd.print("RPM ");
// LCD ekranın 1. satırına sıcaklık bilgisini yazdır
lcd.setCursor(0, 0);
lcd.print("Sicaklik:");
lcd.print(celsius);
lcd.print(" C, ");
}
Thank you, I'll try.
But in the loop there is only motor value, temperature value and printing on the LCD.
There's nothing else in the loop except for the variables.
I think this;
If I write the stepper motor loop with while, what will it end like?
The stepper library uses a blocking call .step() to move the motor and only returns after the movement has finished. Then, your code goes on to calculate the temperature, etc.
Use the AccelStepper library which allows you to takes steps while other things are happening.
There is also the MobaTools library that lots of people like (I have not used it) that allows the same asynchronous steps
I check the motor speed with a potentiometer. In the program I have given below, only when I delete the "lcd.print" commands, the pot works. When there is an LCD program, the motor rotates at the initial speed and the pot does not change the motor speed. Can you help?
(Also the right half of the lcd screen is broken for some reason, it has been working normally for a few days)
#include <LiquidCrystal.h>
#include <Thermistor.h>
#include <NTC_Thermistor.h>
#include <SmoothThermistor.h>
#include <AccelStepper.h>
#define stepsPerRevolution 200
// Motor kontrolü için pin tanımlamaları
// motor sürücü kartının pinlerini tanımla
const int in1 = 6;
const int in2 = 7;
const int in3 = 8;
const int in4 = 9;
// motoru tanımla
AccelStepper motor(AccelStepper::FULL4WIRE, in1, in2, in3, in4);
// Potansiyometre ve motor hızı için pin tanımlamaları
const int pot = A1; // Motor Hız Kontrol Potu
// LCD bağlantıları
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Termistör için pin tanımlamaları
#define SENSOR_PIN A0
#define REFERENCE_RESISTANCE 8000
#define NOMINAL_RESISTANCE 100000
#define NOMINAL_TEMPERATURE 25
#define B_VALUE 3950
#define SMOOTHING_FACTOR 5
Thermistor* thermistor = NULL;
const int role = 10; // Rölenin bağlandığı pin
const float lowerThreshold = 207; // Alt sıcaklık eşiği
const float upperThreshold = 213; // Üst sıcaklık eşiği
void setup() {
Serial.begin(9600);
// motorun maksimum hızını belirle (adım/s)
motor.setMaxSpeed(1000);
// motorun başlangıç hızını belirle (adım/s)
// motorun dönüş yönünü belirle (sabit olarak saat yönü)
motor.setPinsInverted(false, false, true);
// LCD'yi başlat
lcd.begin(16, 2);
pinMode(role, OUTPUT);
// Termistörü başlat
Thermistor* originThermistor = new NTC_Thermistor(
SENSOR_PIN,
REFERENCE_RESISTANCE,
NOMINAL_RESISTANCE,
NOMINAL_TEMPERATURE,
B_VALUE
);
thermistor = new SmoothThermistor(originThermistor, SMOOTHING_FACTOR);
}
void loop() {
// potansiyometrenin değerini oku (0-1023 arası)
int potValue = analogRead(pot);
// potansiyometrenin değerini motor hızına eşle (0-255 arası)
int motorSpeed = map(potValue, 0, 1023, 20, 370);
// motor hızını ayarla
motor.setSpeed(motorSpeed);
// motoru çalıştır
motor.runSpeed();
// Sıcaklık ölçümü
const double celsius = thermistor->readCelsius();
const double kelvin = thermistor->readKelvin();
const double fahrenheit = thermistor->readFahrenheit();
if (celsius < lowerThreshold)
{
digitalWrite(role, HIGH); // Röleyi aç (ısıtıcıyı çalıştır)
}
else if (celsius > upperThreshold)
{
digitalWrite(role, LOW); // Röleyi kapat (ısıtıcıyı durdur)
}
// Motor hızını LCD ekranın 2. satırında göster
lcd.setCursor(0, 1);
lcd.print("MotorHizi:");
lcd.print(motorSpeed);
lcd.print("RPM ");
// LCD ekranın 1. satırına sıcaklık bilgisini yazdır
lcd.setCursor(0, 0);
lcd.print("Sicaklik:");
lcd.print(celsius);
lcd.print(" C, ");
}
Poll the motor and step it if a step is due, implementing a constant speed as set by the most recent call to setSpeed(). You must call this as frequently as possible, but at least once per step interval,
Can you please tell a little bit more about your stepper and the driver? A link to a datasheet would be fine.
And what Arduino board are you using?
The update of your LCD always takes some time, which may get your stepper to 'stutter' a little bit if you create the step pulses within loop(). The MobaTools lib creates the step pulses via timer IRQ in the background. If needed pulses are even created while the LCD is updated.
The Motor Driver has 4 signal inputs and 4 motor pin outputs. I feed it with 12 volts.
Kolaha solved the problem, but I think I can improve it even more. At the moment, the engine heats up very quickly at low revs and starts to misfire.
The max output current of the motor drive is 2 amps, the motor works with 1.5 amps.
I don't know because it's my first time using a stepper motor. Vibration increases at low rpm. Is this normal?
The datasheet you provided contains al lot of different steppers regarding the coil current. The ancient L298 is not a suitable driver for most of them. You may damage driver/and or motor. Only the versions with 0.4A coil current and 30Ohm coil resistance may work - though it's not a good solution.
You need a current controlling driver like the DRV8825 or the TMC 220x drivers.