Arduino Tutorial 03: Analog Inputs

Welcome to the third Arduino Tutorial from our Arduino Tutorial Series. In this tutorial we will learn how the Arduino Analog Inputs pins work and make few examples using a potentiometer and a photocell.

This is a Step by Step Video Tutorial which is easy to be followed. Also, below the video you can find what Parts do we need for this tutorial and the Source Codes of the Examples in the video.

Components needed for this Arduino Tutorial


  •  Arduino Board – [Get One]
  • Breadboard and Jump Wires – [Get One]
  • Potentiometer
  • Photocell (Photo-resistor)
  • LED
  • 220 & 10k Ohm Resistors

Circuit schematic of the first example. Using the potentiometer value as analog input


Analog Inputs Circuit Schematic 01

Circuit schematic of the second example. Using the photocell as a voltage divider and it’s variable value as analog input


Analog Inputs Circuit Schematic 02

Source Code of the first and the second example


void setup() {
Serial.begin(9600);
}

void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);

Circuit schematic of the third example. Using the potentiometer to control the LED brightness via PWM


Analog Inputs Circuit Schematic 03

Source Code of the third example


int led = 7;

void setup() {
Serial.begin(9600);
pinMode(led, OUTPUT);
}

void loop() {
int sensorValue = analogRead(A0);
int newValeu = map(sensorValue, 0, 1023, 0, 255);
analogWrite(led, newValeu);
}

2 Responses

Leave a Reply

Your email address will not be published.