Sunday, August 7, 2016

Analog Read Serial

Analog Read Serial

       Before you start to write programs you should download the relevant compiler.  To download the compiler before you should check the version according to your computer/ Your operating system. Assume your computer has Windows Operating System, You should download the Windows Installer.  
       After install the compiler successfully connect Arduino device to the computer.
Then open the compiler, If it successfully connected you will see the device name under the left-hand side down corner. go to Tools -> Port. Then you will see the port number connected to the device. 

       This program is about 
  • Reads an analog input on pin 0, prints the result to the serial monitor.
  • Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
  •  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

void setup() { // initialize serial communication at 9600 bits per second: 
  Serial.begin(9600);
}

void loop() {// the loop routine runs over and over again forever:
  int sensorValue = analogRead(A0);  // read the input on analog pin 0: 
  Serial.println(sensorValue); // print out the value you read:
  delay(1);        // delay in between reads for stability
}

To demonstrate that program we connect LM35 temperature sensor to thr A0 port.
Then go to Tools -> serial Plotter, you will see the temperature value on it.

No comments:

Post a Comment