Arduino Tutorial 38: Using a Tilt Switch Cut Off With a DC Motor

แชร์
ฝัง
  • เผยแพร่เมื่อ 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
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 404

  • @coltongerber4498
    @coltongerber4498 2 ปีที่แล้ว +16

    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 !

    • @426F6F
      @426F6F ปีที่แล้ว

      Great idea, Colten!

  • @arseivan
    @arseivan ปีที่แล้ว +2

    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);
    }

  • @pappgergely5031
    @pappgergely5031 4 ปีที่แล้ว

    Thank you Paul! I am happy to have you here!

  • @noelomeli1520
    @noelomeli1520 3 ปีที่แล้ว +1

    Homework done and now on to the next one! Thank you for the great lessons!

  • @Anmol-AK
    @Anmol-AK 5 หลายเดือนก่อน +2

    Completed the homework under 30 minutes on my own. Thanks a lot for your teaching sir

  • @tiberiumihaescu7348
    @tiberiumihaescu7348 4 ปีที่แล้ว +1

    I'm watching your videos up until the last second. Thank you so much for your work!

  • @LeonJakub
    @LeonJakub 3 ปีที่แล้ว +3

    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!

  • @moniftormos6881
    @moniftormos6881 3 ปีที่แล้ว

    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.

  • @mrktm65sx
    @mrktm65sx 5 หลายเดือนก่อน

    Completed homework on my own. Looking forward to the next tutorial. Thanks Paul!

  • @nickr8747
    @nickr8747 4 ปีที่แล้ว +6

    Keep doing these videos. they may not be crazy popular, but you have no idea how much these videos help us.

  • @danielsaenz5570
    @danielsaenz5570 2 ปีที่แล้ว +2

    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!!

  • @caripatd232441
    @caripatd232441 3 ปีที่แล้ว +2

    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.

  • @fjdelahoz
    @fjdelahoz 4 ปีที่แล้ว

    Happy Thanksgiving Paul to you and your loved ones. I enjoy your lessons very much and am looking forward to the next one!

  • @tedsykora1858
    @tedsykora1858 4 ปีที่แล้ว

    watching start to finish and doing the homework. Fun and helpful series.

  • @ericsmith7988
    @ericsmith7988 3 ปีที่แล้ว

    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.

  • @stephenmarshall1286
    @stephenmarshall1286 4 ปีที่แล้ว

    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.

  • @donalddalrymple1776
    @donalddalrymple1776 4 ปีที่แล้ว

    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.

  • @christophechalons9072
    @christophechalons9072 3 ปีที่แล้ว +2

    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 !

  • @andrewhodson8346
    @andrewhodson8346 3 ปีที่แล้ว

    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

  • @katherineclarke4435
    @katherineclarke4435 3 ปีที่แล้ว

    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!

  • @markfuentes3666
    @markfuentes3666 4 ปีที่แล้ว

    I complete the home work. Worked great. Did it the same as you. Thanks for these videos.

  • @srduke
    @srduke 4 ปีที่แล้ว +2

    I absolutely love these lessons. Lets have a "Yippy i yay" for Paul

  • @blazenbunny84
    @blazenbunny84 2 ปีที่แล้ว

    Tried it hands on and was successful in completing my homework :) Thankyou so much!!!

  • @jbelmont72
    @jbelmont72 ปีที่แล้ว

    love these. I used a nested if loop to give the motor the "kickstart" so I could initiate spinning at a lower RPM.

  • @hasan-motam
    @hasan-motam ปีที่แล้ว

    I did the homework without a problem. Thanks once again Paul.

  • @adamcurtice3584
    @adamcurtice3584 2 ปีที่แล้ว

    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.

  • @jessekloberdanz246
    @jessekloberdanz246 2 ปีที่แล้ว

    Love the videos! We appreciate you. I did this one a bit different, but your way seemed to work better.

  • @OtAkU10505
    @OtAkU10505 4 ปีที่แล้ว

    I ALWAYS do my homework Paul!! Love your videos!

  • @thefierceninja2557
    @thefierceninja2557 2 ปีที่แล้ว

    I did the homework with flawless victory! Can't wait to start on the joystick controls!

  • @user-ys6bc7yh7z
    @user-ys6bc7yh7z 7 หลายเดือนก่อน

    Assignment is completed!
    Love your lessons and started to learn math because of your inspiration!
    Thank you very much.

  • @tntragan
    @tntragan 2 ปีที่แล้ว +1

    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.

  • @Europayacht
    @Europayacht 4 ปีที่แล้ว

    Very very educating to me and my friends, really dragged us into the µC buissness. Thanks to Paul !

  • @higuy2k
    @higuy2k 4 ปีที่แล้ว

    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. 😀

  • @glennfelpel9785
    @glennfelpel9785 4 ปีที่แล้ว

    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.

  • @pudgepatenaude3481
    @pudgepatenaude3481 3 ปีที่แล้ว

    Boom, done already on my own from homework assignment. you are an excellent teacher. thanks so much.

  • @dannycollins5698
    @dannycollins5698 ปีที่แล้ว

    Finished the homework before watching this. I used an else statement instead of another if statement.
    Thank God for you! God bless you sir!

  • @user-vf7fx2ff9d
    @user-vf7fx2ff9d ปีที่แล้ว

    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!!!

  • @panzerblitz8226
    @panzerblitz8226 2 ปีที่แล้ว

    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.

  • @travisrichardson5366
    @travisrichardson5366 4 ปีที่แล้ว +1

    My coding was slightly different initially, but still got it to work. Yours was definitely more streamlined. On to my next homework assignment.

  • @clairsmyers3571
    @clairsmyers3571 4 ปีที่แล้ว

    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.

  • @richardletourneau2672
    @richardletourneau2672 4 ปีที่แล้ว

    I did the assignment after few corrections it work OK. After I put the decimal point everything work fine. Thanks again.

  • @muhammadrafiqulislamkhan6994
    @muhammadrafiqulislamkhan6994 2 ปีที่แล้ว

    This another great project for me. I am waiting for next one. Thank you very much.

  • @TheParksy72
    @TheParksy72 3 ปีที่แล้ว

    did the homework, love that I just know how to do it. It's all thanks to you, my good sir.

  • @philnewman1110
    @philnewman1110 ปีที่แล้ว

    Still there watching all the way through to the very end Paul, as always a very interesting tutorial, thanks again!!

  • @TheSelfUnemployed
    @TheSelfUnemployed 2 ปีที่แล้ว

    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!

  • @marksholcomb
    @marksholcomb 3 ปีที่แล้ว

    Did homework, but, simply put the tilt switch in series with Vcc. Thanks for another great lesson.

  • @richardbritain7435
    @richardbritain7435 2 ปีที่แล้ว

    Brilliant!! I managed the tilt and stop homework on my own. The next project looks tricky though. Thanks.

  • @Rob_TheOne
    @Rob_TheOne 3 ปีที่แล้ว

    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.

  • @muhammaddanial50
    @muhammaddanial50 3 ปีที่แล้ว

    Did my homework in just 5 mins time thanks to you paul💯

  • @michaeldalfonzo3912
    @michaeldalfonzo3912 2 ปีที่แล้ว

    Did the homework and got it working just fine. This one was easy.

  • @johntello8904
    @johntello8904 3 ปีที่แล้ว

    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!

  • @AlexDavis-ch1ro
    @AlexDavis-ch1ro ปีที่แล้ว

    Super challenging homework, but mostly was able to do it. Thanks for your great instruction!

  • @theknottyworkshopgeoffjung529
    @theknottyworkshopgeoffjung529 4 ปีที่แล้ว

    Thanks for the video. Did the homework and got it on my own.

  • @muhammadrafiqulislamkhan6994
    @muhammadrafiqulislamkhan6994 2 ปีที่แล้ว

    Every projects I love. Thank you.

  • @josephcapell1494
    @josephcapell1494 3 ปีที่แล้ว

    I always do my homework! Thank you for the videos.

  • @pratikdas1780
    @pratikdas1780 3 ปีที่แล้ว

    Did it on my own, sir. Thank you for all the lessons. 38 down. 20 more to goooooo!!!

    • @pratikdas1780
      @pratikdas1780 3 ปีที่แล้ว

      *30 more to go lol. sorry for the typo.

  • @SimonChil
    @SimonChil 3 ปีที่แล้ว

    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.

  • @matthewstone898
    @matthewstone898 7 หลายเดือนก่อน

    Was able to do this, simple enough and added a active buzzer as part of the tilt.

  • @josemejias1054
    @josemejias1054 4 ปีที่แล้ว

    i watched all your videos and theyre really good during quarantine. Thank you.

  • @tallslimpr
    @tallslimpr 3 ปีที่แล้ว

    Im here Paul, til the end. Thank you !

  • @MarvPerk3
    @MarvPerk3 3 ปีที่แล้ว +1

    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!

  • @kevhopkins984
    @kevhopkins984 3 ปีที่แล้ว

    Enjoyed, and yes I did do the Homework, not quite the same way you did, but still with success.

  • @tdc485
    @tdc485 3 ปีที่แล้ว

    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.

  • @pralaymajumdar7822
    @pralaymajumdar7822 4 ปีที่แล้ว

    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.

  • @lesliejames5722
    @lesliejames5722 2 ปีที่แล้ว

    Rose and Ronald, another good lesson thanks Paul.

  • @RavensHammer00
    @RavensHammer00 ปีที่แล้ว

    Watched to the end, and your coding was almost exactly like mine! Thank you! Off to do more homework!

  • @johnkafer5061
    @johnkafer5061 4 ปีที่แล้ว

    yup, did homework and solved it......you are an excellent teacher, giddyup...

  • @shivanipawar7569
    @shivanipawar7569 4 ปีที่แล้ว +1

    did my homework!!! and it was working perfectly fine....

  • @ylevite
    @ylevite ปีที่แล้ว

    This one was easy :) Thanks for the wonderful lessons!

  • @bleujaegel
    @bleujaegel ปีที่แล้ว

    Made it through the homework unscathed. Love the homework assignments!

  • @JohnSmith-lp5en
    @JohnSmith-lp5en ปีที่แล้ว

    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.

  • @ianteague2929
    @ianteague2929 ปีที่แล้ว

    I'm definitely doing my homework. And I do watch all the way to the end of every episode .

  • @Hino_55
    @Hino_55 4 ปีที่แล้ว

    Great lesson Sir Paul, Thankyou!

  • @aideningraham7249
    @aideningraham7249 4 ปีที่แล้ว

    Awesome video, cant wait for the next one!

  • @agustinruiz2081
    @agustinruiz2081 2 ปีที่แล้ว

    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.

  • @freetjen
    @freetjen 10 หลายเดือนก่อน

    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 ✌

  • @Mrgasman1978
    @Mrgasman1978 ปีที่แล้ว

    Rose amd Ronald! I always watch all videos to the end and more than once!.

  • @tonyperry6702
    @tonyperry6702 4 ปีที่แล้ว

    Did my homework. It worked perfectly.

  • @marcusindicuz7757
    @marcusindicuz7757 4 ปีที่แล้ว

    thank u so much for all the lessons. I did the homework without and extra code
    :)

  • @yovavgur-ari9580
    @yovavgur-ari9580 ปีที่แล้ว

    Great lesson

  • @jabber2824
    @jabber2824 หลายเดือนก่อน

    Yes I always do the homework and watch to the end :-) Great stuff incorporating earlier learned stuff.

  • @GeoGebweiler
    @GeoGebweiler 4 ปีที่แล้ว

    Oh yes. I also did my homework and it worked fine :-) Thanks for teaching, Paul !

  • @VegasGuy89183
    @VegasGuy89183 ปีที่แล้ว +2

    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. 👍

    • @kriegschwert
      @kriegschwert ปีที่แล้ว

      Haha, putting the tilt switch on extensions was a great idea, thanks!

  • @garywilliams5962
    @garywilliams5962 3 ปีที่แล้ว

    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 👍👍

  • @dougnash6316
    @dougnash6316 4 ปีที่แล้ว

    That was brilliant, many thanks. My motor is OK, I had it plugged into the VIN not 5v. Aging eyes. Still a problem with either the power supply board or the controller but there is a work around.

  • @warsteelcalgarus5790
    @warsteelcalgarus5790 ปีที่แล้ว

    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

  • @1271344able
    @1271344able 3 ปีที่แล้ว

    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.

  • @sammysam1503
    @sammysam1503 3 ปีที่แล้ว

    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);
    }
    }

  • @thysdelport6782
    @thysdelport6782 ปีที่แล้ว

    Done and dusted. Added two motors due to the use of L298N board. Great tutorial yet again.

  • @thomascolley9784
    @thomascolley9784 ปีที่แล้ว

    Hi Paul, nice work as usual. I learn a lot from your videos. I do the homework and have had some success. Have that I keep getting distracted coming up with silly projects of my own by combining different lessons. Thanks for your help

  • @kevincornelia4067
    @kevincornelia4067 3 ปีที่แล้ว

    Did the homework on my own👌. My code was a bit different but it worked the same! Used and if, else statement 👍🏻.

  • @hughpatterson1480
    @hughpatterson1480 2 ปีที่แล้ว

    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.

  • @aaronmilliman7685
    @aaronmilliman7685 ปีที่แล้ว +1

    Another great video. Thank you.

  • @pokerface68
    @pokerface68 2 ปีที่แล้ว

    This was a fun easy project. I set mine up very similar to yours except mine worked correctly the first time because I did a digitalRead(tiltPin) instead of analogRead(tiltPin) like you did. The other difference I had was instead of using analogWrite(speed_pin,0); I created and used another variable - motorOff=0 to shut off the motor using analogWrite(speed_pin,motorOff); Once again, thank you for a fine lesson!

  • @liquidalex772
    @liquidalex772 4 หลายเดือนก่อน

    I love these videos i just started with arduino and this help so much

  • @CarolinaDGF
    @CarolinaDGF 2 ปีที่แล้ว

    Easy - once I remembered to do the resistor trick on the tiltPin. :) I am very much enjoying this series.

  • @johnganci933
    @johnganci933 4 ปีที่แล้ว

    I've completed the homework and look forward to comparing your solution, to be shown in lesson 39.This was a fun assignment.
    On another note, I did not buy my Elegoo kit at the beginning of this series, so I have a lot of earlier lessons to do. One of those, lesson 22 (active buzzer), has homework to add a potentiometer to sound the buzzer when the potentiometer has a value greater than or equal to 1000. I decided to do this one. Since my breadboard is currently set up for lesson 38, the Arduino 5V pin is in use by the joystick. The potentiometer needs 5V, GND, and an Arduino analog pin. Rather than use the Arduino 5V pin, I thought that, since the power board that is already on my breadboard outputs 5V, I would use that with the potentiometer. Much to my surprise, when turning the potentiometer from low to high, the value went from 0 to around 995. Adding code as shown in lesson 12 (potentiometer) to also show voltage, the 995 value corresponds to 4.86V, a little shy of 5V. I am using an AC-DC adapter to power the power board. I did verify that the AC-DC adapter is outputting 9.03V, so it appears to me that my power board is not outputting 5V.
    Just to doublecheck, I did hook up the potentiometer directly to the Arduino 5V pin. In that case, the maximum potentiometer value (and voltage) is 1023 (and 5.00V), as expected.
    Could someone here check if their power boards behave similarly? The simplest test is to repeat lesson 12 (potentiometer), but hook it to 5V and GND on the lesson 38 breadboard layout so that it is powered by the power board.
    This is not a problem, just a surprise. The DC motor and stepper motor lessons work fine, even if the power board outputs slightly less than 5V.

  • @oljeitulkhagva6288
    @oljeitulkhagva6288 3 ปีที่แล้ว

    love the content keep it going

  • @ShockingTips
    @ShockingTips ปีที่แล้ว

    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 👍

  • @opalprestonshirley1700
    @opalprestonshirley1700 4 ปีที่แล้ว

    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.