adding jogging for motor to sketch

hi guys
back again, trying to add the jogging part for my motor to feed the label roll in m/c,but i just dont seem to win these { } brackets confuse me still, i quite dont get it. ill post the sketch the last part is my jogging section, i am stuck.
im not even sure if i have it at the right place. sorry still learning

//*
//  Control of a 4 wire stepper motor with optical-sensor (TCST2103) high and low
//  readings with led confirming sensor status, reading 28mm x 32mm label on a roll
//  sensor reading 28mm edge of label. { Motor jogging function included.
//  (Under Construction) }.  
//*

#include <Stepper.h>

const int led = 13;        // led indicator on pin 19
const int buttonPin = 3;   // pushbutton on pin 5(motor inch)
const int sensor = 2;      // sensor on pin 4
const int stepsPerRevolution = 200;     // 1.8 degree step motor
Stepper myStepper(stepsPerRevolution, 9, 10, 11, 12);
int stepCount = 0;     // number of steps the motor has taken
int buttonState = 0;   // variable for reading the pushbutton status
int val = 0;       // variable to store the sensor status (value)

void setup() {
  
  pinMode(led, OUTPUT);        // initialize LED as an output
  pinMode(buttonPin, INPUT);   // initialize pushbutton pin as an input:
  pinMode(sensor, INPUT);      // initialize sensor as an input
  
}

void loop() {

    val = digitalRead(sensor);  // read sensor value
    if (val == LOW)  {          // check if the sensor is HIGH/LOW                            
    digitalWrite(led, LOW);     // turn led off
        
  } else {
      
    val = digitalRead(sensor);        // read sensor value
    if (val == HIGH)       
    digitalWrite(led, HIGH);           // turn led on 

    int sensorReading = analogRead(A0);   // pot to adjust motor speed
                     // map it to a range from 20 to 255:
    int motorSpeed = map(sensorReading, 0, 1023, 20, 255);
    if (motorSpeed > 0) 
    myStepper.setSpeed(motorSpeed);   // set the motor speed:
                                      // step 1/200 of a revolution:
    myStepper.step(stepsPerRevolution / 200);  // step 1/200 of a revolution:


   // buttonState = digitalRead(buttonPin);  // read the state of the pushbutton value:
   // if (buttonState == HIGH);     // the buttonState is HIGH: 
   // digitalWrite(led, HIGH);      // turn led on
   // myStepper.step(20);           // stepper run 20rpm

// } else {
     
  // if (buttonState == LOW);    // the bottonState is LOW
  // digitalWrite(led, LOW);     // turn led off
  // myStepper.step(0);          // stepper stop
   
   }
  }

pls any help

The word “jogging” only appears in the heading comment at the top of the code and nowhere in the actual code or comments. What do you mean when you use this word? What do you expect the output to do when it is “jogging”?

    int sensorReading = analogRead(A0);   // pot to adjust motor speed
    // map it to a range from 20 to 255:
    int motorSpeed = map(sensorReading, 0, 1023, 20, 255);
    if (motorSpeed > 0)

Well, motor speed can’t possibly be less than 20 according to this code, so there’s no point testing if it’s greater than zero.

hi m,
like this i can jog the motor when label in sensor (sensor reads the label) im trying to jog the motor to feed label in the sensor unit

``
//*
// Control of a 4 wire stepper motor with optical-sensor (TCST2103) high and low
// readings with led confirming sensor status, reading 28mm x 32mm label on a roll
// sensor reading 28mm edge of label. { Motor inch function included (Under Construction.) }
//*

#include <Stepper.h>

const int buttonPin = 3; // pushbutton on pin 5(motor inch)
const int led = 13; // led indicator on pin 19
const int sensor = 2; // sensor on pin 4
const int stepsPerRevolution = 200; // 1.8 degree step motor
int state = LOW; // default, no motion detected
int val = 0; // variable to store the sensor status (value)
// initialize the stepper library on pins 9 through 12:
Stepper myStepper(stepsPerRevolution, 9, 10, 11, 12); // initialize the stepper
//library on pins 9 through 12:
int stepCount = 0; // number of steps the motor has taken
int buttonState = 0; // variable for reading the pushbutton status

void setup() {

pinMode(led, OUTPUT); // initialize LED as an output
pinMode(sensor, INPUT); // initialize sensor as an input
pinMode(buttonPin, INPUT); // initialize pushbutton pin as an input:
}

void loop() {

val = digitalRead(sensor); // read sensor value
if (val == LOW) { // sensor value low
digitalWrite(led, LOW); { // turn led off
buttonState = digitalRead(buttonPin); //read botton value
if (buttonState == LOW) //botton state low
myStepper.step(0); // motor stop
}

} else {

val = digitalRead(sensor); // read sensor value
if (val == LOW); // sensor value low
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) { // button state high
myStepper.step(20); // run motor

val = digitalRead(sensor); // read sensor value
if (val == HIGH);
digitalWrite(led, HIGH); // turn led on

int sensorReading = analogRead(A0); // pot to adjust motor speed
// map it to a range from 20 to 255:
int motorSpeed = map(sensorReading, 0, 1023, 20, 255);
if (motorSpeed > 20);
myStepper.setSpeed(motorSpeed); // set the motor speed:
// step 1/200 of a revolution:
myStepper.step(stepsPerRevolution / 200); // step 1/200 of a revolution:

}
}
}

