Last active
October 10, 2019 23:44
-
-
Save KyleMartinTech/ea7392d1001902f369def134c4bfaa5d to your computer and use it in GitHub Desktop.
DIY Timelapse Cart
This file contains hidden or 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
/* | |
This is the code for a video I (kyle martin tech) did on how to make a | |
DIY GoPro Time Lapse Dolly. That video can be found here: https://youtu.be/KywjUrnVIWY | |
I have also created a video walk through of this code which can | |
be found here: https://youtu.be/F8oxyoFxaS8 | |
The parts used in this project are | |
Arduino Nano: | |
Buy: http://geni.us/iBNl | |
Data Sheet: https://store.arduino.cc/usa/arduino-nano | |
Pololu VNH5019 motor driver: | |
Buy: http://geni.us/AG9E | |
Data Sheet: https://www.pololu.com/product/1451 | |
I think you could use a product like this: http://geni.us/ZaVOAHO in place of | |
the motor driver I used as it would be a way cheaper way to go. However, I have | |
not tried it so you may have to change the code a little bit. | |
4W drive robot base: | |
Canada: http://amzn.to/2FpEXEH | |
USA: http://amzn.to/2oXALBF | |
Electronic components needed | |
10KΩ Resistor: http://geni.us/iiQzu | |
500Ω Resistor : http://geni.us/iiQzu | |
10KΩ Potentiometer: http://geni.us/PAQqY | |
Momentary switch: http://geni.us/ftRfDFk | |
LED: http://geni.us/ZKHeHy | |
Perfboard: http://geni.us/m9S5M | |
Power switch: http://geni.us/51TIXdr | |
battery holder: http://geni.us/9yQvWB | |
Hook up wire: http://geni.us/1KABm | |
Tools you will need | |
Soldering Iron: http://geni.us/tA8R | |
Helping hands: http://geni.us/lRIGR | |
Side cutter: http://geni.us/tABXxIc | |
Wire stripers: http://geni.us/BETSCkf (Get red for stranded and yellow for solid) | |
*/ | |
//#include <Arduino.h> | |
const int speedInput = A1; // this is the pin the output of the pot will connect to | |
const int PWM = 5; //these names correspond to the names used by the data sheet for the VNH5019 Motor Driver Carrier made by Pololu | |
const int INA = 6; | |
const int INB = 4; | |
const int button = 7; // This is the pin our switch is connected to. The voltage is held low by a 10kΩ pull down resistor | |
const int LED = 9; // The indicator LED is connected to this pin via a 500Ω resistor | |
int readValue = 0; //this is where the value read from the pot will be stored | |
int writeValue = 0; //as the analog input can have 1023 values while the output can have 255 we must map the imput value to an output value | |
int buttonState = 0; // this will record if the button has been pressed or not | |
int count = 0; // This is a count used in a loop later | |
int PWMSpeed = 0; //this is the speed the motor is driven at | |
void setup() { //in void set up we will assign the different pins as inputs or outputs | |
pinMode (speedInput, INPUT); | |
pinMode (PWM, OUTPUT); | |
pinMode (INA, OUTPUT); | |
pinMode (INB, OUTPUT); | |
pinMode (button, INPUT); | |
pinMode (LED, OUTPUT); | |
} | |
void loop() { //this is the part of the program which will run forever | |
//this first if statement is just to check if the button has been pressed | |
if (digitalRead(button) == HIGH) { //if the button has been pressed the program will change the button state from 1 to 0 or 0 to 1 | |
if (buttonState == 1) { | |
buttonState = 0; | |
} else if (buttonState == 0) { | |
buttonState = 1; | |
} | |
while (digitalRead(button) == HIGH) { //this while loop will only run if the button was pressed and is here to hold the program from continuing until the button is released. | |
delay (10); | |
} | |
} //this is the end of our first if statement | |
digitalWrite(INA, HIGH); //These next to lines are just to set the direction of the motor. If you swap them the cart will go the other way. | |
digitalWrite(INB, LOW); | |
readValue = analogRead(speedInput); //we find out the value of the pot and store it as read value | |
if (buttonState == 0) { //this is the second if statement and is the split between continues and intrementent | |
digitalWrite(LED, LOW); //turn off the LED so we know we are in continuous mode | |
writeValue = map(readValue, 0, 1023, 0, 255); //map the input to the output | |
analogWrite(PWM, writeValue); //write that value and send it to the motor driver | |
delay(50); // short delay to stop the program for tripping over its self | |
} else { //that is the end of the continuous program, at this time the program will loop back to the start of void loop | |
//if interment mode was selected the first part will be skipped and the program will pick up here after storing the value from the pot | |
digitalWrite(LED, HIGH); // turn the LED on to let us know intermittent mode is active | |
writeValue = map(readValue, 0, 1023, 0, 10000); //map the input value to output, instead of speed this time it is a time value | |
while (PWMSpeed < 80) { //This while loop is a speed ramp it stops the cart from bouncing too much when the motors start and stop. The number shown is the max speed the dart will reach. | |
analogWrite(PWM, PWMSpeed); | |
delay(1); // this is the speed of acceleration 1 fast and 10 would be slow | |
PWMSpeed = PWMSpeed + 2; //this is even more control over the speed of accelerations 1 is slow and 10 would be super fast. | |
} | |
delay (0); //how long the cart stays at speed after it has accelerated | |
while (PWMSpeed > 0) { //the same as the accelerations while loop but just for deceleration | |
analogWrite(PWM, PWMSpeed); | |
delay(1); | |
PWMSpeed = PWMSpeed - 2; | |
} | |
analogWrite(PWM, 0); // it is not clear what the power level will be when the while loops is exited so we play it safe and turn the motors off | |
while (digitalRead(button) == LOW && count < writeValue) { //this is the while loop that controls the delay between bursts, it will be exited when it reaches the time set by the pot or when the button is pressed. | |
delay (1); | |
count++; //count is how long the loop has been running for is tracked | |
} | |
count = 0; //reset the count so we are ready to go on the next pass | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment