LED Dimmer Lab

In the “Blink” example the frequency at which the LED blinked was controlled by the calls to the delay function. In this lab a potentiometer is used to increase and decrease the duty cycle of an external LED. Concepts introduced in this lab include wiring an external circuit to the 3DoT I2C connector, plus Arduino “analogWrite” and “map” functions.


This lab series is an adaptation of the Arduino “Analog In, Out Serial” Arduino Tutorial. The student will also be using the Arduino map function as described.

Build the Circuit

Hardware Needed:
● 3DoT board/Arduino Uno
● 470 Ω Resistor
● Jumper wires
● Breadboard
● Potentiometer

Figure 2.1: Fritzing breadboard graphic.

Connect the anode (the longer, positive leg) of the LED to an analog output pin on the board in series with a 470 Ω Resistor as shown in Figure 1.7. Connect the cathode (the shorter, negative leg) directly to ground. Then connect the potentiometer between ground, an analog pin and 3.3 volts.

Write the Arduino Program

After constructing the circuit in Figure 2.1 plug the Arduino board into a computer and open the Arduino Software (IDE) and enter the code described below and shown in Figure 2.2. Configure the out and in pins as you had selected.

Figure 2.2: Light_Dimmer code in Arduino IDE.

Using your knowledge of Arduino map, explain to yourself how the potentiometer controls the brightness of the LED.

Design Challenge ‐ DC Motor Controller

In this design challenge you are going to modify your dimmer program to control the speed of a DC motor plugged into to the Motor A connector on your 3DoT board.

Figure 2.3: Motor connection location on the 3DoT board.

Step 1: Redirect the analog output from the LED to the PWM input of Motor A.

const int analogOutPin = 9;

Step 2:  After studying the 3DoT Detail Block Diagram, modify the “setup” section of the Light_Dimmer program to configure the H‐Bridge so motor A turns in a clockwise (CW) direction.
Step 3: Upload your new motor control program and vary the speed of the motor using the potentiometer.