# Need to generate 5 different PWN signals in Arduino UNO

**URL:** <https://forum.arduino.cc/t/need-to-generate-5-different-pwn-signals-in-arduino-uno/1085914>\
**Category:** Programming\
**Created:** [February 3, 2023, 11:02am UTC](https://forum.arduino.cc/t/need-to-generate-5-different-pwn-signals-in-arduino-uno/1085914 "2023-02-03T11:02:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![xiwom24001](https://avatars.discourse-cdn.com/v4/letter/x/df705f/32.png) [@xiwom24001](https://forum.arduino.cc/u/xiwom24001)\
**Post date:** [February 3, 2023, 11:02am UTC](https://forum.arduino.cc/t/need-to-generate-5-different-pwn-signals-in-arduino-uno/1085914/1 "2023-02-03T11:02:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sherzaad](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sherzaad/32/226173_2.png) [@sherzaad](https://forum.arduino.cc/u/sherzaad)\
**Post date:** [February 3, 2023, 11:07am UTC](https://forum.arduino.cc/t/need-to-generate-5-different-pwn-signals-in-arduino-uno/1085914/2 "2023-02-03T11:07:41Z")

</div>

have a look at this product:

> **[Adafruit 16-channel PWM/Servo Shield](https://learn.adafruit.com/adafruit-16-channel-pwm-slash-servo-shield)**
>
> This tutorial will help you get started with the Adafruit 16-channel servo/PWM shield. Great for powering 16 servos or PWM outputs for LEDs. This stackable design is easy to use and requires only 2 I2C pins on any Arduino.

hope that helps...

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [February 3, 2023, 11:09am UTC](https://forum.arduino.cc/t/need-to-generate-5-different-pwn-signals-in-arduino-uno/1085914/3 "2023-02-03T11:09:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gcjr](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gcjr/32/314015_2.png) [@gcjr](https://forum.arduino.cc/u/gcjr)\
**Post date:** [February 3, 2023, 12:24pm UTC](https://forum.arduino.cc/t/need-to-generate-5-different-pwn-signals-in-arduino-uno/1085914/4 "2023-02-03T12:24:29Z")

</div>

> [@groundFungus](#):
>
> It is just a square wave.

```arduino
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;
    }
}

```

---

<div class="post-metadata">

**Author:** ![johnwasser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnwasser/32/214270_2.png) [@johnwasser](https://forum.arduino.cc/u/johnwasser)\
**Post date:** [February 3, 2023, 12:34pm UTC](https://forum.arduino.cc/t/need-to-generate-5-different-pwn-signals-in-arduino-uno/1085914/5 "2023-02-03T12:34:39Z")

</div>

> [@xiwom24001](#):
>
> I need assistance in generating 5 different frequencies

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().

---

<div class="post-metadata">

**Author:** ![xiwom24001](https://avatars.discourse-cdn.com/v4/letter/x/df705f/32.png) [@xiwom24001](https://forum.arduino.cc/u/xiwom24001)\
**Post date:** [February 7, 2023, 6:17am UTC](https://forum.arduino.cc/t/need-to-generate-5-different-pwn-signals-in-arduino-uno/1085914/6 "2023-02-07T06:17:24Z")

</div>

Thank you all for all the solutions.

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

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [August 6, 2023, 6:17am UTC](https://forum.arduino.cc/t/need-to-generate-5-different-pwn-signals-in-arduino-uno/1085914/7 "2023-08-06T06:17:28Z")

</div>

Closed on August 6, 2023, 6:17am UTC

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