stepper motor with potentiometer controlled by arduino and xbee.

Discussion in 'Embedded Systems and Microcontrollers' started by Manas Bose, Mar 16, 2016.

  1. Manas Bose

    Thread Starter New Member

    Mar 16, 2016
    Hello all

    I am working on a project, where I have to control a stepper motor step control with the help of a potentiometer, and arduino ,I have wrote a skech with the help of a friend attached herewith, it is working fine.

    now I want to make this thing remote, I want to use 2 arduino and 2 xbee, on sending side a arduino, xbee, and a potentiometer will be there. On receiving side a arduino, xbee and a stepper motor will be there. Earlier one setup I made with servo motor.
    I and my friend don't have adequate knowledge of c ++, I hereby request u to kindly help
    In the coding, or at least if u can throw some light on it.

    Code (C):
    2. #include <Stepper.h>
    3. int current_position = 0;
    4. const char direction_pin = 2;
    5. const char step_pin = 3;
    6. const char pot_pin = 1; //analog input 1
    7. void setup()
    8. {
    9. pinMode(direction_pin, OUTPUT);
    10. pinMode(step_pin, OUTPUT);
    11. pinMode(pot_pin, INPUT);
    12. }
    14. void loop()
    15. {
    16. int  readvalue = analogRead(pot_pin);
    17. readvalue = map(readvalue,0,1023,0,1151);
    18. if (readvalue > current_position)
    19. {
    20. step_motor_forward();
    21. current_position += 1;
    22. }
    23. else if (readvalue < current_position)
    24. {
    25. step_motor_back();
    26. current_position -= 1;
    27. }
    28. }//end of loop
    30. void step_motor_forward()
    31. {
    32. digitalWrite(direction_pin, LOW);
    33. digitalWrite(step_pin, HIGH);
    34. digitalWrite(step_pin, LOW);
    35. }
    37. void step_motor_back()
    38. {
    39. digitalWrite(direction_pin, HIGH);
    40. digitalWrite(step_pin, HIGH);
    41. digitalWrite(step_pin, LOW);
    42. }
    Moderators note : used code tags for c
    Last edited by a moderator: Mar 16, 2016
  2. TheButtonThief

    Active Member

    Feb 26, 2011
    There are no line comments on your code, this makes it seriously hard for anyone else to read. Also, we need a schematic.
  3. dannyf

    Well-Known Member

    Sep 13, 2015
    That may be the case but you should know what you are trying to do and how you are tying to so it.
  4. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    Stepper motors require more than one pin to drive, depending on the type used. Here is a tutorial on using an Arduino to drive a unipolar stepper motor. Note that it uses four pins.
  5. mcgyvr

    AAC Fanatic!

    Oct 15, 2009
    What kind of help are you looking for?
    You need stepper driver..
    You should use google as there are plenty of examples of xbee to xbee communication..

    Its simply 2 parts.. get the master/slave talking to pass the pot value..
    Then read the pot value on the master and drive the stepper as needed..

    IMO.. 99.999% of any Arduino questions/sample files,etc.. are already done on the internet and easily found using google

    This should be sufficient for the xbee communication between the sender and receiver

    and there are TONS of stepper examples on the arduino site or just google "arduino stepper potentiometer"..
    Combine the 2 and voila..

    and a stepper does NOT work like a RC servo...
  6. Manas Bose

    Thread Starter New Member

    Mar 16, 2016
    Thank u sir,
    In this code , the stepper motor, will respond to pot. movement, ie full pot movement = 300 degree rotation of stepper.