Need to generate 5 different PWN signals in Arduino UNO

Hi All,

I need assistance in generating 5 different frequencies like 10, 20, 30, 40, and 50Hz with 50% duty cycle respectively in the Arduino Uno PWM pins, as I'm new to programming having difficult to use PWM pins, can anyone guide.

Thanks in advance

have a look at this product:

hope that helps...

A waveform that is set (stuck) at 50% duty cycle does not need PWM. It is just a square wave. Do your search for "arduino generate a square wave". Then you can use any pins.

struct Sig {
    unsigned      freqHz;
    const byte    Pin;
    unsigned long msecPeriod;
    unsigned long msecLst;
};

Sig sigs [] = {
    { 10, 13 },
    { 20, 12 },
    { 30, 11 },
    { 40, 10 },
    { 50,  9 },
};
const unsigned Nsigs = sizeof(sigs) / sizeof(Sig);

void
loop (void)
{
    unsigned msec = millis ();

    Sig *p = sigs;
    for (unsigned n = 0; n < Nsigs; n++, p++)  {
        if (msec - p->msecLst >= p->msecPeriod)  {
            p->msecLst = msec;
            digitalWrite (p->Pin, !  digitalRead (p->Pin));
        }
    }
}

void
setup (void)
{
    Serial.begin (9600);

    Sig *p = sigs;
    for (unsigned n = 0; n < Nsigs; n++, p++)  {
        pinMode (p->Pin, OUTPUT);
        p->msecPeriod = 1000 / p->freqHz;
    }
}

The UNO only has three hardware timers for generating frequencies. At such low frequencies, you can use software and any pins you like. Start with the "BlinkWithoutDelay" example. For more precise timing you can switch to micros().

Thank you all for all the solutions.

@gcjr, this is what I was looking, thank you.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.