[/code]

To me, jog means run slowly if button is pressed, stop when button is released.

if (val == HIGH); <---- semicolon kills if condition, remove.

This is not needed, “val” cannot be HIGH and LOW at the same time.

} else {

  val = digitalRead(sensor);   // read sensor value
  if (val == LOW);             // sensor value low

hi guys
i think i have what is needed but some issues somewhere any hope.the last section does what it must read the labels , stop inbetwwen labels and carry on. i just need to jog the motor to feed the label roll in


void loop() {

val = digitalRead(sensor); // read sensor value
if (val == LOW) { // sensor value low
digitalWrite(led, LOW); // turn led off
buttonState = digitalRead(buttonPin); //read botton value
if (buttonState == LOW) //botton state low
myStepper.step(0); // motor stop

} else {

val = digitalRead(sensor); // read sensor value
if (val == LOW) // sensor value low
buttonState = digitalRead(buttonPin); // read botton value
if (buttonState == HIGH) // button state high
myStepper.step(20); // run motor

val = digitalRead(sensor); // read sensor value
if (val == HIGH) // sensor value high
digitalWrite(led, HIGH); // turn led on

int sensorReading = analogRead(A0); // pot to adjust motor speed
// map it to a range from 20 to 255:
int motorSpeed = map(sensorReading, 0, 1023, 20, 255);
if (motorSpeed > 20)
myStepper.setSpeed(motorSpeed); // set the motor speed:
// step 1/200 of a revolution:
myStepper.step(stepsPerRevolution / 200); // step 1/200 of a revolution:

}
}

You used code tags around your code in your initial post, then stopped. Why?
Code tags please. Formatting your code with “Auto Format” also helps.

After clicking on </>, place your code between the tags, not after them.

OldSteve:
You used code tags around your code in your initial post, then stopped. Why?
Code tags please. Formatting your code with “Auto Format” also helps.

After clicking on </>, place your code between the tags, not after them.

Code tags is mentioned under item #7 of “How to use this forum - please read”.

Another important section is #10.

  1. Post in proper sentences

This is a forum you are using, not a mobile phone.

As a courtesy to the people you are hoping to have help you, type complete sentences. That is:

Start with a capital letter.
Spell words properly.
Finish with a period (full-stop). (Just the one, thanks!)

I’ll be ill if I keep seeing “ill” where it should be “I’ll.”

HI Guys.
I’ve re-done the sketch and all i’m asking is help to unscramble my sketch so that i can JOG the motor. I’ve done it the way i see the whole operation to be run, i’m new and still learning so keep bad comments to yourself, i thought this is a community based platform to help others. Please show my mistakes and please explain why, that’s the only way people will learn. Don’t refer me back to this or that page because trust me I’ve 'read most and sometimes they just need a bit down to earth explaining.
Please read the beginning of the sketch I’ve explained as best as i can, everything works led, sensor,
speed control, just cant get the jogging section working.

[code]
//*
//         Using Arduino UNO to Program.
//  Control (L298N Driver) of a 4 wire Bipolar stepper motor with optical-sensor (TCST2103),
//  reading labels on a reel.(28mm x 32mm) with a spacing of 3mm  between labels. 
//  A led confirms sensor status. A pushbutton is used to (JOG/INCH the motor) to feed the
//  labels in the machine till the sensor can take over, starting the procedure of the labels
//  being applied to the product. 
//  A 5K Potentiometer is added to adjust the speed of the motor.  
//          { A Motor JOG/INCH function included (Under Construction.) }
//*   

#include <Stepper.h>

const int buttonPin = 3;   // pushbutton (pin 3 arduino - pin 5 ATmega 328P)
const int led = 13;        // led indicator (pin 13 arduino - pin 19 ATmega 328)
const int sensor = 2;      // sensor (pin 2 arduino - pin 4 ATmega 328)
const int stepsPerRevolution = 200;     // 1.8 degree step motor
int state = LOW;           // default, no motion detected
int val = 0;               // variable to store the sensor status (value)

                           // initialize the stepper library on pins 9 through 12.
Stepper myStepper(stepsPerRevolution, 9, 10, 11, 12);  //(pin 9-12 arduino - pin 15-18 ATmega 328)
                           
int stepCount = 0;         // number of steps the motor has taken
int buttonState = 0;       // variable for reading the pushbutton status

void setup() {

  pinMode(led, OUTPUT);         // initialize LED as an output
  pinMode(sensor, INPUT);       // initialize sensor as an input
  pinMode(buttonPin, INPUT);    // initialize pushbutton pin as an input:
}

void loop() {

  val = digitalRead(sensor);     // read sensor value
  if (val == LOW)  {             // sensor value low
    digitalWrite(led, LOW);       // turn led off
    buttonState = digitalRead(buttonPin);     //read botton value
    if (buttonState == LOW)        //botton state low
      myStepper.step(0);             // motor stop

  } else {

    val = digitalRead(sensor);    // read sensor value
    if (val == HIGH)              // sensor value low
      buttonState = digitalRead(buttonPin);   // read botton value
    if (buttonState == HIGH)     // button state high
      myStepper.step(20);           // run motor

    val = digitalRead(sensor);    // read sensor value
    if (val == HIGH)             // sensor value high
      digitalWrite(led, HIGH);      // turn led on

    int sensorReading = analogRead(A0);   // pot to adjust motor speed
    // map it to a range from 20 to 255:
    int motorSpeed = map(sensorReading, 0, 1023, 20, 255);
    if (motorSpeed > 20)
      myStepper.setSpeed(motorSpeed);      // set the motor speed:
    // step 1/200 of a revolution:
    myStepper.step(stepsPerRevolution / 200);  // step 1/200 of a revolution:

  }
}

[/code]

@artois, I am guessing (because you have not said so yet) that by "jog" you mean that you want to be able to press a button and have the motor run slowly while you feed in a new roll of labels? Is that correct?

Before I can help, you need to explain clearly what the program you have posted actually does?

...R
Stepper Motor Basics
Simple Stepper Code
Planning and Implementing a Program

Without using the word "jog" please explain what "jog" means.

Hi all, MerryXmas to the lot of you.
After Many hours tinkering I’ve managed and won. These { } brackets really had me going to sort out the procedure of the code. Yes JOG / INCH I Mean to Move the motor a bit

[code]
//*
//         Using Arduino UNO to Program.
//  Control (L298N Driver) of a 4 wire Bipolar stepper motor with optical-sensor (TCST2103),
//  reading labels on a reel (28mm x 32mm) with a spacing of 3mm  between labels. A led confirms
//  sensor status and (JOG/INCH) delay. A pushbutton is used to (JOG/INCH) the motor with a 2 sec
//  delay between each push of the button, to feed the labels in the machine till, the sensor can 
//  take over, thus starting the procedure of the labels being applied to the product.
//  A 5K Potentiometer is added to adjust the speed of the motor.
//*

#include <Stepper.h>

const int buttonPin = 3;          // pushbutton (pin 3 arduino - pin 5 ATmega 328P)
const int led = 13;               // led indicator (pin 13 arduino - pin 19 ATmega 328)
const int sensor = 2;             // sensor (pin 2 arduino - pin 4 ATmega 328)
const int stepsPerRevolution = 200;     // 1.8 degree step motor
int state = LOW;                  // default, no motion detected
int val = 0;                      // variable to store the sensor status (value)

// initialize the stepper library on pins 9 through 12.
Stepper myStepper(stepsPerRevolution, 9, 10, 11, 12);  //(pin 9-12 arduino - pin 15-18 ATmega 328)

int stepCount = 0;              // number of steps the motor has taken
int buttonState = 0;            // variable for reading the pushbutton status

void setup() {
  pinMode(led, OUTPUT);         // initialize LED as an output
  pinMode(sensor, INPUT);       // initialize sensor as an input
  pinMode(buttonPin, INPUT);    // initialize pushbutton pin as an input:
}

void loop() {

  buttonState = digitalRead(buttonPin);  // read button value
  if (buttonState == HIGH)  {            // button state high
    val = digitalRead(sensor);           // read sensor value
    if (val == LOW)                      // sensor value low
      digitalWrite(led, HIGH);           // turn led on
    myStepper.step(50);                  // motor run
    delay (2000);
}   
 {
    val = digitalRead(sensor);           // read sensor value
    if (val == LOW)                      // sensor value low
      buttonState = digitalRead(buttonPin);  // read button value
    if (buttonState == LOW)              // button state low
      digitalWrite(led, LOW);            // turn led off
    myStepper.step(0);                   // stop motor

    val = digitalRead(sensor);           // read sensor value
    if (val == LOW)                      // sensor value low
      digitalWrite(led, LOW);            // turn led off
    val = digitalRead(sensor);           // read sensor value
    if (val == HIGH)   {                 // sensor value high
      digitalWrite(led, HIGH);           // turn led on

      int sensorReading = analogRead(A0);   // pot to adjust motor speed (0v-AO-5v) 
                 // map it to a range from 20 to 255:
      int motorSpeed = map(sensorReading, 0, 1023, 25, 255);
      if (motorSpeed > 25)
        myStepper.setSpeed(motorSpeed);     // set the motor speed:
                 // step 1/200 of a revolution:
      myStepper.step(stepsPerRevolution / 200); // step 1/200 of a revolution:

    }
  }
}

[/code]