Using the LED and Knob

Once you're comfortable controlling the vibrator motor itself, you can add functionality to your programs by using the LED and knob included on the Master Beta Shield. Now, instead of just writing to pin 5, we'll be writing to pin 13 (the LED) and reading from pin A2 (the knob).

Note: It might seem weird, but in Arduino, A2 is an integer just like 1, 2, and 200.

Some new functions we'll be using are:

  • digitalWrite(pinNumber, HIGH/LOW)

    Setting whatever is connected to pinNumber to HIGH will turn it on, while LOW will turn it off, with no settings in between.

  • analogRead(pinNumber)

    Returns an integer from some input device connected to the pinNumber.

LED! (pin 13)


The LED is a digital pin, whereas the vibrator motor is an analog pin. This means that while we have many different settings on the vibrator between off and vibrating at maximum speed, the LED can only be "on" or "off."

Try writing a program that turns the LED on whenever the vibrator is vibrating, and turns it off whenever the vibrator is off. We'll need to declare the LED pin as an output with pinMode in the setup like we did with the vibrator.

Knob! (pin A2)


The knob at pin A2 is an analog input pin. This means that we can't set any values for it, just read it's current state, which can have many different settings. Unlike the vibrator motor, an analog output pin which can be set from 0 to 255, the knob goes between 0 and 1023.

  • Write a program that reads the current setting on the knob and adjusts the vibration speed accordingly. This will allow us to change the vibration speed in real time like some of the fanciest vibrators out there. Remember that the knob has a different range of numbers than the vibration motor.
  • Let's put the LED and knob to good use together. Change the program so that the LED can be off (no vibration is happening), on (the vibrator is on), or blinking (the vibrator is changing speed).