Code Monkey home page Code Monkey logo

servomotor's Introduction

ServoMotor

The purpose of this library is to create a custom servo motor. To use it you will need:

  • An H-bridge
  • A DC motor that can be reversed by flipping the voltage across it.
  • An analog sensor that can measure the position of the motor.

You will also need a single analog pin and two pins capable of pwm output. See this page to find out what pwm pins are available on your arduino board:

Wiring

Each of the components must be connected in the following way:

  • The motor leads connect to the H-bridge.
  • The H-bridge input pins are connected to the chosen pwm pins of the arduino.
  • The sensor is connected to the chosen analog pin of the arduino.

The schematic below provides an example for the required conections:

picture

Usage

The available functions are:

  • initialize(): sets the input and output pins and calibrates the servo.
  • readSensor(): returns the unfiltered sensor signal.
  • setPosition(int): sets the target position of the servo.

Note that the library uses analogRead() to measure the sensor. As such, the entire range of motion will be divided to 1024 individual steps. For a 180 degree rotation this means a maximum precision of 180/1024 ~ 0.18 degrees.

The motion of the servo is controlled via a PID loop. The associated coefficients are set when a sketch is compiled and cannot be changed once the arduino is running.

References

The library uses an alpha-beta filter to smoothen and differentiate the signal from the analog sensor.

servomotor's People

Contributors

rcmags avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.