vefindie.blogg.se

Position control of a dc motor arduino
Position control of a dc motor arduino








position control of a dc motor arduino
  1. #POSITION CONTROL OF A DC MOTOR ARDUINO SERIAL#
  2. #POSITION CONTROL OF A DC MOTOR ARDUINO DRIVER#

PCA9685: 12-bit => 0-4095) const int directionPin1 = 10 //digital pin, output, sets the direction const int directionPin2 = 9 //digital pin, output, sets the direction const int standByPin = 6 //STDBY pin, must be active high.

#POSITION CONTROL OF A DC MOTOR ARDUINO DRIVER#

SSD1306AsciiWire oled float OLEDTimer = 0 //Timer for the display refresh interval //I2C pins: //STM32F103C8T6: SDA: PB7 SCL: PB6 //Arduino: SDA: A4 SCL: A5 //- //Input and output pins //Motor encoder const int encoderPin1 = 3 //this pin is also the interrupt pin! const int encoderPin2 = 4 //this pin is a normal pin, read upon the interrupt int encoderPin2Value = 0 //value of the encoder pin (0 or 1), this pin is read inside the interrupt - used for direction determination //- //PWM motor driver const int PWMPin = 11 //this is an analog pin (with the tilde (~) symbol), this pin can also do higher frequency + independent from millis()'s timer int PWMValue = 0 //0-255 PWM value for speed, external PWM boards can go higher (e.g. Serial.# include //This is for i2C # include //i2C OLED # include //i2C OLED # define I2C_ADDRESS 0x3C # define RST_PIN - 1 If(buttonPushCounter1 >= 2) buttonPushCounter1 =0 Serial.print("number of button2 pushes: ") Serial.println(" Type Direction in Box above. If anyone can reference me to some relevant material or shed light on this via their experience or otherwise I would greatly appreciate it. I have been staring at the computer for 12 hours a day since Thursday and maybe it might just take a fresh pair of eyes to help me understand. I have studied the examples and many tutorials which I thought were relevant and have spent hours trawling through the net to find a similar previously asked question to no avail. Ideally, I would like to enter the desired switch-case statement, loop through this switch-case statement until the correct position has been met, stop the motor at this point and return to main loop. My problem is that this set up doesn't allow time for the encoder to reach the desired position before reacting.

#POSITION CONTROL OF A DC MOTOR ARDUINO SERIAL#

Each serial command begins by turning on the motor, reading the the current position of the motor, reacting accordingly (if not at desired position stay on, if at desired position turn off) and then exits the switch-case statement. I am using a switch-case statement to differentiate between the different serial commands. 2,3 = W, 2,4 = NW)įor the purpose of this exercise I will be using 2 push buttons instead of the optical sensors to simulate the position of the encoder and I will also be using LED's to signal the state of the motor (RED = ON, GREEN OFF) (Counter-intuitive, I know), and finally I will be using the serial port to command the desired position (ideally a wind direction sensor will provide the direction but will keep the serial port command control for demonstration purposes). Therefore, a combination of the optical eye readings will give the desired position ( 1,1 = N, 1,2 = NE. The motors output shaft is connected to a 2:1 gear box and then to a compass dial.

position control of a dc motor arduino

One optical sensor will detect the 4 holes and the other optical sensor will detect the nipple. The encoder is concentric with the output shaft of the motor, contains 4 holes about its perimeter and also has a single nipple (for a loss of other words) extruded from its outer edge, parallel with the disk face. I will be using 2 optical sensors and a disk encoder to detect the motor position.

position control of a dc motor arduino

To detect the 8 positions (N, NE, E, SE, S, SW, W, NW) of a DC motor.

position control of a dc motor arduino

I'm studying mechanical engineering so I'm out of my comfort zone at the moment but keen to learn. I started my first ever project on Thursday night.










Position control of a dc motor arduino