Intro to topic :
It is sometimes essential to us read the analog value from different sensors and Shields in order to perform certain tasks let see resistance change in some path or voltage drops of some sort. So in arduino you can read analog quantities directly without any external hardware.
Hardware needed :
- Arduino UNO board
- Bread board
- Jumper wires
- PC on which the arduino IDE is installed
- Variable resisters (Potentiometers)
Steps to follow :
- First of All complete the circuit as below
- Connect the one pin of POT to Arduino Pin A0 and other pins to 5V and GND respectively.
- Connect the arduino board to PC and open up the software.
- Goto file>examples>01.basic>Analog read serial.
- After opening it upload this code to your board and then wait for uploading.
- Now open Up serial monitor from tools>serial monitor Or simply press Ctrl+Shift+M.
- You will see that there will be list of values going on in Serial monitor screen once you get this.
- Change the POT value by moving its knob to some other point as you change the value on serial monitor will automatically change.
Code to Upload :
*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor.
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
*/
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(1); // delay in between reads for stability
}
No comments:
Post a Comment