Arduino Uno R4 WiFi LESSON 11: Pulse Width Modulation (PWM) Simulation of Analog Voltages

Поділитися
Вставка
  • Опубліковано 5 жов 2024
  • Pick your Sunfounder kit up so you get the same results I do:
    amzn.to/3SciApZ
    This is the Oscilloscope I used in this lesson.
    amzn.to/3S1AzOE
    You can pick up the neat jumper wires I showed in the video here:
    amzn.to/3U2vyIe
    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 I introduce you to the concept of analog voltages on the Arduino Uno R4 Serial Monitor. I show how the arduino simulates analog voltages using PWM, or pulse width modulation. I explain the concept, and then show you the waveform on an oscilloscope Enjoy!
    [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. ]
    #arduinor4wifi
    #PWM
    #tutorial
  • Наука та технологія

КОМЕНТАРІ • 44

  • @larryb6759
    @larryb6759 6 місяців тому +6

    Pulse Width Modulation (PWM) is a technique used to encode analog information in a digital signal. It involves rapidly switching a digital output between on and off states at a fixed frequency. The ratio of time the signal is on (high) to the time it is off (low) within each period, known as the duty cycle, determines the average voltage or power delivered to a load. PWM is commonly used in controlling the speed of motors, regulating LED brightness, and generating analog signals from digital sources.

  • @peterwadham7965
    @peterwadham7965 6 місяців тому

    Great Lesson and nice scope, PWM allows the user to change the proportion of the time the signal is high compared to low, over a constant time interval to simulate an analog output

  • @alfredcalleja450
    @alfredcalleja450 6 місяців тому +1

    Hi Paul, thanks for another insightful tutorial. Even though I did your previous tutorial on PWM, I found this really reinforced my understanding of PWM and analogWrite, so I found this video really helpful and useful. Also, you really brought home to me the understanding that analogWrite is really pwmWrite and it only simulates an analog signal. Thanks again.

  • @jameslewellen150
    @jameslewellen150 6 місяців тому +1

    Nice video, in my previous homework I used the oscilloscope to show this. Have a nice day/night.

  • @CasiboyCasiboy
    @CasiboyCasiboy 6 місяців тому +1

    hey Paul , i really love and enjoy your series of tutorial. In my opinion you are the best teacher there is out here, dynamic, make difficult concepts look casual , funny and have a lot knowledge. Could you do a series of tutorials on PCB design, I am sure you are pretty knowledgeable in this area of engineering. Thank you , God Bless you and your loved ones.

    • @paulmcwhorter
      @paulmcwhorter  6 місяців тому

      Thank you for the kind words. Probably wont be doing a PCB series as I do not have access to a way to get them made. Also, it is a tough topic as the software typically has so many different parameters, it is hard for a hobbiest to really master the topic.

    • @CasiboyCasiboy
      @CasiboyCasiboy 6 місяців тому

      PCBway offers manufacturing services at very affordable prices, often just a few dollars. Your ability to simplify complex concepts has always impressed me, so I understand if you prefer not to dive into this topic. However, if you're willing, I'd greatly appreciate a well-written explanation.

  • @frickinbill
    @frickinbill 6 місяців тому

    Great lesson! Ordered oscilloscope from your amazon link as its a very useful instrument.
    I agree with another comment regarding a basic course in how to utilize one as it can be very intimidating in regards to cost versus proper usage.

  • @jeraldgooch6438
    @jeraldgooch6438 6 місяців тому

    Not related to this video but…. I needed to edit a file on an RPi4. I found one of your old videos that covered how to use nano. Because of that video I was successful in what I needed. Just to remind you that your videos are valued as a tech library. Thanks.

  • @mundocoolokudasai9478
    @mundocoolokudasai9478 7 місяців тому +2

    Excellent videos, dear teacher, you could make an example with Arduino to control a brushless motor for RC airplanes, using drivers because I always end up burning the drivers and mosfets, to control the gates of the mosfets, the motors are soon three-phase and we use them famous h-bridges, we would appreciate it, and for everything you have taught us, God bless you

  • @Tron_Starfighter
    @Tron_Starfighter 4 місяці тому

    We can simulate an analog value using a digital device if we properly choose our ON and OFF time frames. The arduino function 'analogWrite' performs this function for us requiring us to only need to choose a "brightness" value; which in reality is setting the ON/OFF time frames. I suspect we could achieve the same result manually by using the function 'digitalWrite' and choosing sufficiently small 'delay' time values for ON and OFF.

  • @FreidonNasrat
    @FreidonNasrat 5 місяців тому

    great lesson, I understood how to use PWM to perform analogWrite to digital.

  • @drthik1
    @drthik1 6 місяців тому

    Makes sense how the arduino uses pwm/timing/off-on to control output voltage. Used the oscilloscope to see the signal output. It would be nice to get a supplemental crash course lesson on using it though. I ordered one through your amazon link.

    • @paulmcwhorter
      @paulmcwhorter  6 місяців тому +3

      I am thinking about doing a general circuits class around the oscilliscope but just have not yet got it all laid out.

  • @DrDave327
    @DrDave327 5 місяців тому

    Great review, Paul! Keep this great content coming!!

  • @larryplatzek9017
    @larryplatzek9017 6 місяців тому

    As usual this a great lesson and next week will be doing Analog reads, good!

  • @MStoica
    @MStoica 6 місяців тому

    I can say your videos are great, without saying “your videos are great”: I’m watching despite the coffee remarks 😁 I would never put more coffee than milk in a coffee drink. Plus 2-3 kinds of syrup: always caramel and coconut, and sometimes also hazelnut - otherwise the drink doesn’t make any sense to me 😅

  • @ryanholt2509
    @ryanholt2509 3 місяці тому

    Great explaination!

  • @taurus548
    @taurus548 5 місяців тому

    Great Lesson!

  • @scottwait3585
    @scottwait3585 6 місяців тому

    Thank you Paul

  • @robertschuldenfrei2402
    @robertschuldenfrei2402 6 місяців тому

    There is no “making” assignment for this week. Rather, teacher Paul asked us to summarize Pulse Width Modulation (PWM) as explained in the video. The Arduino can only generate digital signals by way of two voltages, either zero volts or five volts. That can be made to correspond to a pseudo analog value of voltages between 0 - 5. It does this by dividing the signal into small segments of 1/256 or 0.01953 volts each. It then passes one of these integers on to the analogWrite() function. For example, if you sent 51 to the analogWrite() function it would output 1v. It does this by keeping the pulse voltage at 5 for 51/256 of the time and 0 for 205/256. The LED appears to be dimly lit all of the time, but it is dark most of the time in this example.
    Just for fun I asked ChatGPT: “What is Arduino PWM?” Of course, ChatGPT did not listen to today’s presentation, however its answer is quite good. Here is part of its answer:
    Arduino PWM (Pulse Width Modulation) refers to the technique used by Arduino microcontrollers to simulate analog output using digital signals. PWM allows you to control the average voltage level delivered to a load by rapidly switching a digital output pin on and off at varying intervals. By adjusting the duty cycle (the percentage of time the signal is on versus off within each cycle), you can effectively control the power delivered to devices like LEDs, motors, or other actuators.
    In an Arduino, PWM is commonly used for tasks such as dimming LEDs, controlling the speed of DC motors, or generating analog voltage levels for interfacing with analog components. Although Arduino boards are digital devices, PWM enables them to interface with analog components and perform analog-like tasks.
    Arduino boards have built-in PWM capabilities on certain pins, which are marked with a "~" symbol on the board. These pins are capable of producing PWM signals using the analogWrite() function in Arduino IDE. The function takes two arguments: the pin number and the desired duty cycle, which ranges from 0 (always off) to 255 (always on).

  • @anagramfive
    @anagramfive 4 місяці тому

    Homework: In this class we learned that Arduino has the hability to "simulate" analog outputs in order to have a range of 256 levels of voltage in the PWM (Pulse Widht Modulation) pins intead of the digital ouput of only 0 or 5 volts (Low & High). The special pins PWM are marked with the symbol "~" beside of the pin number. The Pulse Widht Modulation consists not in make a variation in the ouput voltage, but in making a kind of average voltage by letting out 5V for a fraction of 2ms. This way we have a 256 fractions of every 2ms to emulate an output between 0-5 Volts. In this case when the analogWrite in a PWM pin = 0, we have an output of 0V. all the time. In tha case of analogWrite in a PWM pin = 255, we have a constant output of 5V. In between if we have a value of 128, we have 1ms High and 1ms Low (simulating an output of 2.5V.), and so on all the range...

  • @dorixlopte6026
    @dorixlopte6026 2 місяці тому

    if you want a output of 2,5 v the arduino don´t understand 2,5v he can only produce 0v and 5v, so the arduino switch in the half of a period off and the other half on. The average is 2,5v.

  • @PhilipStanway
    @PhilipStanway 5 місяців тому

    The lesson explained how to get an output with only zero and five volts to simulate any other voltage. The output of zero and five volts is switched in a defined period on and off so the average of the voltage over that period is the desired output voltage. For the Arduino this only works on output with a "~" and use of the analog write function.

  • @J-WafflezZ
    @J-WafflezZ 4 місяці тому

    Question, if the analogWrite is just PWM and the average is taken from the 2ms, why cant we get the same result from a digitalWrite if we manually average a 126 having a digitalWrite of HIGH with a 1ms delay and then a digitalWrite of LOW with another 1ms delay?
    Im sure im missing something here, im just not quite sure what it is...
    [edit] For those who have the same questions. If you use a digitalWrite with 1ms delays in between the HIGH and LOW, you can actually mimic an analogWrite at 126, its just not as efficient.

  • @mahanmotaghiraad1790
    @mahanmotaghiraad1790 Місяць тому

    So I believe we should use 1k resistors even if we are using a low voltage as it is actually implementing 5 volts. right?

  • @chrisallen2894
    @chrisallen2894 2 місяці тому

    🙏

  • @kenamosjr.bo_51
    @kenamosjr.bo_51 6 місяців тому

    I originally thought it would show up as the voltage value we wanted but remembered it only shows time/ frequency on scope as full voltage . The actual voltage needs read by meter and it will be the voltage we’re after. Been 45 yrs since high school electronics-Lol.

  • @fredvanderheyden6969
    @fredvanderheyden6969 5 місяців тому

    Hi Paul, I am a complete newbie, have been doing your tutorials in this series. Runing an Uno R3. All was going good till this session. I think I may have cooked two boards. I can't get past this message: "uploading error: exit status 1". Have tried reinstalling the IDE program, different cables to connect UNO, different Ports. Is there a way to test for u/s boards?

  • @ArthurCammers
    @ArthurCammers 17 днів тому

    With my Arduino Uno WIFI pin 12 (putative on PWM) behaves just like pin 11 (PWM) with output from analogWrite command.

  • @BerndRenzing
    @BerndRenzing 6 місяців тому

    Question:
    If I have an actor which supports v(max) 3V; could I use also PWM with 126 for this although the device gets 5 Volts for 1ms and then 0 Volts for the other ms.

    • @paulmcwhorter
      @paulmcwhorter  6 місяців тому

      Yes, you have to be cognizant of that PWM does produce a larger peak votage than the specified voltage, so you have to make sure that will not damage the component you are driving.

  • @RiteshKumar-vz5pz
    @RiteshKumar-vz5pz 6 місяців тому

    create a video, how to code esp32 and ram4m1 chip intependently without using any usb bridge, because when i program esp32 in arduino r4 wifi , the device goes always on ESP_Download mode, then we can't program ram4m1 chip then.
    please guide us how to access both chip independently

  • @coolguyfilms6631
    @coolguyfilms6631 3 місяці тому +2

    Hey paul 👋
    Please adopt me so i can be paul jr.
    Xoxo

  • @zrig1
    @zrig1 22 дні тому

    Is it odd that I am following an Arduino tutorial to learn my ESP32 ...

  • @wallypelech6181
    @wallypelech6181 6 місяців тому

    😅 27:35

    • @wallypelech6181
      @wallypelech6181 6 місяців тому

      If I wanted to analogwrite 120 only on the 1st time through the loop, what would the waveform look like after the first 2ms?

  • @richardsstark9825
    @richardsstark9825 6 місяців тому

    my homework ua-cam.com/video/3TOiPGM94Ak/v-deo.htmlsi=54MDc1G1MDxY8tfV
    In audio terms, the Arduino PWM pin generates a square wave of constant amplitude (peak to peak of approximately 5 volts) and constant frequency (wavelength of about 2 milliseconds, or 500Hz, corresponding to a musical note close to of B4). Modulating the pulse width by varying the analogWrite value in the code changes the average voltage as measured with a multimeter or LED brightness. This changes the timbre of the note without changing the frequency or amplitude.

  • @patrickfox-roberts7528
    @patrickfox-roberts7528 6 місяців тому

    Thanks Paul.