Tutorial 08: analogRead() and the Serial Port: Arduino Course for Absolute Beginners (ReM)



How to Use Analog Read on an Arduino Board

Steps

  1. Set up your Arduino Board and Circuit.
    • Plug in the Arduino into the computer
    • Set up a Circuit with a potentiometer, where the 5V pin is connected to the right pin of the potentiometer, the A0 pin is connected to the middle pin of the potentiometer, and left pin of the potentiometer is connected to ground.
    • Set up another circuit with an LED by connecting an LED with a 220 Ohm resistor to a digital I/O pin.
  2. Start Programming the Arduino.
    • Open the Arduino Software and make sure you're connected by clicking on Tools>Board. Set it as Arduino/Genuino UNO, click on Tools>Port and make sure you are connected to the port with Arduino on it.
  3. Program the Arduino (Void Setup).
    • Before the Void setup, initialize a variable as an integer by typing "int Value;"
    • "void setup()" is where functions are ran before the Arduino goes through a loop
    • In the void setup() set your pins by typing "pinMode(A0, INPUT);" and "pinMode(11, Output);".
    • This will initialize the pins. Pin A0 will become an analogue input and pin 11 becomes a digital output.
    • Pin A0 will read the voltage received from the circuit from 0V-5V and set it as a value between 0-1023. This is essentially 0.0049V per unit.
    • Type in "Serial.begin(9600)" to begin a serial connection.
    • This will allow you to read the values of the analog input in the loop
  4. Program the Arduino (Void Loop):Reading the Value
    • "void loop()" is where you're main code will go. This will continue to repeat while the Arduino is powered.
    • To read the voltage of the potentiometer type in the code "Value = analogRead(A0);"
    • This will read the voltage and set the variable as the voltage between the number 0-1023
    • To be able to view this value type in "Serial.printIn(Value);"
    • When running the code you can pull up the serial monitor by clicking Tools>Serial Monitor.
  5. Program the Arduino (Void Loop):Using the Value
    • To use the value, you can type an if/else statement after the code to read the value.
    • Type in "if (Value500) { digitalWrite(11, HIGH); }
    • This code means if pin A0 is reading a value lower than 500 pin 11 will turn off (The LED should not be lit), but if pin A0 reads a value higher than 500 pin 11 will turn on (The LED should be lit).
  6. Use the Code
    • To use the Arduino Code first compile the code by clicking "Verify". If you typed in everything correctly you should get no errors. If you get error, recheck your syntax.
    • Once the code is compiled upload the code in the Arduino by clicking "Upload".
    • Next open the Serial monitor by clicking "Tools>Serial Monitor" You should then see the value being read by the Arduino.
    • Try turning the potentiometer, this should change the value being seen in the monitor.
    • Try turning the potentiometer, so the light will turn off and on.
  7. Congrats you have now read values from a potentiometer and gave an output according to an input!





Video: Learning AVR-C Episode 8: Analog Input

How to Use Analog Read on an Arduino Board
How to Use Analog Read on an Arduino Board images

2019 year
2019 year - How to Use Analog Read on an Arduino Board pictures

How to Use Analog Read on an Arduino Board recommend
How to Use Analog Read on an Arduino Board forecast photo

How to Use Analog Read on an Arduino Board photo
How to Use Analog Read on an Arduino Board picture

How to Use Analog Read on an Arduino Board How to Use Analog Read on an Arduino Board new picture
How to Use Analog Read on an Arduino Board new pics

pictures How to Use Analog Read on an Arduino Board
foto How to Use Analog Read on an Arduino Board

Watch How to Use Analog Read on an Arduino Board video
Watch How to Use Analog Read on an Arduino Board video

Discussion on this topic: How to Use Analog Read on an , how-to-use-analog-read-on-an/
Discussion on this topic: How to Use Analog Read on an , how-to-use-analog-read-on-an/ , how-to-use-analog-read-on-an/

Related News


Penicillin G Potassium Reviews
What To Do If Your Kid Gets a Concussion During a Game
Celebrity Hairstyles: Kirsten Dunst Hairstyles
Jackie Collins: A Tribute To A Literary Icon
7 Style Lessons From Justin Theroux
A utility basket that can house towels, blankets, and pillows you use semi-frequently and folds up to a fraction of the size when you dont need it
How to Install a Car Seat
4 Ways to Recover
Schizophrenia Myths and Facts
I Do My Own Eyebrow Tinting at Home—Heres How
Hanging Straight-Leg Raise
Does Your Teen Have an Eating Disorder



Date: 04.12.2018, 08:35 / Views: 62234