Wednesday, March 14, 2018

Analog Input with Arduino for beginners

What is Arduino Analog Input?

Analog signals are those signals having values without any restrictions (for example: 1.5 Volts, -5.06 Volts or 2.3 Volts)

Most signals in nature are Analog. That is audio signals are analog, temperature values are analog, speed of a motor is analog.

We need to read analog signals in Arduino to know their exact values to let Arduino take action about it.

For example, if you have a circuit to control temperature in a room, you must be able to read this room temperature to control it.

Also, if you are building a water level controller in a water tank you need to read water level in the tank.

And so on.

In the early days of electronics and Microcontrollers, designers had to put extra ICs called A/D converters (Analog to Digital Converters). That's because Microcontrollers only understand and process digital signals.


But in these days, Microcontrollers come with built in A/D converter which makes design more efficient in code and power usage.

Arduino also comes with internal A/D converters so it can read analog signals with no extra hardware. All you need is writing code(or calling the ready written libraries) for analog input.


Example Circuit:



This circuit is simply built with Arduino connected to potentiometer to make a variable voltage input(Analog Input) to Arduino.


When Arduino detects a change in analog input, it changes the rate at which the built in LED at pin 13 blinks.




 Arduino





 Arduino




This is the code that runs it:

/*
  Analog Input

  Demonstrates analog input by reading an analog sensor on analog pin 0 and
  turning on and off a light emitting diode(LED) connected to digital pin 13.
  The amount of time the LED will be on and off depends on the value obtained
  by analogRead().

  The circuit:
  - potentiometer
    center pin of the potentiometer to the analog input 0
    one side pin (either one) to ground
    the other side pin to +5V
  - LED
    anode (long leg) attached to digital output 13
    cathode (short leg) attached to ground

  - Note: because most Arduinos have a built-in LED attached to pin 13 on the
    board, the LED is optional.

  created by David Cuartielles
  modified 30 Aug 2011
  By Tom Igoe

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/AnalogInput
*/


int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);
  // turn the ledPin on
  digitalWrite(ledPin, HIGH);
  // stop the program for milliseconds:
  delay(sensorValue);
  // turn the ledPin off:
  digitalWrite(ledPin, LOW);
  // stop the program for for milliseconds:
  delay(sensorValue);
}






 



Paid Online Surveys
Check our books on Amazon we created on our way to find happiness.
A Trip To Siwa Oasis: Tourist guide to an Egyptian Oasis by [ElSakhawy, Sara M.]

A Trip To Siwa Oasis

The Ultimate travel bag list by [ Elskhawy, Sara M.]

No comments: