Notifications
Clear all

control Stepper motor with temperature  

  RSS

Jocke
(@jocke)
Active Member
Joined: 4 months ago
Posts: 7
2020-08-22 2:49 pm  

Hey all . hope you have a nice weekend! I want help from someone who can write code. myself I am new came into this and have read and write difficulties. I want to burn wood in my wood boiler. for that I need to control the air intake. I have an Arduino Uno and a stepper motor, 42byghw811. and a l298n. a temperature probe ds18b20. I want Stepper Motor to rotate 2 full turns from 70 "to 90" Celsius. Stepper motor has 200 steps per revolution. is there anyone who wants to help I am very grateful.


 


Quote
frogandtoad
(@frogandtoad)
Honorable Member
Joined: 1 year ago
Posts: 540
2020-08-23 9:42 am  
Posted by: @jocke

Hey all . hope you have a nice weekend! I want help from someone who can write code. myself I am new came into this and have read and write difficulties. I want to burn wood in my wood boiler. for that I need to control the air intake. I have an Arduino Uno and a stepper motor, 42byghw811. and a l298n. a temperature probe ds18b20. I want Stepper Motor to rotate 2 full turns from 70 "to 90" Celsius. Stepper motor has 200 steps per revolution. is there anyone who wants to help I am very grateful.


 

In your Arduino IDE, under: "File -> Examples -> Stepper.*"

... you can find some default, introductory working code examples to get you started.

Please feel free to ask any questions about any parts of the code you're having difficulty with, and we'll be happy to help.  Also note, that your own stepper library/motor will most likely come with some examples too... just search the examples section.

Cheers!


ReplyQuote
Jocke
(@jocke)
Active Member
Joined: 4 months ago
Posts: 7
2020-08-23 9:54 am  

@frogandtoad Okay! But I do not know how to map the temp sensor to the Stepper Motor to rotate 2 revolutions from 70 degrees Celsius to 90 degrees Celsius. at slow speed


ReplyQuote
Jocke
(@jocke)
Active Member
Joined: 4 months ago
Posts: 7
2020-08-23 10:08 am  

I'm running this code now as a test.
wants to change the potentiomer to temp probe and to a digital input.
otror I can use the map command to make the stepper motor rotate 2 turns from 70 degrees Celsius to 90 degrees Celsius and then back.

/*
Stepper Motor Demonstration 3
Stepper-Demo3.ino
Demonstrates NEMA 17 Bipolar Stepper with L298N Driver
Uses Potentiometer on Analog Input A0
Uses Arduino Stepper Library

DroneBot Workshop 2018
https://dronebotworkshop.com
*/

// Include the Arduino Stepper Library
#include <Stepper.h>

// Define Constants

// Number of steps per output rotation              
const int STEPS_PER_REV = 200;
const int SPEED_CONTROL = A0;

// Create Instance of Stepper Class
// Specify Pins used for motor coils
// The pins used are 8,9,10,11
// Connected to L298N Motor Driver In1, In2, In3, In4
// Pins entered in sequence 1-2-3-4 for proper step sequencing

Stepper stepper_NEMA17(STEPS_PER_REV, 8, 9, 10, 11);

void setup() {
// nothing to do inside the setup
}

