Arduino MEGA Board


LED (x4)

270 Ω Resistors (x4)



I followed along with the first half of Chapter 3 of Kassandra Perchs’ book, Learning JavaScript Robotics, which explored the differences between Digital and PWM Output Pins. The goals of this chapter were to:

  • Learn how GPIO pins work
  • Use multiple outputs with several LEDs

*all information below is paraphrased from Perchs’ book (linked under Resources)

General-Purpose Input/Output (GPIO) Pins

GPIO pins can either provide electrical current (output), or read it from the circuit (input). 

In this chapter, I looked at the two types of output pins: Digital output pins and PWM output pins.

Digital Output Pins

Digital output pins provide two levels of electrical current: on and off, HI and LOW, or 1 and 0. This means that it can only change a component into two different states. In terms of the LED, a Digital output pin could turn it on or off, or make it blink.

On the Arduino MEGA, pins 22-53 are Digital.

Pulse Width Modulation (PWM) Pins

PWM pins can sed varying levels of power… kind of. What’s happening is the pin still sends out HI/LOW signals, just at very quickly timed intervals to imitate varying power. PWN pins can be set between 0 and 255, which tells the pin how often to set current to HI. For example, when set to 0, the electrical current would be HI 0% of the time, so an LED would be off. When set to 85, the current would be HI 33.3% of the time, and the LED would appear at 33.3% brightness. 

On the Arduino MEGA, pins 2-13 are PWM pins.

In this video, you’ll notice that the LED is able to turn on, off, and blink. When I tried to make it pulse, there was an error. That is because a digital output pin is not able to vary the output current, so it can not vary the brightness of the led.

Looking at the differences between Digital and PWM pins through multiple LEDs

This is what the set up would look like on an Arduino Uno. For my board (MEGA), the Digital pins I used were 22 and 24 instead of 2 and 4.

This is the code I used to explore the Digital and PWM pins.