Arduino Tutorial 8: Understanding Pulse Width Modulation (PWM) and the Arduino Analog Write Command
Вставка
- Опубліковано 4 лип 2024
- You guys can help me out over at Patreon, and that will keep this high quality content coming:
/ paulmcwhorter
In this video we dive into how the Arduino Analog Write command really works. We connect the arduino to an oscilloscope and take a look at what the waveforms really are that are being generated.
You can get the following Elegoo kit, to follow these lessons and play along at home
amzn.to/3c9SJrO
You can get more details at our WEB site HERE:
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 - Наука та технологія
You: Trying to set a half brightness to the LED.
LED: -_-
Aight, that's the best joke I've heard all day
Just change int to float and change the number to 127.5
Hahahaha. Nerdy. ❤️
😂😂😂😂😂
you won the internet for a day
The moment I knew Paul was my favorite teacher was when he felt the need to re-square his boards because it bothered him - then explain it bothered him. His organization makes me so happy.
I’ve been binging all of these over my 2020 Xmas break. Thanks, Paul, for putting these learnings together! You’re an EXCELLENT teacher.
Having things square (in alignment) is an OCD trait of mine. I also obsess over things like keeping my cash all facing the same way front side up and stacked in denominational order. A picture on the wall makes me crazy if it is off level by 2 degrees. Grid-lined paper is greater than sliced bread to me.
@@arubaguy2733 "keeping my cash all facing the same way front side up and stacked in denominational order." YES. bonus points if you flatten bent corners on bills
the moment i knew was 2 seconds into the first video
the sheer attention to detail sets him apart
cheers!
Some of the best camera work I've seen on the internet UA-cam lessons.
agreed, this is honestly amazing
Correct
Definitely. Great performance for continuous recording without weird cut off blips
lesson 8 and i've learned a lot about arduino and how to get a "caffeine overdose" from those iced coffee
HAHAH, thanks Paul McWhorter
I have worked all my life in the electrical/electronic field And I Wished I had a Tutor like you . I'm now in my seventies and still learning Thanks Paul You are the best .
Your explanations are great: I'm a total novice and yet I understood perfectly everything you talked about.
Plus, I love the fact you're teaching things that allow us to understand what's going on, instead of just telling (for example) that PWM works the way it does "because it does".
I'm really glad I've found your videos!
Awesome, thank you!
"A real way of teaching engineering"
Well explained sir
I can see my dream come true only because of your fantastic tutorials. I want to run a CNC machine using Arduino. I will be greatful to you for rest of my life.
Hows the CNC machine going?
What’s a CNC machine?
@@danieldickinson9167 CNC stands for Computer Numerical Control and it is used to move the several axis of a tool by computer control. Industry uses CNC for welding metals, drilling, cutting and more on many materials. There are CNC drills, milling machines, lathes, routers, plasma cutters, water jet cutters, welders, EDM machines, benders, grinders, and probably many other machines that are CNC. People are now building their own 3D printers which are a type of CNC machine.
Really you are a fantastic teacher, it is a good way to explain PWM. now I understand PWM very well! Thanks.
Absolutely agree. Can't imagine it being demonstrated any other way, now that I have seen this lesson. Way to go, Paul!
It was interesting that when you dropped the pwm signal to 60 with the capacitor in the circuit the led actually cut out as the forward voltage was too low. This of course doesn’t happen without it as it’s being pulsed with 5v for a short time. So an led can run dimmer with pwm than it can with analog input. That’s really cool!
I actually regret not seeing this sooner
I didn't really understand Pulse Width Modulation before but I do now. Watching you build the circuit, then actually seeing a pictorial representation of what's happening as you changed the values in the program really made it clear. A lot clearer than reading an explanation in a book.
my notes for this lesson
analogWrite("pinNumber","value between 0-255"); the value 0-255 corresponds to 0-5 volts
this command uses - pulse width modulation: this means that the Volts are only either 0 or 5 but pulse on and off at a speed that is dependent on what value you are using.
how to view it: imagine a person is running at a speed of 5mph, for 0.1 seconds before they stop for 0.1 seconds. from your perspective it would appear that the person is running at a speed of 2.5mph even though they are actually only ever running at a speed of either 5mph or 0mph
brilliant
@@MrAshwindersingh well i dont get it. ..
Is it because the image persists in the eye for 0.1 s approximately. So even when it stops our eye continues seeing it for 0.2 secs and that is why it appears that he is slower and running at 2.5 mph?
I am a senior Electrical Engineering major at a good school and I didn't understand PWM at all when it was taught to me. Now it makes complete sense. Thank you so much Paul!
Excellent description of PWM... It made complete sense!
Brilliant explanations throughout your lessons Paul. Well paced and the content just enough in each session. Thank you
Hey Paul, like always, enjoying and actually learning from these videos, instead of other places. Thanks a lot once again. Keep it up.
Dear Paul!
Thank you for this in depth series of the Arduino. This is very promising and I'll can't wait to see all of it.
Thank you again sir!
You made this incredibly clear. Thanks so much, Paul!
Thank you so much for breaking out the oscilloscope. I never even knew I wanted to know this level of detail. Outstanding series so far and looking forward to the rest
PWM is something like turning a light switch on and off fast or slow causing it to be brighter or dimmer. Enjoying your classes. Thanks
I really love these videos, I’m a freshman doing mechanical engineering! I love these so much thank you
Can’t get enough of your videos it feels like I’m back in school in the best way possible!
Completely understood the concept. Great video.
I like that you go through the basics and code before jumping right into fancy sensors and motors like other lessons. You give us a good background and concepts so we create a renown things 👍
Hearing you say “hook a brother up” just cracks me up. Seriously though - these tutorials are GREAT! You are an amazing teacher. So clear and concise. Thank you so much.
Fantastic demo and explanation. Thanks Paul.
I really appreciate these tutorials. Very in depth it's impossible to get lost
The amount of preparation and thought that goes in making these videos is heartwarming. You're a fantastic teacher Sir
Sir there could not be an easier video explaining these concepts Bravo and a salute to your efforts 👍
This is great. I'm having so much fun watching these videos. I've watched them all at least three times.
I have just one word for your lecture , it awesome
Just wanted to thank you for this series. I've been "shotgunning" circuits and code by just copying and making up my own stuff for too long. You really have made understanding what is going on a lot easier!! Having a good teacher that is interested and motivated in the subject makes all the difference in my opinion. Thanks again and let's keep rolling!!
I'm a 50 year old technician that went to tech school before PC's were popular. Maybe it's the fact that I'm mature now and have a greater attention span but I think you are just a kind soul and it translates to a good teaching style. You are definitely taking the apprehension I had in learning Arduino and the associated programming to a manageable level. I've thoroughly enjoyed your lessons and look forward to learning more.
Thanks Paul you are always so clear in what you say. I now fully understand PWM. You are such a good teacher!
Thanks Paul. You make it very easy to understand.
I loved seeing the voltage on the oscilloscope, it really brings home, in a very visual way, how PWM works. I would love to have seen the Fade sketch on the oscilloscope to see what that would look like. Thanks for another great vid
8 lessons in 3 days, and still going strong! I love it, Paul
8 in 2 days mine
that's a lot of coffee!
The way you explain it, it is easy to understand. Love learning about this stuff.
These kind of lessons are empowering in the sense that I am learning about what's actually going on rather just putting words into code. It is not boring at all. Understanding the fundamentals is allowing me to think further into the codes and asking myself "what is really going on when I put this code in and is it what I want the Arduino to do?" The more of these kinds of lessons, the more I feel I am gaining in fluid knowledge that I can apply rather than just regurgitating information.
who is here in this quarantine
me!!!
i am doing this is surprising how many items we use every day could be working with there's
Week 10 (excluding school holidays) of lockdown in Scotland here :-)
me i loved this class
Me!
Paul, you do an excellent job of describing things. It is very easy to follow. You are a great teacher. Please continue to produce videos!
I loved this lesson! Especially the fact that you used the oscillator. Made it 100 times easier to understand!!
Well designed course for PWM. Thank you, Paul.
I would like to summarize the concept of PWM: a programmer sets the time for a circuit to be on and sets the time for a circuit to be off, in an on-and-off cycle. The result is the final average output voltage is set to a fixed value.
To easily undestant the effect of PWM, I do not think the best example is LED brightness. I believe the best example is use PWM to set the speed of a computer fan. Students will be able to visually see and understand PWM can set or change how much wind the fan can blow to them.
Thank you, Paul!
agreed, the eye doesn't respond linearly to brightness
It's actually amazing what you can do with pwm. We use it quite a bit with flight controllers to control our brushless motors for our drones. These motors are supplied constants battery voltage up to about 25v but the pwm occurs through a data line which is just 0-5v that turns the motors off or on by applying the battery voltage or removing It. It handles not only setting the rpms of the motors but ramping them up slowly or quickly and even active braking of the motor rpms by momentarily reversing the motor. Not to mention the radio control signal is based on pwm as well. I was one told to think of pwm as cruising at speed on a bicycle. You can stop pedaling and coast. If you want to keep that speed you don't have to pedal constantly but rather push the pedal full force a quarter turn every now and then to keep the speed constant. I probably didn't explain that very well but it made sense to me at the time.
I’m just starting arduino I didn’t think this lesson was important but wow
Ramble On Paul, I've never learnt so much in such a short time, Loving the videos Mate!!!
I enjoyed the class, great demo of the O-scope. Made PWM very clear and showed exactly what was going on. Thanks
The arduino simulates the analog voltatage by switching from plus 5v to 0 back and forth in a frequency to get the voltage
unless you use a capacitor right? I'm just asking because im not sure.
@@vitustillebeck4965 yaahh....
Paul I work in heavy equipment design and particularly in the hydraulic systems which power the mechanisms. Sometimes the valves we use are PWM type valves. Now with this understanding I can see better how the valves are working. In those systems they have PWM drivers which apparently produce enough amperage to actuate the valve coils. And I believe the signal we send the drivers is just a lower amperage signal. Does that sound correct?
Thank you for the class Paul. I am enjoying and liking the course.
Thank you ! The oscilloscope display re-inforced the PWM concept.
Hi Paul. loving the videos and looking forward to each one. only thing I noticed is your scope was set to 0.5mS per division and the period was 4.2 divisions. that to me is just a fraction over 2mSec not as you said 4mS. just me being eagle eyed. but loving it. when you getting onto inputting via switches or sensors?. keep up the excellent videos and not tried the ice coffee yet...
I could have misread it, thanks for the observation.
Not drinking Ice Coffee could get you banned from the channel, though:)
@@paulmcwhorter Now Paul, you know it's really tea in that cup. HaHa. Fantastic tutorial series so far! Learning so much. Thanks
@@paulmcwhorter actually you read the period from the screen and the msec/division scaling correctly, you just made a mistake when you used the calculator. You might want to put an overlay of the video at that point with the correct period of 2.1 msec rather than 4.2 msec.
Thank you for the Arduino Tutorials sir!!
I know that capacitor opposes sudden change in voltage. ic = C dV/dt. So, when the pin output goes from LOW to HIGH, capacitor should take large impulse current as dV/dt goes to +inf. Similarly when the pin output goes from HIGH to LOW capacitor should supply large impulse current back to Arduino pin.
Is it safe in the long run? Are digital/analog pins capable of taking current from external circuits??
The things you are saying are correct . . . I was just trying to show a quick and dirty demo of how capacitors can turn AC into DC. If you were really going to do this, you should do some circuit design.
It is safe, the Arduino pin when off is effectively floating and does not "sink" current from the cap, and the charge will sink quickly through the LED. Every digital pin is capable of handling 5V. What do you think it is doing for the digitalRead?
Great job explaining PWM, very easy to understand especially with the info from the oscilloscope. Thanks for the great videos, looking forward to going through the rest of them.
Yes I understand pulse width modulation after your explanation.
I fundamentally disagree with this video. It is well understood that good Arduino videos should be accompanied by hot coffee with cream and lots of sugar. 😊
BANNED!
😂
@@paulmcwhorter lol. Merry Christmas.
😂
Makes sense! Great explanation! Thanks Paul!
I have to reach out and say thank you, and I'm in awe of your lessons here. Just bought my kit, and can't wait to start playing with it. I'm a teacher myself and do short video lessons and am looking for great applications to show my students of mathematics and science. You break things down really well!
Well done Paul, thoroughly understood. Wish you were my professor back in the days. Thank you! Great job!
Hi Paul, you made it very clear to my understanding PWM. Thank you! 🙏
Love your videos! I always go back to them when i need help with Arduino.
it super clear - pulse wave modulation .. really amazing way how you teach. God bless you!
Another excellent video, thanks for all you do Paul!
Paul, you explained PWM very clearly. Just makes me want to know more and keep following your lessons
I understand pulsewidth modulation. Thanks Paul.
Loving this series..
this series is outstanding
Best explanation about pulse width modulation that I could find over internet. Thanks for teaching me
Really enjoyed this video, I now understand PWM but also adding the capacitor to smooth out the signal made so much sense. I'll be trying this myself tomorrow.
I've been wondering what uses capacitors had for a long time and this tutorial was a perfect example. Thank you!
Another gem!! Thanks a bunch. I understand capacitors and PWM now much better than ever before!
You are such a great teacher..... THANK YOU!
Best arduino teacher in my life!!!!
Thanks a lot sir
Yes. The aid of the oscilloscope display helps me to understand PWM in a very visual way. Thanks.
what I love about these videos is the under the hood explanations
I'm finally making the leap with a good understanding of electronics to software development. That was a great video of PWM. You have a very impressive course so far. great job!! 10/10
This really helped me learn about PWM
Very clear explanation. Also now understand the usefulness of capacitors a little more.
I have been watching each of your tutorial, and following with practicals on my breadboard : I am finally getting somewhere with Arduino! Excellent teaching method. I can see the value of setting the variables and having no numbers in the loop.Great demonstration of PWM and use of that capacitor .
Cheers for another great tutorial, mate! I am really getting to grips now with the theory and practical of electronics/voltages/analog/digital etc.
Another great video. The demo with addition of capacitor was very clear. Must say Paul, I thought I sort of understood PWM before I watched the video. Now I KNOW I do! Thanks a lot.
I have been wanting to understand PWM for so long and have been looking all over the internet for this. This is by far the best video that explains PWM to me with this oscilloscope. Thanks, Paul for this.
It helped to expand my undderstanding of PWM. thanks bro.
Excellent..! I bought the kit and trying one by one ..! Success so far..!
Thank you Sir Paul. Excellent lesson.
I had a basic bbn understanding of PWM, but when you hooked the cap in at the end, a HUGE lightbulb went off in my head. Thank you, thank you, thank you !!!
No doubt this is one of the best lessons explaining PWM!
I think this was great. I new what i PWM but I enjoyed very much your explanation. Thank you
Antonio Domit
Well done Paul! Ramble on it’s making sense to me. I’ve been explaining this to my spouse and friends and it is sticking.
Definitely, this is the best place to know about PWM. Many thanks. Great Job sir.
I'm doing some revision.. You explained pwm very well! Thanks Paul!
You Sir are heck of a teacher for any level student!! my sincere gratitude!!!
Thanks for the work you did on this. Just a few lessons and I can already see what going on in more complicated programs.
Yes, I understand. As I commented earlier, I am using your course as a refresher. I learned all this almost 50 years ago.
I fully understood the PWM concept. Than you Paul sir
Excellent explanation and demonstration Paul. I’ve certainly heard of PWM before but now have a clear understanding of exactly what it means.
Thanks a lot M. McWorther, your explanations over all that you teach are cristal clear, even for a french Canadian guy. Have a good day.
This makes a lot of sense, also to a lot of other stuff I’ve learned (like why some lamps look like they blink) i now also know why to use capacitors, and now i also know why you’d use resistors for the led instead of just setting the value of brightness to something like 30.
Thanks for the help Paul!
Thank you Paul, I've really learnt of you and your tutorial videos are the best academic videos I've ever watched. You describe everything in detail and I really enjoy watching your videos. I appreciate your time, patience, and effort. Thank you Thank you Thank you
Fantastic video series. I’m able to follow along and really getting the concepts.