element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • 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
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • 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 Dc motor problem
  • 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
  • State Verified Answer
  • Replies 17 replies
  • Answers 1 answer
  • Subscribers 418 subscribers
  • Views 1892 views
  • Users 0 members are here
Related

Dc motor problem

e14 Contributor
e14 Contributor over 12 years ago

Hi all just started with programming an Arduino UNO - I have no previous programming background!!

 

I started with Evil Genius book and I want to make a table feed for my milling machine, but right now im just experimenting with dc motor control.

 

What I have set up is a H Bridge (HMD-02)  2 buttons and 2 potentiometers and 1 dc motor

What i want it to do is 1 Nothing until I press 1 button then Turn forward at speed set by pot 1  , stop when i let go of button and turn backward at speed set by pot 2 when I press button 2???

 

MY sketch starts the motor running as soon as I compile and I cant find the problem??????

 

Please any help??

Many thanks.

Attachments:
dc_motor1.ino.zip
  • Sign in to reply
  • Cancel
Parents
  • e14 Contributor
    0 e14 Contributor over 12 years ago

    It would be helpful if you posted your Arduino sketch.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • e14 Contributor
    0 e14 Contributor over 12 years ago in reply to e14 Contributor

    Hi I tried to attach it as a file!! Copy and paste did not work!

    What is the best way??

     

    Gerhard

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • e14 Contributor
    0 e14 Contributor over 12 years ago in reply to e14 Contributor

    /*

    * dc moto with h-bridge and 2 potentiometers and 2 buttons

    * 1 button for forward at speed set by pot 1

    * 2 button for bacward at speed set by pot 2

    */



    int pot1 = 0;          // potentiometer to pin A0

    int pot2 = 1;          // potentiometer to pin A1

    int enable = 11;       // to enable on h bridge

    int motorPin1 = 9;     // to In1 on h bridge

    int motorPin2 = 10;    // to In2 on h bride

    int redBut = 12;       // button to 12 pull-down

    int greenBut =13;      // button to 13 pull-down





    void setup()                    // run once, when the sketch starts

    {

      Serial.begin(9600);           // set up Serial library at 9600 bps

      pinMode(pot1, INPUT);       

      pinMode(pot2,INPUT);

      pinMode(enable, OUTPUT);

      pinMode(motorPin1, OUTPUT);

      pinMode(motorPin2, OUTPUT);

      pinMode(greenBut , INPUT);

      pinMode(redBut , INPUT);

      digitalWrite (motorPin1 , LOW);

      digitalWrite (motorPin2 ,LOW);

      digitalWrite(enable ,LOW);

    }



    int getPot1() {

      int v;

      v = analogRead(pot1);

      v /= 4;

      v = max(v, 90);

      v = min(v, 255);

      return v;

    }





    int getPot2() {

      int w;

      w = analogRead(pot2);

      w /= 4;

      w = max(w, 90);

      w = min(w, 255);

      return w;

    }



    int motorFoward() {

      analogWrite(motorPin1, getPot1());

    digitalWrite(enable,HIGH);

    digitalWrite(motorPin2,LOW);

    }



    int motorBackward() {

      analogWrite(motorPin2, getPot2());

      digitalWrite(enable,HIGH);

      digitalWrite(motorPin1,LOW);

    }



    int allStop(){

      digitalWrite (motorPin1 , LOW);

      digitalWrite(motorPin2 , LOW);

      digitalWrite(enable ,LOW);

    }





    void loop()                     // run over and over again

    {

      if (greenBut = HIGH){

      motorFoward();}


      else if (redBut = HIGH){

      motorBackward();}


      else{

      allStop();}

    }





    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • e14 Contributor
    0 e14 Contributor over 12 years ago in reply to e14 Contributor

    Don't have time to look through it at the moment, but to post it just add <code>....</code> within the html editor.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • e14 Contributor
    0 e14 Contributor over 12 years ago in reply to e14 Contributor

    Don't have time to look through it at the moment, but to post it just add <code>....</code> within the html editor.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • 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 © 2026 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.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube