Arduino Tutorial 38: Using a Tilt Switch Cut Off With a DC Motor
HTML-код
- Опубликовано: 25 ноя 2019
- 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 today's lesson we demonstrate how to incorporate a tilt switch cutoff into a DC motor project. This is a useful method for cases where you would like to automatically turn your motors off in the case your project/device turns over or tips. This feature can be useful in a number of different projects and prototypes.
You can get the kit I am using for this series at the following link:
amzn.to/2I7N4Ek
Follow these lessons on our FREE web site:
toptechboy.com/arduino-tutori...
[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 did the homework on the last episode no problem and decided to use the knowledge Ive gained so far afterwards to combine my DC Motor, Servo, and Joystick , X controlling motor speed/direction , Y controlling servo position to point the fan in a desired direction. My longest code so far and was successful right away. Fantastic teaching I can’t thank you enough !
Great idea, Colten!
Great lesson! Here is the code I ended up having before watching the video:
void loop() {
bool tiltVal = !digitalRead(tiltPin);
digitalWrite(directionPin1, HIGH & tiltVal);
digitalWrite(directionPin2, LOW & tiltVal);
analogWrite(speedPin, mSpeed);
}
Completed the homework under 30 minutes on my own. Thanks a lot for your teaching sir
Did the homework! When you see people only viewing for 3 minutes I think you'll find it's people just revisiting sections of tutorials they have watched in entirety previously to help better understand the one they are currently working on. I have certainly done this on multiple occasions!
Keep doing these videos. they may not be crazy popular, but you have no idea how much these videos help us.
Thank you Paul! I am happy to have you here!
I made it Mr. McWhoter. Great video as always. I will finish this course to the end. So far I haven't had any problem and I've managed to pull out every assignment before see in you doing it. I always watch your videos up until the last second. Thank for your hard work doing these videos.
Did my homeworks, even managed to control speed and direction with a pot and a pushbutton (using the INPUT_PULLUP status given by one of your followers)... I'm so happy that 2 days ago I didn't even know how to use a component... now I just feel like understanding is at hand !
What I like the most is when you explain by physics and math how and why things work in a component. It's so helpfull !
Great teacher ! I have been watching your videos since a week and now I have reached this lesson. Wish you a great day for you and you granddaughter.
I'm watching your videos up until the last second. Thank you so much for your work!
Homework done and now on to the next one! Thank you for the great lessons!
I used the tilt switch and also used the photo detector,. they work great together. The motor does slow down with low light and full speed at full light. Thank you Paul always a good day to watch your lessons.
Completed homework on my own. Looking forward to the next tutorial. Thanks Paul!
Finished the homework before watching this. I used an else statement instead of another if statement.
Thank God for you! God bless you sir!
I completed the homework prior to watching this lesson. The logic was pretty straight forward. I used an If-Else statement to solve the logic. It worked great with very little issues. Thanks for the knowledge.
I did it ;) (it was kind of easy) Thanks so much for all these AMAZING TUTORIALS!!
These homework assignments are so important I am so glad you do them!!
BOOOOOM!!! Did it all by myself, coded it a slightly different way. Tilt sensor wasn't working at first, narrowed it down to hardware issue through your excellent de-bugging training; moved it away from the columns occupied by L293D and giddy up!!!! Success!
Hi Paul. Did my homework and very close to your solution. I also pointed out your baud rate error in my comments to Tutorial 37. Really enjoying these tutorials. Thanks
Happy Thanksgiving Paul to you and your loved ones. I enjoy your lessons very much and am looking forward to the next one!
love these. I used a nested if loop to give the motor the "kickstart" so I could initiate spinning at a lower RPM.
My version was about 90% the same as your version including pin and variable names. I lean toward the if/else versus the if/if approach. Good lesson, getting more comfortable with the thought process for the design. Keep it up, thanks.
I absolutely love these lessons. Lets have a "Yippy i yay" for Paul
I did the homework without a problem. Thanks once again Paul.
Tried it hands on and was successful in completing my homework :) Thankyou so much!!!
Yes did the homework and worked great. I like the fact you make mistakes (whether deliberate or not) as this makes us analyse the issue.
I did the homework with flawless victory! Can't wait to start on the joystick controls!
watching start to finish and doing the homework. Fun and helpful series.
Did the homework. I used a while loop instead and it worked quite nicely. Had to take the delays out like you did. I was yelling at you about the analogWrite instead of the digitalWrite. My wife thinks I'm crazy.
Assignment is completed!
Love your lessons and started to learn math because of your inspiration!
Thank you very much.
Very very educating to me and my friends, really dragged us into the µC buissness. Thanks to Paul !
Love the videos! We appreciate you. I did this one a bit different, but your way seemed to work better.
This another great project for me. I am waiting for next one. Thank you very much.
I complete the home work. Worked great. Did it the same as you. Thanks for these videos.
Another good lesson. At the pace you are presenting them I am able to keep up and to do the homework. Will have this one done for next week.
See you then. Thanks you for the training.
Hi Paul, I looked the lesson until the end :-) ...and I made my homework! I appreciate your effort for teaching us very much! Thank you a lot!!!
Did the homework between lessons. Got it working, after watching you code it, I had to look over my shoulder to see if you had watched me write the code, almost identical right down to variable names. 😀
Still there watching all the way through to the very end Paul, as always a very interesting tutorial, thanks again!!
Brilliant!! I managed the tilt and stop homework on my own. The next project looks tricky though. Thanks.
Super challenging homework, but mostly was able to do it. Thanks for your great instruction!
Great job!
Boom, done already on my own from homework assignment. you are an excellent teacher. thanks so much.
Did the homework and got it working just fine. This one was easy.
Using this to control an rc crawler thank you! Back to the servo and IR control lessons. Glad I did my homework and mapped my buttons.
The tilt switch homework was easy and ill be getting to work on the joystick HW in the morning as it is getting late. Thanks you Paul!
Was able to do this, simple enough and added a active buzzer as part of the tilt.
did the homework, love that I just know how to do it. It's all thanks to you, my good sir.
I did the HW before watching , and it was working, thanks to your great explanations about tilt function earlier! Thanks again, you are the perfect teacher.
Excellent!
I did the assignment after few corrections it work OK. After I put the decimal point everything work fine. Thanks again.
I did my homework and had it working prior to watching this episode. Setting the motor speed to zero seemed logical, so that's what I did. The only mod I made was to put the tilt-switch on a couple of male/female wire extensions to make the tip-over testing easier. Thank you for another wonderful lesson. 👍
Haha, putting the tilt switch on extensions was a great idea, thanks!
Every projects I love. Thank you.
I did it myself. I also added a potentiometer to control the speed and a button to change direction. Off to do the joystick assignment now.
I did my homework. I only added one if statement in my code, so that when tiltVal == 1, the command digitalWrite(speedPin, LOW) was executed. Thanks for the great lesson Paul!
Enjoyed, and yes I did do the Homework, not quite the same way you did, but still with success.
Im here Paul, til the end. Thank you !
Watched to the end, and your coding was almost exactly like mine! Thank you! Off to do more homework!
Excellent!
Rose amd Ronald! I always watch all videos to the end and more than once!.
Rose and Ronald, another good lesson thanks Paul.
Mr McWhortor, I just received the elegoo super starter kit today. I should have gotten that a long time ago. I had a problem getting the board going but checked the com channel and it was different than my Arduino. I changed that and, it is working fine and ran the sketches that I uploaded to it. I'm good to go and now I have the sensors to follow your videos. Thanks for the advice. That starter kit is absolutely the way to go.
Did homework, but, simply put the tilt switch in series with Vcc. Thanks for another great lesson.
Did my homework in just 5 mins time thanks to you paul💯
I ALWAYS do my homework Paul!! Love your videos!
Yes I always do the homework and watch to the end :-) Great stuff incorporating earlier learned stuff.
Awesome video, cant wait for the next one!
i watched all your videos and theyre really good during quarantine. Thank you.
Happy to hear that!
My coding was slightly different initially, but still got it to work. Yours was definitely more streamlined. On to my next homework assignment.
yup, did homework and solved it......you are an excellent teacher, giddyup...
I got it before to watch the video, basically it was easy applying the concepts I learnt in the 2 previous videos . I am looking forward to doing the next homework with the joystick.
Great job!
Of course i've done my homework. Always do! I even tried to go further including a joystick on my own but i'll have to wait for the next lecture to figure it out.
Did it on my own, sir. Thank you for all the lessons. 38 down. 20 more to goooooo!!!
*30 more to go lol. sorry for the typo.
I always do my homework! Thank you for the videos.
I'm definitely doing my homework. And I do watch all the way to the end of every episode .
This one was easy :) Thanks for the wonderful lessons!
Great job!
Thanks for the video. Did the homework and got it on my own.
thank u so much for all the lessons. I did the homework without and extra code
:)
Yes sir.....I am able to do the homework....I am eagerly waiting for the next Tuesday at 9:30 pm in India....Thank you.
Did my homework. It worked perfectly.
did my homework!!! and it was working perfectly fine....
Oh yes. I also did my homework and it worked fine :-) Thanks for teaching, Paul !
I did my homework before watching the video worked great. Todays homework is going to be fun really like how you assign homework to test your viewers learning progression though these series of videos.
Great job!
Made it through the homework unscathed. Love the homework assignments!
Hey Paul, I sure did the home work plus I added the green and red LED to show a visual warning if the fan tipped over.
Did the homework on my own👌. My code was a bit different but it worked the same! Used and if, else statement 👍🏻.
I love these videos i just started with arduino and this help so much
Done and dusted. Added two motors due to the use of L298N board. Great tutorial yet again.
Nice work!
This one was cake!! The only thing to this point that I’m struggling to conceptualize is the toggle switch. It gets easier the more I practice with it tho
Exactly man
I can agree
I absolutely agree 🙂
Yes
@@williamhandlebar9585 the toggle switch was very challenging
Great tutorial as usual. Did the math already for the joystick and all works fine. I really love to do the homework in front, and then see how you did it afterwars. Start getting the hang on the math stuff 🤓. Can't thank you enough for taking the time and effort to explain all those things to us ✌
Great lesson Sir Paul, Thankyou!
Hi, Paul. Did the homework on my own successfully. Since the bread board is so big and I hate to have to tear it down and start over most times, I decided to see if I could combine lessons 35, 36, 37 and 38, both schematic and code, so I could run the whole shmear at once. So, now I have a reversible stepper motor driven by a toggle switch, a DC motor and fan running clockwise (so the air blows out/up from the blades), and both motors stop if the tilt switch goes to 1... with green and red LEDs to indicate when it is normal vs "tilted". I'm sure the battery doesn't love running 2 motors at once, but the PS does seem to handle it. My board is quite full, but I didn't run out of pins! Fun!
Easy - once I remembered to do the resistor trick on the tiltPin. :) I am very much enjoying this series.
Cool, thanks
As I tell my students, any homework I give you, I do myself. I did the homework because the only way to really learn is to try things on your own. Doing this is really helpful because a day will come when there is no one to guide you but yourself. Thanks for another great video.
Great job!
Great lesson
I did this after the previous lesson all on my own! Loving the videos!
int speedPin=5;
int dir1=4;
int dir2=3;
int tiltPin=2;
int tiltVal=0;
int mSpeed=255;
void setup() {
// put your setup code here, to run once:
pinMode(speedPin,OUTPUT);
pinMode(dir1,OUTPUT);
pinMode(dir2,OUTPUT);
pinMode(tiltPin,INPUT);
digitalWrite(tiltPin,HIGH);
pinMode(buttonPin,INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
tiltVal=digitalRead(tiltPin);
analogWrite(speedPin,mSpeed);
Serial.println(tiltVal);
if(tiltVal==1){
digitalWrite(dir1,LOW);
digitalWrite(dir2,LOW);
analogWrite(speedPin,mSpeed);
tiltVal=digitalRead(tiltPin);
Serial.println(tiltVal);
}
if(tiltVal==0){
digitalWrite(dir1,HIGH);
digitalWrite(dir2,LOW);
analogWrite(speedPin,mSpeed);
tiltVal=digitalRead(tiltPin);
Serial.println(tiltVal);
}
}
I am now able to add the tilt cut off with flashing red LED. Control the speed of the motor with a potentiometer. Turn the whole thing off and on and reset the tilt state with a button.
I just wanted to take the time before finishing this video to let thank you for this series!
You taught me how to do Fusion 360 and I'm so happy to continue to be able to learn from you.
Reply
love the content keep it going
I was thinking about where a tilt switch is used and there is one in my portable heater that shuts it off to prevent fires. It also turns on a red light. Really useful information 👍
Another great video. Thank you.
Glad you enjoyed it
Did my tilt switch homework, pretty much the same except I used an “if else” command. Off to do my joystick homework now, looking forward to this, bit more challenging than the tilt switch 👍👍
Awesome Paul, May God bless you!
Thank you kindly
Great stuff!
Homework did, thanks Paul.
Glad to help
I did do the homework and it works well. Mine was slightly different than yours but with the same result. Your coding was a bit simpler though. Thanks Paul.