If you are new to Arduino, you can get started with Arduino Tutorials for newbie.
How It WorksWhen user access webpage of PHPoC [WiFi] Shield from a web browser on smartphone or PC, a WebSocket connection will be created between Arduino and web browser. WebSocket connection allows to real-time exchange data between web browser and Arduino without reloading webpage.
When user rotates the needle on webpage, the rotated angle will be send to Arduino. Arduino convert angle to the equivalent position (unit is pulse), and then use PID algorithm to rotate DC motor the equivalent position.
PID library for Arduino is available here. It also contains auto-tuning function for both position and speed.
Angle to Position Calculation
Assumption:
- Incremental Encoder Resolution (counts per revolution): ENC_RESOLUTION
- Gear Ratio: GEAR_RATIO
Signal from Encoder will be decoded by DC Motor Controller. DC Motor Controller acts as Quadrature Decoder, which will quadruple (x4) the number of pulses per revolution.
We have:
- a revolution <=> 360 degree <=> ENC_RESOLUTION * GEAR_RATIO * 4
- angle <=> position
=> position = angle * ENC_RESOLUTION * GEAR_RATIO * 4 / 360
The motor I used have:
- ENC_RESOLUTION = 13
- GEAR_RATIO = 100
=> position = angle * 13 * 100 * 4 /360
(see line 68 of Arduino code)
Wiring- Stack PHPoC Shield or PHPoC WiFi Shield on Arduino
- Stack DC motor controller PES-2604 on PHPoC Shield or PHPoC WiFi Shield
- Connect the terminal block of DC motor controller to DC motor and power supply for DC motor as follows:
- Terminal Block - VM <----> (+) wire - power supply for DC motor
- Terminal Block - GND <----> (-) wire - power supply for DC motor
- Terminal Block - M1+ <----> (+) wire - DC motor
- Terminal Block - M1- <----> (-) wire - DC motor
- (Optional) Connect the encoder port of DC motor controller to encoder pin of DC motor as follows:
- Encoder 1 - 5V <----> Vcc - Encoder of DC motor
- Encoder 1 - GND <----> GND - Encoder of DC motor
- Encoder 1 - 1A <----> A phase - Encoder of DC motor
- Encoder 1 - 1B <----> B phase - Encoder of DC motor
- Encoder 1 is located on the upper row of encoder port. More detail is here
Comments