PWM Device Tester

Le Wed 21 March 2018

This is just a quick project that you may find useful. I put it together to carryout out a couple of tests;

  • I wanted to see if I could smooth or average a Pulse Width Modulated (PWM) signal. Result: Yes, I could change the shape of the signal but averaging it was impossible for most signals.
  • I wanted to test a selection of 2N2222A transistors that appeared to be behaving weirdly. Result: Yep, they were pretty weird. The pins were the reverse of the standard TO-92 package for an NPN transistor.

I'm sure it will be used again in the future for other small investigations.

The circuit shown is for testing a transistor. The LED is the load and a useful indicator of the output that won't stress the transistor. The button is used to step through a number of preset PWM signals. The PWM control pin is digital pin 6. Depending on the Arduino you are using you may need to change this to suit your board.

PWM Tester Circuit

Or for a breadboard layout.

PWM tester on a Breadboard

Here is the Arduino Code. Adjust the SigPin number to suit the PWM pin you are using. Most of the code within the Loop is a simple around to debounce the button presses. All it does is ignore any further presses of the button until 2 seconds has elapsed since the last press. Download the sketch from here: PWMSignalGeneratorv0.ino


 * A simple Tester for the PWM output of an Arduino Nano
 * to use on any components that require a PWM signal.
 * Pins are;
 * Momentary button on D12 using a pullup resistor
 * PWM output on Pin D6

int OutputSigList[] = {0,20,80,120,180,255}; //List of signals to step through

int SigPin = 6;
int ButtonPin = 12;

int SpdPointer = 0; //Pointer for the speed from OutputSigList
long TimePrevPress = 0; //Carrier for previous time of button press

void setup()


void loop()
  if(millis()-TimePrevPress>2000 && int(digitalRead(ButtonPin) == HIGH))
    TimePrevPress = millis();
    SpdPointer = SpdPointer + 1; //advance the pointer to next speed.
    if(SpdPointer > 5)
      SpdPointer = 0; //wrap around the pointer list.

This is the raw PWM signal on the oscilloscope.

PWM Signal on Oscilloscope

Par Hamish Trolove, Cat├ęgorie : Tech Projects

Tags : Arduino / Electronics /