By

Arduino Learning #2: digitalWrite, analogWrite, and which pins are which.

Without knowing how to use the pins on the Arduino board, you basically just have a fancy battery.

Here we can see the pins. There are three sections

  1. Digital Output
  2. Analog Input
  3. Power

Try and find all three sections.

Now look closely at the digital pin section. Some pins have a ~ next to them. This means that they are capable of acting as an analog output or PWM. We can use the pins in this section for sending out data, to do things such as control motors and LED's, write things to a screen, or even send us a tweet when our plants need to be watered.

In the section labeled "Analog" we see there isn't a lot of variation in the markings. All these pins do is read data. For example if you wired a circuit with a thermistor connected to you analog input, you could very easily make a thermometer.

Under the power section we can see a few grounds, a 3.5V, a 5V, and a reset. If you know a little bit about basic electronic circuits this should be pretty straightforward.

About analogWrite()

In your code, you can use a function called analogWrite, which will simply output a given amount of voltage to the pin you specify. To use analogWrite, you specify an analog output pin, meaning it has a ~ next to it, and a value between 0 and 255 for the amount of output.

analogWrite() Example

Imagine there is an LED attached to pin 3. ``` // Put code inside the loop() function so that our program will keep running. void loop() {

// Turn on the LED
analogWrite(3, 255);

// Wait 1 second (1000) milliseconds
delay(1000);

delay(1000);
analogWrite(3, 0);

} ``` This code will cause the LED to turn on and off every second.

digitalWrite() Example

You probably won't be using digitalWrite unsupervised for quite some time, because it generally requires knowledge of integrated circuits, but for your reference, you can use digitalWrite() on any digital pin be writing

digitalWrite(pin_number, HIGH);

// OR

digitalWrite(pin_number, LOW);

HIGH and LOW are what we call constants in Arduino

Written by
Programmer, Entrepreneur, Startup Enthusiast