Это видео недоступно.
Сожалеем об этом.
Arduino Tutorial 39: Using a Joystick to Control DC Motor Speed and Direction
HTML-код
- Опубликовано: 17 авг 2024
- You guys can help me out over at Patreon, and that will help me keep my gear updated, and help me keep this quality content coming:
/ paulmcwhorter
You guys can help me out over at Patreon, and that will help me keep my gear updated, and help me keep this quality content coming:
/ paulmcwhorter
In this video we show how to control a DC motor using a joystick. The example shows you can control both speed and direction. We use the L293d motor controller and a small DC motor.
You can get the kit I am using for this series at the following link:
amzn.to/2I7N4Ek
Follow these lessons for FREE on our WEB site:
toptechboy.com...
[Disclosure of Material Connection: I am a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com. This means if you visit the link and purchase the item, I will receive an affiliate commission. Regardless, I only recommend products or services I use personally and believe will add value to my readers.]
#Arduino
i dont know why i find it so amusing when he says "BOOOM". Good video!
And giddy up! Lol
"I want everyone to hold your breath, BOOOM!"
Geeks version of when a good chef says *Bamm!*
I'm so grateful to you for making these videos. You're one of the few gems on RUclips who goes over the science behind different components without directly jumping into writing code or building the circuit. Thank you for making these videos.
Watched the whole thing but did it on my own before watching the video. I had a bit of variability on the home position so I needed a range for the zero speeds. I always seem to over complicate things and then I watch you and you make it so much simpler. Thanks again.
I was discussing this homework with my wife in the car (I'm sure she was thrilled) and just talking through how I thought the graph would have to look. I admit that I wasn't able to do the whole thing on my own, but was super excited when Paul drew the graph exactly how I had described what I thought it would look like to my wife. Three weeks ago I wouldn't have had a clue what any of this meant...thanks Paul!
Hey Paul, I was able to do this on my own thanks to your incredible videos and teaching skills. Doing it on my own was very rewarding and the only thing I did differently to you was use a quadratic equation for mSpeed where 511.5 was the x value of the turning point (halfway between 0 and 1023). I also incorporated the use of the switch on the joystick, where if the switch is pressed (swVal=1) the motor stops running no matter what the jVal is. Thank you so much for your videos Paul!
How can we do that? I def wish Paul would have gone over quadratic equations as this is an amazing example.
Here is a bit of an advice for anyone doing this in the future. In the motor which comes with the kit, there is a metal pin inside (which is called a shaft I believe), that goes through the whole motor. On one side of said pin we put the fan blade (aka the propeller thingy), but the other side is sticking out a bit from the rare (bottom) side of the motor. Since this is not an extremely strong motor (you can easily stop it with your finger without having to be afraid to get hurt), if the bottom portion of the pin is touching any surface, it may slow down or even prevent the motor from spinning the fan blade (depending on how you fixed the motor on your workbench or desk). I couldn't start the fan with mSpeed of 100 before I lifted the motor up and fixed it in a position where the pin wouldn't touch any surface, then I could do 100 and even 90.
I'm 81 and have played with arduino a lot and watch all your videos to the end so I don't miss anything. I'm a retired tool and die maker and love electronics as much as you do. I worked with mechanical engineers making changes to a production line so I got to see first hand what was done. Keep up the great series as you do it well. I lole the way you can set all the views to show the circuit, the code or the outputs on screen as you need them. I bet it took you a while to figure that all out.
😊
I struggled with this one and got my slope/point slope equations wrong at first. Then I realized one slope was negative and the other was positive. idle (zero motor speed) joystick value for me was 505 so i used two different slopes . It was straight forward after that. Thank you Paul for this practical usage of mathematics.
I just got an arduino and you have been so helpful, thank you for making this learning experience as easy and as informal as possible. thank you!
Great to hear!
I did this one on my own. I figured out the math but was having trouble with it working on the circuit. I finally remembered to use float for my speed value and it worked perfectly. I even added a servo on the other axis for extra credit. I am excited about what I am learning and grateful for the effort you have put into these tutorials. Very much appreciated.
I did it on my own, because I watched and worked every lesson until this one, thank you so much Paul.
As always another great lesson. I did the maths but used three if statements so that there was a 'dead zone' in the middle. (On my joy stick from 500 to 510 where the motor had mSpeed of 0). As the motor does not turn less than mSpeed of 90, the mSpeed went from 90 to 255 in both directions to give a larger range on the joystick
I have had my arduino for years and have used it for many projects. When I purchased it I also purchased a box of ribbon cables. Up until yesterday, I never realized that they were put out by elegoo. Very nice set of cables, they have served me well!!
"BOOM!! " I did it the same way you did and your way of teaching is wonderful.
I'm so grateful that I made this project myself. All Thanks to You. You are such a great Teacher.
Nobody on the internet teaches like u.
I was not able to do this one on my own. I haven't been able to do any of these on my own, but I am getting a much better understanding on how this works. I am determined to get one of these assignments done on my own before the end of the series.
Hi Paul, I was able to do this on my own. The difference is that my xValue in neutral position is 532. So the 2 slope equations look quite different. But it works pretty well. I got lot of fun.
I didn't do this lesson beforehand -- I had to follow along, but everything made perfect sense to me!
I was able to do it by myself. Followed your examples from previous lessons. Did the math. Used "if" statements. It worked. Fun as always.
Did lesson 39 myself! My line slope did not use zero for output, but the 100 we know is minimum needed to start motor. Also used a dead band for neutral pos.
Thanks Paul, great Project.
Did it on my own, did the exact same way as you did sir.
But i find it more natural to turn the motor on before setting the direction although virtually it doesn't make any difference as the arduino reads the lines of code very very very fast.
Thank you for this lesson Sir Paul!
Hi Paul, I was able to complete the homework on my own. The only difference is I accounted for the value needed to start my motor, so my Y values on my graph went from 140 to 255. That is for these lessons they are great.
Yes i was able to make my homework,in almost the same way,with a good result.
I had some minor dificulties:
the "middle point" of my yVal was not right in the middle and istable variing between 509,510 and 511,
so I decided craeted a "flat"zone between 508 and 513 where the speed should be =0
so I used 3" if "situations :if (Xval >= 0 && Xval = 505 && Xval speed= 0 and also (dir,LOW and dir2,LOW)
if (Xval >= 513&& Xval speed accellerating from 0 to255
Honestly, I had it difficult to find the good working math formula,
I was really on the right way, but I was not focussed enough to solve the problem ( althoug it is easy,when you have a clear mind!).
Sorry, I used the map-funtion, to reach a good result
i tried to do this lesson on my own as homework, however i made a small math error and my motor ended up fast in the middle position and off at either extreme of the joystick, i ended up watching through this video with you to walk through my math to find my errors, thanks for a great learning experience!
Great Lesson. I was able to do this one. I made an "off range" so that a small movement from center didn't trigger a start in either direction, Other than that my code matched yours. Thanks!
Dear sir.
Thank you VERY much for this content and all the hard work you’re putting into this channel. You are indeed amazing. Your way of teaching is something that should be implemented in schools.
You remind me of my high school physics teacher, Mr Norton. Edward Norton if I remember correctly. This was about 20 years ago and I still remember his hands-on method, he had US doing stuff and analyzing things, rather than just explaining it and hoping something settles in our teenage brains.
Thank you and prosperity unto you and yours.
May your coffee always be strong and your mug full.
Hi, Paul, I was able to do this on my own, but it took me a long time to properly work through the math. I had to output my speed values to the serial monitor to see that my equations needed adjustment, and then went back and forth until I got it right. I just wasn't being precise enough when gradually plugging the numbers in and doing the equations one by one with actual point values in order to get the final equations right. I also have a joystick whose centerpoint Y is at 504, so I had to be using 519 in the equations to make everything work right. I'm actually glad that was the case because it made me learn better about plugging in the right numbers in the right places. ... but I got it done on my own and then watched lesson 39. Enough for tonight, I think! Thanks, as always.
Incredible lesson sir....I am from India and become your student in your zone.....eagerly waiting for your next lesson... Tuesday at 9:30 pm in India...
I did this one on my own and dear lord I feel like a rock star! My method was different but not far off in the results as it still accomplished the exact same thing. Here's what I did:
I started by hooking up the joystick and used my code from the projects in previous lessons like the servo arm to save time. Then, I plugged in the equation for the servo arm and modified it to divide the max motor speed by the max joystick setting instead, wrote the IF statements, and booted up the program. Just like I expected, the motor would move faster and slower in reverse the more I pulled the joystick down, however, I needed to fix the problem with going forward as I just plugged in (255./1023.)*Jval for motor speed. After only 30 seconds of looking at the problem I remembered the existence of Absolute Values which is basically the distance on a number line from zero. After about 45 minutes of trial and error, I finally came up with the absolute value function: F(x) = |x-510| where x = (510/1023)*Jval. After that I simply added one more variable that was equal to (255./1023.)*Jval to use as a compass to trigger the IF statements and used my absolute value function for the actual speed and EURIKA. In hindsight, I could've used x in the IF statements instead of making a new variable just for the IF statements but now I'm too lazy to optimize it more. All in all, this was one of the most fun circuitry projects I've done on my own so far, I highly appreciate your work as a teacher Paul. p.s. down with Ice Tea and Coffee and up with the most excellent cup of Ice Cold Water!😆
GIDDY-UP ! it worked a treat ! (all on my lonesome). I made life more complicated, as I used the start point of the motor offset to 75. Also, for some reason, my centered stick was spewing out random variations around 512. So I also did a 'dead-zone' IF band-width in the middle that kept the motor shut down when stick released, stopping the motor from 'wining'. Your way of starting from '0' instead of 75 seems to do this, when I later tried your better method. I also shared the ground & 5v off the breadboard for the J-stick, thinking that was a 'must'. Great Video, Thank you Paul .... uk
This lesson was really interesting and informative, thank you.
i really enjoyed the math of the 2 slopes as it showed how far i have come, as i really struggled with the slope math in previous lessons, but followed it this time much more competently.
many thanks from the UK.
You're very welcome!
Thanks for the tutorial. I was able to make it on my own, although with a few modifications: Instead of plugging the formula with numbers, I put the slope-point formula with variables such as x1, x2, y1, y2, and then, when declaring those variables, I could define (and then modify if I want) the range of the joystick or the motor without changing the formula...
Other modification is that in each formula, I defined the x-value of an endpoint to centerVal + tolerance or centerVal - tolerance, such that there is a dead zone to the left and right of centerVal (the neutral position of the joystick) where the motor is off.
Code:
//y-axis and joystick switch are unused.
const int xPin = A0;
//const int yPin = A1;
//const int switchPin = 6;
const int motorPin = 7;
const int dir1Pin = 8;
const int dir2Pin = 9;
//Constants for both linear functions:
const float centerVal = 505; //In my case, the neutral value of the x-axis is 505
const float tolerance = 3;
const float x1 = centerVal + tolerance;
const float x2 = 1023;
const float y1 = 0;
const float y2 = 255;
const float x3 = centerVal - tolerance;
const float x4 = 0;
const float y3 = 0;
const float y4 = 255;
float xVal;
//float yVal;
bool switchState;
bool dir1 = 0;
bool dir2 = 1;
float motorSpeed;
void setup() {
pinMode(xPin, INPUT);
//pinMode(yPin, INPUT);
//pinMode(switchPin, INPUT_PULLUP);
pinMode(motorPin, OUTPUT);
pinMode(dir1Pin, OUTPUT);
pinMode(dir2Pin, OUTPUT);
Serial.begin(9600);
}
void loop() {
xVal = analogRead(xPin);
if (xVal > x1)
{
dir1 = 1;
dir2 = 0;
motorSpeed = ((y2 - y1) / (x2 - x1)) * (xVal - x1) + y1;
}
else if (xVal < x3)
{
dir1 = 0;
dir2 = 1;
motorSpeed = ((y4 - y3) / (x4 - x3)) * (xVal - x3) + y3;
}
else
{
motorSpeed = 0;
dir1 = 0;
dir2 = 0;
}
analogWrite(motorPin, motorSpeed);
digitalWrite(dir1Pin, dir1);
digitalWrite(dir2Pin, dir2);
Serial.print(xVal);
Serial.print(" ");
Serial.println(motorSpeed);
}
I was able to do this project on my own! My code was almost exactly the same, except that I forgot to include the equals sign in one of the conditional statements. Adding that equal sign makes the motor run more smoothly. I'm proud that I was able to figure it out! Thanks alot Paul!
It took me some time to understand that I couldn't plug the joystick into the rail because the voltage drops when the motor switches on. But when I realised that (and redid my equations :-)) everything worked! Another great lesson, thank you!
Thank you very much, Mr. McWhorter, for this amazing tutorial please do not stop teaching.
I was able to do it on my own mostly the same way but I coded 3 if statements not 2 as such:
my middle value for the joystick was 525.
1st If statement "if (yVal >520 && yVal
I couldn't find a motor controller yet, but I managed to get the math and the code ready on my own and some confirmation from our most excellent teacher by watching the video to make sure I did the calculations correct.😀
I used 3 conditions for my fan. My joystick's neutral read value is 496 so I made that the 'off' position. I then used two separate linear equations for the forward and reverse directions based off of the independent read value and the dependent min/max motor speed of 100-255. The forward directional speed was calculated using the read value of the joystick from 0 to 495, and the reverse directional motor speed value was calculated with the read values from 497 to 1023. I also factored in the initial kickstart speed at the beginning of the motor 'on' cycle for both directions, and then put the analog read command into a while loop that only executes while the condition is true. Thanks so much Paul for teaching us! *SPOILER!! Here's my code!* 😌
int speedPin = 11; // Motor controller pin 1 (speed pin)
int dirPin1 = 8; // Motor controller pin 2 (direction)
int dirPin2 = 7; // Motor controller pin 7 (direction)
int mSpeed1; // Motor Forward Directional Speed
int mSpeed2; // Motor Reverse Directional Speed
int mSpeed3 = 0; // Motor Stop
int yPin = A2; // Joystick pin
int readVal; // Joystick sensor value
int dt = 50; // Delay
void setup() {
// put your setup code here, to run once:
pinMode(speedPin,OUTPUT);
pinMode(dirPin1,OUTPUT);
pinMode(dirPin2,OUTPUT);
pinMode(yPin,INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
readVal = analogRead(yPin);
if (readVal > 495 && readVal < 497) { // Stop Motor
analogWrite(speedPin,mSpeed3);
Serial.println(readVal);
}
if (readVal >= 0 && readVal < 495) { // Forward Motor Rotation
digitalWrite(dirPin1, LOW);
digitalWrite(dirPin2, HIGH);
analogWrite(speedPin,255);
delay(dt);
while (readVal >= 0 && readVal < 495) { // Joystick input speed
readVal = analogRead(yPin);
mSpeed1 = (155./-495.) * (readVal - 495.) + 100.;
Serial.print("Read Value: ");
Serial.print(readVal);
Serial.print(" Fan Speed: ");
Serial.println(mSpeed1);
analogWrite(speedPin,mSpeed1);
}
}
if (readVal 497) { // Reverse Motor Rotation
digitalWrite(dirPin1, HIGH);
digitalWrite(dirPin2, LOW);
analogWrite(speedPin,255); // Kickstart motor
delay(dt);
while (readVal 497) { // Joystick input speed
readVal = analogRead(yPin);
mSpeed2 = (155./526.) * (readVal - 497.) + 100.;
Serial.print("Read Value: ");
Serial.print(readVal);
Serial.print(" Fan Speed: ");
Serial.println(mSpeed2);
analogWrite(speedPin,mSpeed2);
}
}
}
I was able to complete the homework very similar to your version. Math is your friend. Like you said, as soon as I drew the graph it became very simple. I printed the speed and joystick position and it was very smooth. Thanks for videos.
Good Lesson. I had slightly different logic ,but, fundamentally the same. Past lesson flow makes it simple. Thank you !
The secret word? i watched till the end though. I couldnt do it myself. This is the most useful channel ever!
I was able to do this one on my own but my coding was a bit more jumbled and overly complex. Instead of going from 0-255 on the sweep in either direction, I had mine go 100-255 since the fan won't run reliably below 100. Good stuff! I've been learning a lot from these videos and having a very good time doing so. I've always been fascinated by numbers and very much appreciate that you break it down and show the math involved.
Yes, I did the same, starting from 75. This fellow is fabulous isn't he .... uk
I got this to work, incorporated the emergency tilt switch as per the previous lesson, and used the joystick button as a motor 'boost' to help get it started. Another neat little project.
I did the project on my own. The difference was I did it using x as the independent variable, not Y, but the equations were virtually the same. Good lesson and its applications should be many. Thanks for another terrific video.
I really enjoy (and appreciate) your videos, Paul. Thank you for putting them together. I love how your lessons have built upon each other, and how you incorporate past lessons (review) into new ideas. I also appreciate that you explain the math and concepts in great depth. Although, I do have to confess - I now "cheat" and use the map function for simplicity :)
map function to the rescue! While I do agree that learning the math is important, the map function allows you to EASILY make changes should you need to scale it slightly differently if needed based on hardware.
Couldn't get it working on my own... added a decimal to the last constant of B (from y=mx+b) in both equations and it worked. Man, those trailing decimals sure are important in this language!
Great lesson. I had problems doing the maths so I made it work with the build in function. Even with your explanations of this lesson it took me a while to understand it. I am probably a bit older than you are but I enjoy every lesson you post. Now lets do the homework and looking forward to the next lesson.
Boom. I am proud and lucky to have a teacher like you. You are just a majic. Thank you.
I did the homework and after 39 Tutorials, coding it was not hard at all. Thank you Paul, for all your hard work making the Tutorials. Only 29 more Tutorials to go..................
Heey! I did my homework, but used the lazy method: I set the direction by comparing jVal with the mid value (512). Then, I set the speed with this formula: mSpeed = 255./512. * abs(jVal-512) (it works for all values of jVal).
Only thing is... I think there's something wrong with my L293D... The first time the motor was only moving in one direction. After half hour of trying everything, it just randomly started running both ways (the wiring, pins, code were the same). Oh well. Miracles do happen :))
Thank you for the lesson, sir! Your math was more elegant than mine. Your method works for all cases and I'm very grateful for learning it here.
This was the first video of yours I watched. I already had an Elegoo Uno kit and had my L293D chip wired on to my prototyping board and wanted to figure out how to control a motor with the analog joystick. Just watched this video and followed along, my neutral position was 517 but using the code and formula was able to get mine up and running in no time at all! Thanks for this video! Subscribed!
You are a wonderful teacher makes hi-tech things so lucid
Homework done. With linear function calculation etc. That worked. It also works with the map() function which a bit of cheating. It basically maps the x values to y values without the formula. Great stuff Paul !
Hi, thank you for these lessons, I really enjoy them. I have done the assignment on my own, but slighltly differently from you. I created a neutral zone at the middle position of the joystick (from 500 to 510, as mine settled at ~505) to make sure there is no current sent to the motor. Also I have done the math with the lowest motor speed value to be 100, so I gain finer speed control over the travel of the joystick. So my code ended up having 3 if statements. I have to admit that your code with the equal slopes is much more elegant, but mine works too. Thanks again for these lessons.
I was able to work through the basics of this even up to figuring out I needed two different equations, so I felt pretty good about that, but it fell apart pretty quickly in the coding. I was trying to way over complicate it in ways I can't even explain any more. In the end I had to follow along to sort out where I went wrong. The actual solution was so much simpler than I had it figured. I've got to say, having a guide for this stuff makes it same so simple, but whoever was the first person to ever figure some of this stuff out must've been an absolute diabolical genius! I don't hold out much hope that I will get this next homework assignment on my own but here we go...
I made the math and stuff, but wasn't going well with this project... I had to watch this video to check what I did wrong, feeling myself defeated while hitting that play button... Turns out my math was ok, but forgot my decimals in both equations, that's why couldn't make it work at first attempt, now I don't feel myself defeated anymore, but the feeling is kinda sweet & sour at the moment hehe... I'll never forget writing my decimals again in my equations. Thanks for doing this Paul!, can't wait to start working on your more recent series.
Wow. Another great vid. I am going to try to do your tutorials from the start. Your quality is worth a patreon its better the other online learning sites.Thank you
Another great project. You have fun project ideas. Makes this feel like play instead of work. I really like using the joystick.
I did the homework right after the last video, and got everything working correctly on my first attempt! The only major difference in my code was that I made a positive motor speed and negative motor speed, because I didn't realize I could set motspeed with different formulas based on whether it was positive or negative. I also had the serial monitor print out the speed and joystick value. Thanks for the lesson!
Excellent!
I did my homeowrk perfect! And also used the SW of the joystic to open or close a LED, you are an awesome teacher!
Thanks Paul. DId this one on my own. Had problems with obtaining finer precision of the motor speed with joystick movement. Fixed it after some troubleshooting.
Thanks Paul, Another Great Lesson! I used a similar method to control 2 DC motors with one joystick
Did it before the video started. The function I used was an absolute function centered at 122.5 as the x axis, this being the reading from the analog read function. The y axis went from 100 to 255. I applied the y values onto the motors analogwrite.
Essentially my graph was a piece wise function. The equations were,
For x122.5
Y = (155/131.5)*(ypinval-122.5)+100
I set the cutoff at 100 since as discussed in the earlier videos, that is essentially the starting point for the motor.
Really satisfying to figure it out on your own.
Oh yeah, I converted the 0-1023 from analog read to 0-255 first just to make it easier for myself hahah.😅😁
My circuit would'nt work because my jStick's center value was 510 (not 513). This meant that one side over powered the motor to 256. Who knew it was so touchy? My problem solved when I set that side to 1 less in the equation and the result factored to 255. Thank you Mr. McHorter. BTW, I love the homoework assignments AND I'm finally learning why algerbra was/is important! The Slope intercept meant nothing to me until I started applying a voltage based on the potniometer. At 54, this old dog is learning some new tricks. 🙂
I got most of it on my own but needed your math explation to bring it all together. Excellent lesson and presentation . I really see where my algebra is lacking and will have to do a refresher to comprehend all your equation formulas . It's becoming my biggest stumbling block ... Thanks for helping me keep the cob webs out of this aging brain !!
I did it by myself.
I thought you meant to use a servo to control direction of the motor.I mounted the motor on top of the servo.I used the X axis on the joystick to control direction and Y axis of the joystick to control speed and direction of spin.Thank You for your great videos.
Rather than do a fixed neutral position value, I set the motor speed to zero between 500 and 525. Made a few errors with leaving out the decimal points, but managed to get those sorted.
Excellent lesson - it's very helpful to start combining elements from previous projects to make more complicated devices. Thanks!
did the homework successfully but, taking your advice from lesson 1, used variables throughout the formulae rather than constants for slope and offset etc. Also incorporated variables to allow for motor not starting at values less than 90 so whilst slop was the same then speed ran from 90 to 255 so min speed was a definable input. One problem I had to solve was how to have floating point numbers calculated in a formulae where variables and not constants are used e.g. 255./1023. becomes VariableA/VariableB , I solved this by defining VariableA and VariableB as float type variables, it worked so hope that is the best way to do that. I also didn't just use 512 as the off point but defined 2 variables that could be set just above or below 512 to allow for adjustable dead zone on joystick if needed. Thanks for another great video.
Hi Paul - another great lesson!
When I did the math, I included 2 extra bits to take into account the 100 speed requirement to get the little guy moving, plus my joystick seems to be a little wonky, neutral can be anywhere from 493-501. So I have 3 x "if" loops (dirVal>20, dirVal
hi Paul
I was very interested on how you were going to approach this problem, I did not solve the problem, but thanks to you Im getting better.
Your lessons are well planned and well delivered, including holding my breath.
Thankyou again for a very nice lesson.
Cool, thanks
I got the homework done! The tilt sensor was a lot harder to program in this then the last one. Cant believe in just a short time I was able to accomplish it. thanks for your most excellent teachings .
Good Tutorial. Your joystick made made life a lot easier but provided a less general solution. My neutral point was 503 meaning that one direction had 503 steps and the other 519. I also used a variable for the minimum speed so that the fan started as soon as the joystick was moved.
The basic speed calculation was (joystick_value - neutral_point)* ( (max_speed - min_speed)/(steps_for_this_direction)) + min_speed.
Got the homework done by myself but used while loops instead of if statements, it was basically the same with the difference being that i had to have three extra lines for the while loop version to check the jPin to exit each loop, so i ended up switching to the if version. Something i wanted to note is that for whatever reason my joysticks value when not moved in either direction is not a steady 512 it varies lightly, so i ended up using a small range for when it was not being moved (515-525) in my case, and then did the math for one direction from 0-515 and the other direction from 525-1023.
Thanks to the great lessons, I nailed it!! Ready for tutorial 40!!👍
OK I was moving in the right direction with the two if statements and the < and => 512 with the differing HIGH-LOW to get the different directions, but I struggled with the math. After some online study and then watching you solve it, I realized I was making it way too hard. Watching you solve this I think it finally clicked for me! Haha unfortunately one of the wires broke off the motor, so I had to order a soldering iron so I can fix it before I move on to the next lesson. See you in a few days when I get my motor repaired, and thanks for another fine lesson!
Brilliant vid - thank you so much. It worked first time!
Btw - thank you for all the work you have done on the Fusion 360 tutorials - I couldn't manage without them.
I find it much easier to just strip off a couple of cables off the ribbon rather than use the whole ribbon cable. Great series, recommended it to a couple of the folks who work with my wife. They have high school kids who are interested in electronics
Did this one on my own but did it with one straight line bisecting mSpeed =0 at Jval=505 (as my kit was slightly offset) My if statement set direction based on mSpeed being >=0 or < 0. It worked great too but uses just one line - simpler maths.... ;-) . Paul you are an awesome tutor.
Ok today I got me a motor and driver and I was able to fully enjoy this section of the tutorials. It is very important to write the code in the correct order (trying on my own).. at some stage I got 168 or something as the middle value for the joystick, so I just started over and did everything a lot more careful, properly focusing and it payed off.
I had the Y axis of the joystick control a servo motor with the fan motor mounted on it so I could control the direction the fan faced with the joystick along with the speed. By rotating the joystick off-axis by 90 degrees, it reverses X and Y so that the servo is now the X (points left and right) and the fan speed/direction is now Y (up and down). Looking at this program, if I can learn how to make things wireless I could use the joystick to operate a little RC car with the ability to turn and control the speed/direction of the wheels. Thanks for another good learning experience, Paul.
Hi! around the 19:53 min mark i was a bit thrown off when you used 255 for the y1 value when earlier in the equation y1 was 0. thank you so much for these incredible lessons btw!
Dear Paul, I find your tutorial videos both educational and entertaining. I've noticed in a couple of the last videos you mentioned that possibly some of your students are not enthused with the math involved to calculate slope, and the slope line equations needed to make the projects a success. I totally agree with you, the math is important to fully understand what is going on under the hood. I appreciate that you are taking the time to explain in detail. But for many, algebra 1 was never high point in high school. I've noticed that these videos I'm currently watching are a few years old and that you are in the process of updating the course with an updated Arduino release. As a suggestion, when you get to the areas involving the math, could you introduce the map function Arduino offers? I don't recommend replacing your math instructions with the function, but to give some of your students in knowing that the map function does exactly what you're teaching. It'll give a choice and possibly make some less math intensive students feel more confident. Thanks for all you do. ~George~
Had a little trouble with this assignment. I just could not visualize the line on the left. I was able to do the math for (512,0) to (1023,255). Had to watch the video until I saw you draw the second line and it all clicked in for me. I have a notebook that I have been keeping though out this corse. I still have to look at the formulas for slope and point slope. But even if I never memorize them. Thanks to you, when I look at them I understand and can do the math. Thanks again.
Thanks a ton for your videos. I learnt arduino because of you. You work is so neat & clean. I need to learn lot of things from you.
i love your videos by the way im using your tutorials to learn arduino for my project for an upcoming coursework and i cant tell you how much fun you make learn these things. thank you so much paul
Great to hear!
Thank you Paul, I am having some trouble with the math portion having been away from that for ~55 years or so. I very much enjoy the learning process though and appreciate your clear explanations
You can do it!
I am From Myanmar. You are the great teacher Mr Paul.I really enjoy learn your lesson.Thank you for sharing and teaching.I really appreciate you. God bless You Mr Paul.
Hi, Paul. I was able to do the home assignment on my own. The only difference is that I let the Arduino do the maths for me. Oh and I also incorporated the servo for the xPin so it is like a boat control. :)
I did it similar to yours, except I created two int's: mSpeedF and mSpeedB (forward and backward) then in the loop wrote the formula for each direction so when I wrote to the speedPin I used either mSpeedF or mSpeedB according to the direction it was going. Also, my center position of the joystick was reading 523, so my slope formulas for forward and backward were different. And finally, I created a between 524 and 525 to turn the motor off to account for any debounce and to make sur the motor was completely shut down when the joystick was in the center position. Fun project!
I did it on my own!!!🤩🤩🤩
I also wrote code by using joystick in vertical and horizontal direction too!!!
This project was great. Did not get the homework - stumbled on the two slopes. Understood it in the end! Great video, of course.
Got everything hooked up, ints and pinModes set, figured out half of the code to get my jVal. Then only did one slope in the math... also overthought the mSpeed=equation in the code and couldn't make it work right .Great explanation, as usual. Thanks Paul.
Great to hear!
Thanks Paul, Another Great Lesson! I really love your lessons .....please keep making such awesome projects!!!
Had it all done correctly but could not get my motor to run. Had to watch you, I am just having problems with the math and knowing what equation to use. Thank you Paul for taking the time to teach us.
I did the assignment on my own at first. I thought I did it wrong when I saw the way you did it, but it turns out my formula and line equation still works. This is the code that I created:
int Speedpin=3;
int Dirpin1=5;
int redpinmotor=3;
int blackpinmotor=6;
int Dirpin2=2;
int motSpeed=255;
int VRYpin=A0;
int VRXpin=A1;
int vrxval;
int vryval;
int del=500;
int switchpin=13;
int switchval;
int greenpin=8;
int redpin=12;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(Speedpin,OUTPUT);
pinMode(Dirpin1,OUTPUT);
pinMode(redpinmotor,OUTPUT);
pinMode(blackpinmotor,OUTPUT);
pinMode(Dirpin2,OUTPUT);
pinMode(VRYpin,INPUT);
pinMode(VRXpin,INPUT);
pinMode(switchpin,INPUT);
pinMode(redpin,OUTPUT);
pinMode(greenpin,OUTPUT);
digitalWrite(switchpin,INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
switchval=digitalRead(switchpin);
vrxval=analogRead(VRXpin);
vryval=analogRead(VRYpin);
Serial.print("Joystick Value Y:");
Serial.print(vryval);
Serial.print(" Joystick Value X:");
Serial.println(vrxval);
motSpeed=(255./1023.)*(vryval);
if(vryval==524){
digitalWrite(Dirpin1,LOW);
digitalWrite(Dirpin2,LOW);
analogWrite(Speedpin,motSpeed);
digitalWrite(redpin,HIGH);
digitalWrite(greenpin,LOW);
}
if(vryval530){
digitalWrite(Dirpin1,HIGH);
digitalWrite(Dirpin2,LOW);
analogWrite(Speedpin,motSpeed);
digitalWrite(greenpin,HIGH);
digitalWrite(redpin,LOW);
}
This one really made me think but I failed! I couldn't work the math, got the fan going in one direction but not the other. Once you explained it BOOM! Great lesson, thank you.
Fun video, Paul! Got it by myself, without looking at how you did it.! Turns out I did it exactly the way you did it.
Fantastic!
Things got a bit cattywampus at first but after making the graph and finding the two equations things started working better until finally it worked right. Math works out again!! Thanks Paul
Always awesome Paul, learning a lot with this arduino tutorial!
Thanks Paul. It worked! But my MID SETTING was 454 and TOP setting was 908. Worked it into the equation & it worked. Now to add some LED's with RED for reverse GREEN for forward. Going to have some fun.
I did it! I just finished doing it, it works great! I'd be dancing around if I could! Okay, now, going to watch the video...Thanks again!
Great job!
I worked it out slightly differently.
I used the co-ordinates 0-1023 for the joystick and -255 to 255 for the fan speed, if the fan speed was less than 0 I reversed the fan direction and converted the negative fan speed into a positive. Slightly longer and more complicated but it worked.