Versions of the board
Versions of Board || Digital pins || Analog Pins || Serial Communication || I2C || Power Input || Breadboard
13 Digital pins
The 13 digital pins on Arduio can be used as both inputs and outputs depending on how you set them up in the coding. Digital pins are either ON or OFF and can have no in between states; just like a regular light switch. We also use the terms 'HIGH and LOW' or '1 and 0' when talking about that is happening on the digital pins.
Pin 13 - the test Pin
Pin 13 is special as it has an LED attached to it, it is marked as 'l' on the board. You can turn this on and off in coding and it allows you to quickly test if things are working correctly without having to add additional indicator lights.
Digital Input Uses
Inputs like switches or sensors that send an ON or OFF signal to a physical condition. The flame sensor for example has the ability to send a digital HIGH signal when there is enough IR heat to pass a threshold. (this threshold is set directly on the sensor board by the user using a small screwdriver).
There are many things which can attach to the digital outputs, one of the most common is an LED.
The LED's need to be wired up and connected to the board using a resistor that limits the current.
It is also common to use these pins for controlling larger more powerful devices (including mains level electricity) using relays.
Pulse Width Modulation is available on the pins with a little squiggle '~' next to them. These pins are special as they allow you to turn on and off the pin for a percentage of a very fast cycle.
Look at the diagram on the left, while the graph is at the maximum the pin is HIGH/ON; if it were connected to an LED the light would be emitted during this HIGH time. As the cycle is so fast it would not appear to flicker to the human eye, but appear dimmer.
We use this PWM to control motor power and servo angle.
Reading the value of a pin
This example finds out if the pin is HIGH or low (1 OR 0)
Writing the value of a pin
This example finds sets the value of pin 13 to HIGH/ON/1
Writing the value of a PWM pin
This example finds sets the value of pin 11 to '127'
PWM of 0 = 0 % cycle
PWM of 255 = 100 % cycle
so setting PWM or 127 is a 50% ON 50% OFF cycle - half power
You will notice the analogWrite function is used here as it is not a simple HIGH or LOW value