To rotate one, or a series of servo motors using one, or a series of potentiometers. To also output the position of the servos using 4 LEDs
Equipment:
- Arduino x1
- Breadboard x1
- Pushbutton x 6
- Servo x 6
- 330 ohm resistor x4
- LED x4
- Wires
References:
Program Details:
Building the circuit is not very complex. We built similar circuits like this before [2][3]. Also a picture of the circuit was provided [1]. Essentially this CIRC lab consists of 6 separate circuits, with 1 input and 5 output. The input is the resistnace reading from the potentiometer. The output is
Program:
//PART 1
#include <Servo.h>
Servo servo;
int pos = 0;
int sensor = 0;
void setup()
{
servo.attach(13);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
}
void loop()
{
int value = analogRead(sensor);
value = map(value, 0, 1024, 0, 360);
value = constrain(value, 0, 360); //Sets value between 0 & 360
delay(50);
servo.write(value); //Sets to desired position
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW); //Turns them off every time, to prevent stacking
if (value == 0)
{
digitalWrite(2, HIGH);
}
else if (value == 90)
{
digitalWrite(3, HIGH);
}
else if (value == 180)
{
digitalWrite(4, HIGH);
}
else if (value == 270)
{
digitalWrite(5, HIGH);
}
}
//Part 2
#include <Servo.h>
Servo rotator, joint1, joint2, joint3, wrist, gripper;
int sensorR = 0, sensorJ1 = 1, sensorJ2 = 2, sensorJ3 = 3, sensorW = 4, sensor = 5;
int valueR, valueJ1, valueJ2, valueJ3, valueW, valueG;
void setup()
{
rotator.write(13);
joint1.write(12);
joint2.write(11);
joint3.write(10);
wrist.write(9);
gripper.write(8);
}
void loop()
{
delay(50);
//Rotator
valueR = analogRead(sensorR);
valueR = map(valueR, 0, 1024, 0, 360);
valueR = constrain(valueR, 0, 360); //Sets value between 0 & 360
rotator.write(valueR);
//Joint One
valueJ1 = analogRead(sensorJ1);
valueJ1 = map(valueJ1, 0, 1024, 0, 360);
valueJ1 = constrain(valueJ1, 0, 360);
joint1.write(valueJ1);
//Joint Two
valueJ2 = analogRead(sensorJ2);
valueJ2 = map(valueJ2, 0, 1024, 0, 360);
valueJ2 = constrain(valueJ2, 0, 360);
joint2.write(valueJ2);
//Joint Three
valueJ3 = analogRead(sensorJ3);
valueJ3 = map(valueJ3, 0, 1024, 0, 360);
valueJ3 = constrain(valueJ3, 0, 360);
joint3.write(valueJ3);
//Wrist
valueW = analogRead(sensorW);
valueW = map(valueW, 0, 1024, 0, 360);
valueW = constrain(valueW, 0, 360);
wrist.write(valueW);
//Gripper
valueG = analogRead(sensorG);
valueG = map(valueG, 0, 1024, 0, 360);
valueG = constrain(valueG, 0, 360); //Sets value between 0 & 360
gripper.write(valueG);
}
No comments:
Post a Comment