Presentation is loading. Please wait.

Presentation is loading. Please wait.

Servos and Stepper Motors

Similar presentations


Presentation on theme: "Servos and Stepper Motors"— Presentation transcript:

1 Servos and Stepper Motors
CS-4540 Robotics - Lab 05 Servos and Stepper Motors

2 Including this as a handy reference for the lab

3 Revisiting the “Connecting a switch to an I/O pin lab” sample software
This is an example of the bad code from last lab. DO NOT USE. It was copy-pasted from a web page and contains hidden ‘non breaking’ spaces which do not compile when posted into the Arduino IDE. Only use this to practice finding code breaking characters. //sample switch code const int buttonPin = 4; const int ledPin =  8; int buttonState = 0; void setup() { pinMode(ledPin, OUTPUT); pinMode(buttonPin, INPUT); } void loop() {   buttonState = digitalRead(buttonPin);   if (buttonState == HIGH) {     digitalWrite(ledPin, HIGH); } else {     digitalWrite(ledPin, LOW);

4 Finding hidden characters in the text file Using Notepad++

5 Finding hidden characters in the text file Using Notepad++
OUCH!

6 Small stepper motor with driver electronics
Small stepper motor with driver electronics The driver board acts as an amplifier so that the low current signal output from the Arduino can be converted to the high power high current required to drive the motor.

7 Stepper motor driver code
*** Sample of the code *** /*    BYJ48 Stepper motor code    Connect :    IN1 >> D8    IN2 >> D9    IN3 >> D10    IN4 >> D11    VCC ... 5V Prefer to use external 5V Source    Gnd    written By :Mohannad Rawashdeh         28/9/2013   */ #define IN1  8 #define IN2  9 #define IN3  10 #define IN4  11 int Steps = 0; boolean Direction = true;// gre unsigned long last_time; unsigned long currentMillis ; int steps_left=4095; long time; void setup() { Serial.begin(115200); pinMode(IN1, OUTPUT);  pinMode(IN2, OUTPUT);  pinMode(IN3, OUTPUT);  pinMode(IN4, OUTPUT);  // delay(1000); } void loop() { *** see actual code in CSNS resources text file *** Stepper Driver Code for 4096 steps/revolution motor Using the code from this instructable because it works better with the motors we have, which are 4096 steps/revolution steppers.

8 Wiring up the stepper and drive circuit
Negative side of the power supply connects to this pin Positive side of the power supply connects to this pin

9 Stepper wiring pictorial

10 PWM Servos http://www.instructables.com/id/Arduino-Servo-Motors/
Black or Brown wire The servos we are using are small enough that the Arduino can provide enough power to safely run them. Larger more powerful Servos would require a separate power supply the same as we used on the stepper.

11 Using the built-in servo library and example code

12 Lab assignment Setup and run a stepper motor demo program.
Hold and stop the Stepper for a brief moment while running – does it return to it’s original start point? Or has it forgotten where it is. See how fast you can get the stepper to turn one complete revolution. Setup and run the servo motor demo program. Hold and stop the Servo for a brief moment while running – does it return to it’s original start point? Or has it forgotten where it is. See how fast you can get the Servo to turn all the way one direction and return. Start thinking about how you would hook 2 steppers or Servos to the Arduino and program it to draw a square using the 2-arm pen potter.

13 References http://www.instructables.com/id/Arduino-Servo-Motors/
h=90365 Arduino/


Download ppt "Servos and Stepper Motors"

Similar presentations


Ads by Google