DiQ

Untitled

DiQ
Dec 3rd, 2015
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. /*
  2. ReadAnalogVoltage
  3. Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
  4. Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
  5. Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
  6.  
  7. This example code is in the public domain.
  8. */
  9.  
  10. // the setup routine runs once when you press reset:
  11. void setup() {
  12. // initialize serial communication at 9600 bits per second:
  13. Serial.begin(9600);
  14. }
  15.  
  16. // the loop routine runs over and over again forever:
  17. void loop() {
  18. // read the input on analog pin 0:
  19. int sensorValue = analogRead(A0);
  20. // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  21. float voltage = sensorValue * (5.0 / 1023.0);
  22. // print out the value you read:
  23. Serial.println(voltage);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment