element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Stepper Motor With FRS
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 2 replies
  • Subscribers 388 subscribers
  • Views 1298 views
  • Users 0 members are here
  • frs
  • stepper motor with arduino
  • force sensor
  • arduino
Related

Stepper Motor With FRS

jerrychok
jerrychok over 4 years ago

Hello Everyone,

I'm  here asking for help for my project, what I'm facing now is, is don't know how to make my stepper motor stop in a certain direction, Here is what I want my project to work,

When there is no force detected stepper motor should not move,

when there is force detected the stepper motor should spin in a clockwise direction and stop at a certain step until when the force is removed then the stepper motor will spin in a counter-clockwise direction and stop at a certain step.

 

From now what I manage is, manage to have the force sensor when there is force it will move in a clockwise direction and when the force is removed it will turn counter clock-wise, but it did not stop in a certain direction.

 

Below is my code.

 

#define dirPin 5
#define stepPin 2
#define stepsPerRevolution 1600


int fsrAnalogPin = 0;
int fsrReading;


void setup() {
   // Declare pins as output:
  pinMode(fsrReading, INPUT);

  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);


}

void loop() {
Serial.begin(9600);
fsrReading = analogRead(fsrAnalogPin); 

  Serial.print("Analog reading = ");
  Serial.print(fsrReading);

if(fsrReading > 200){
  digitalWrite(dirPin, LOW);
  // Spin the stepper motor 1 revolution slowly:
  for (int i = 0; i < 500; i++) {
    // These four lines result in 1 step:
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(1000);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(1000);
  }
  delay(2000);
}
else if(fsrReading < 200){
  digitalWrite(dirPin, HIGH);
  // Spin the stepper motor 1 revolution quickly:
  for (int i = 0; i < 500; i++) {
    // These four lines result in 1 step:
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(1000);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(1000);
  }
  delay(2000);
}
}

 

Message was edited by: Christopher Stanton - code formatting

  • Sign in to reply
  • Cancel

Top Replies

  • shabaz
    shabaz over 4 years ago +3
    Hi Jerry, There's a few points: (1) It is hard reading code unless it is formatted correctly using a monospaced font. You can embed code using that row of icons/tools in the online editor, when you created…
Parents
  • amgalbu
    amgalbu over 4 years ago

    Hello Jerry

    loop() is called repeatedly

    This means that your code will do these steps

     

    1. read analog input

    2. make 500 steps

    3. wait 2 seconds

    4. return to point n.1

     

    I expect the motor will never stop unless you add a flag that says you already performed you 500 steps

     

    cheers

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • amgalbu
    amgalbu over 4 years ago

    Hello Jerry

    loop() is called repeatedly

    This means that your code will do these steps

     

    1. read analog input

    2. make 500 steps

    3. wait 2 seconds

    4. return to point n.1

     

    I expect the motor will never stop unless you add a flag that says you already performed you 500 steps

     

    cheers

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube