The following are pictures of the final assembly and projects as well as a video of what Mater does.
The final Arduino code for the motion is also posted.
Here is the final Gist:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Mater the Tow Truck Arduino Project | |
Fianl sketch | |
Purpose of Project: To control three servo motors using two potentiometers and a push button | |
to provide rotation and movement to the members of our | |
tow truck crane arm. | |
*/ | |
#include <Servo.h> // include servo library | |
Servo Paul; // create servo object to control a servo and to name each servo | |
Servo Chris; // create servo object to control a servo and to name each servo | |
int potpin = A0; //analog pin used to connect the potentiometer | |
int potValue; //variable to read the value from the analog pin | |
int potpin2 = A1; //analog pin used to connect the potentiometer | |
int potValue2; //variable to read the value from the analog pin | |
int button1 = 9; //button pin, connect to ground to move servo | |
int press1 = 0; | |
Servo servoWinch; // create servo object to control a servo and to name each servo | |
void setup() | |
{ | |
Chris.attach(8); //attatch Servo Chris to pin 8 | |
Paul.attach(10); //attatch Servo Paul to pin 12 | |
Serial.begin(9600); //begin serial communication to serial monitor | |
pinMode(button1, INPUT); //Set the pin for button1 as an Input state | |
servoWinch.attach(7); //Attatch the winch servo to pin 7 | |
digitalWrite(9, HIGH); //enable pullups to make pin high | |
} | |
void loop() | |
{ | |
potValue = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) | |
potValue = map(potValue, 0, 1023, 20, 150); // scale it to use it with the servo (value between 20 and 150) | |
Paul.write(potValue); // sets the servo position according to the scaled value | |
delay(15); // waits for the servo to get there | |
Serial.println(potValue); // displays potentiometer value to serial monitor | |
potValue2 = analogRead(potpin2); // reads the value of the potentiometer (value between 0 and 1023) | |
potValue2 = map(potValue2, 0, 1023, 20 , 150); // scale it to use it with the servo (value between 20 and 150) | |
Chris.write(potValue2); // sets the servo position according to the scaled value | |
delay(15); // waits for the servo to get there | |
Serial.println(potValue2); // displays potentiometer value to serial monitor | |
press1 = digitalRead(button1); // If button is pressed, Arduino reads the button state | |
if (press1 == LOW) // If button state is Low, moves servo position to 17 degrees | |
{ | |
servoWinch.write(170); | |
} | |
else { | |
servoWinch.write(15); // If button state is high, servo position will move to 15 degrees | |
} | |
} | |
No comments:
Post a Comment