void loop() {

 


ReplyQuote
Jocke
(@jocke)
Active Member
Joined: 4 months ago
Posts: 7
2020-08-23 10:10 am  

// Define Constants

// Number of steps per output rotation
const int STEPS_PER_REV = 200;
const int SPEED_CONTROL = A0;

// Create Instance of Stepper Class
// Specify Pins used for motor coils
// The pins used are 8,9,10,11
// Connected to L298N Motor Driver In1, In2, In3, In4
// Pins entered in sequence 1-2-3-4 for proper step sequencing

Stepper stepper_NEMA17(STEPS_PER_REV, 8, 9, 10, 11);

void setup() {
// nothing to do inside the setup
}

void loop() {
// read the sensor value:
int sensorReading = analogRead(SPEED_CONTROL);
// map it to a range from 0 to 100:
int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
// set the motor speed:
if (motorSpeed > 0) {
stepper_NEMA17.setSpeed(motorSpeed);
// step 1/100 of a revolution:
stepper_NEMA17.step(STEPS_PER_REV / 200);
}
}


ReplyQuote
Jocke
(@jocke)
Active Member
Joined: 4 months ago
Posts: 7
2020-08-23 10:25 am  
20200823 111611
20200823 111641
20200823 111601

ReplyQuote
Jocke
(@jocke)
Active Member
Joined: 4 months ago
Posts: 7
2020-08-27 8:42 pm  
I'm running dim code now. but I want the stepper motor to rotate 2 revolutions between 70 degrees to 90 degrees Celsius. can you explain how i did this best jocke

Visa mindre

 

#include "Arduino.h"

// The preferred stepper motor driver
#include <AccelStepper.h>
#include <OneWire.h>

// Easy-to-use OneWire DS18B20 temperature library
#include <DallasTemperature.h>

// We want half step (not full step) control of the stepper
#define HALFSTEP 8

// Motor pin definitions
// Blue - 28BYJ48 pin 1
// Pink - 28BYJ48 pin 2
// Yellow - 28BYJ48 pin 3
// Orange - 28BYJ48 pin 4
// Red - 28BYJ48 pin 5 (VCC)

#define motorPin1 3 // IN1 on the ULN2003 driver 1
#define motorPin2 4 // IN2 on the ULN2003 driver 1
#define motorPin3 5 // IN3 on the ULN2003 driver 1
#define motorPin4 6 // IN4 on the ULN2003 driver 1

#define sensorPin 2 // Stepper microswitch sensor
#define tempPin 12 // DS18B20 Temperature sensor

// Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper with 28BYJ-48
AccelStepper stepMotor(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);

// Initialise OneWire comms
OneWire oneWire(tempPin);

// DallasTemp object needs that OneWire setup
DallasTemperature tempSensor(&oneWire);

// Temperature capture
int currTemp = 0;
int oldTemp = 0;

// -------------------------------------------------------------------
// SETUP SETUP SETUP SETUP SETUP SETUP SETUP
// -------------------------------------------------------------------
void setup() {
Serial.begin(9600);

// Start the temperature sensor
tempSensor.begin();

// Set some constraints on the stepper motor
stepMotor.setMaxSpeed(500.0);
stepMotor.setAcceleration(100.0);
stepMotor.setSpeed(50);

// Complete anticlockwise circle until we find the reference point
stepMotor.moveTo(4096 + 100); //4096

// This is the microswitch reference point
pinMode(sensorPin, INPUT_PULLUP);

// Power to the motor is ON
stepMotor.enableOutputs();
Serial.println("Moving stepper to known reference point");

//If we are already STOPPED then move off the mark and re-reference
while (digitalRead(sensorPin) == LOW) {
stepMotor.run();
}

// Now continue to turn until we reach our reference point
while (!digitalRead(sensorPin) == LOW) {
stepMotor.run();
}

// Stop when reference point reached and set the zero position
stepMotor.stop();
stepMotor.setCurrentPosition(0);
Serial.println("Stepper motor at reference point.");

// Set the stepper motor power off
stepMotor.disableOutputs();
delay(1000);
}

long mapTempToPos(long newTemp);
void doPointerMove();

// -------------------------------------------------------------------
// LOOP LOOP LOOP LOOP LOOP LOOP LOOP LOOP
// -------------------------------------------------------------------
void loop() {

// 1. Get the temperature and remember its value
// 2. Move pointer to temperature value via stepper
// 3. Repeat if temperature changes (whole degrees only)
// 4. Allow serial monitor input if connected to IDE

// Get temperature reading in whole degrees rounded to nearest value
tempSensor.requestTemperatures();
currTemp = (int) round(tempSensor.getTempCByIndex(0));

// Has temperature changed (significantly - i.e. whole degrees)
if (currTemp != oldTemp) {
doPointerMove();
}
else
{
// Allow serial monitor input (for testing!) If you put in
// non-numeric values the world as we know it will end.
char manualTemp[3];
if (Serial.available()){
// Read all NUMERIC characters until new line
Serial.println("Manual entry detected");
int charCnt = Serial.readBytesUntil('\n', manualTemp, 3);
manualTemp[charCnt] = '\0';

// Overwrite the current temperature sensor value
currTemp = atoi(manualTemp);
doPointerMove();
}
}

// Loop delay
delay(5000);
}

// -------------------------------------------------------------------
// POINTER MOVE POINTER MOVE POINTER MOVE POINTER MOVE
// -------------------------------------------------------------------
void doPointerMove() {
Serial.println("Temperature Change Detected");

Serial.print("Temperature: ");
Serial.print(oldTemp);
Serial.print(" vs. ");
Serial.println(currTemp);

stepMotor.moveTo(mapTempToPos(currTemp));

// turn on stepper motor
stepMotor.enableOutputs();
Serial.println("Stepper Motor ON");
stepMotor.run();

Serial.println("Stepper moving to new position");
while (stepMotor.isRunning()) {
stepMotor.run();
}

// turn off stepper motor
stepMotor.disableOutputs();
Serial.println("Stepper Motor OFF");

// Remember current temperature
oldTemp = currTemp;
}

// -------------------------------------------------------------------
// MAP TEMP TO SCALE MAP TEMP TO SCALE MAP TEMP TO SCALE
// -------------------------------------------------------------------
long mapTempToPos(long newTemp) {

// Convert the temperature to the stepper 90-degree range
// Note that if you change this the pointer will have a different range
long mappedTemp = map(newTemp - 5, -5, 5, 0, 1024);

// Debugging messages
Serial.print("Input temperature: ");
Serial.print(newTemp);
Serial.print("\tMapped to scale value: ");
Serial.println(mappedTemp);

// All done
return -mappedTemp;
}


ReplyQuote