Difference between analogWrite and digitalWrite

Discussion in 'Programmer's Corner' started by brave_guy, Sep 25, 2014.

  1. brave_guy

    Thread Starter New Member

    Sep 11, 2014
    Hi People,

    Can somebody tell me how "analogWrite" differ from "DigitalWrite" ? In which circumstances should we pick one of them if it makes too much difference?

  2. sirch2

    Well-Known Member

    Jan 21, 2013
    I take it you are talking about Arduino analogWrite?

    If so I'll save you the trouble of just Googling it and tell you that they are very different, so just use digitalWrite unless you know that you really need analogWrite. analogWrite sends a pulsed output via the PWM pins and so can be used to dim an LED or passed through a filter to produce a voltage other than the digital high voltage.
  3. tshuck

    Well-Known Member

    Oct 18, 2012
    It would be good if you mentioned that this is for an Arduino, as some may be confused with undefined language such as "digitalWrite".

    With that said, the Arduino website helps and is the first result when searching for those exact terms:
    As you can see from the documentation, analogWrite is a Pulse-Width Modulated (PWM) signal, where digitalWrite produces a constant HIGH or LOW.
  4. brave_guy

    Thread Starter New Member

    Sep 11, 2014
    Dear tshuck and sirch2,
    As you guessed, the question was for Arduino.
    I think I understood now.