gdandrea97

Lab3 stm

Nov 15th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.39 KB | None | 0 0
  1. /*
  2.   Analog Input
  3.  
  4.   Demonstrates analog input by reading an analog sensor on analog pin 0 and
  5.   turning on and off a light emitting diode(LED) connected to digital pin 13.
  6.   The amount of time the LED will be on and off depends on the value obtained
  7.   by analogRead().
  8.  
  9.   The circuit:
  10.   - potentiometer
  11.     center pin of the potentiometer to the analog input 0
  12.     one side pin (either one) to ground
  13.     the other side pin to +5V
  14.   - LED
  15.     anode (long leg) attached to digital output 13
  16.     cathode (short leg) attached to ground
  17.  
  18.   - Note: because most Arduinos have a built-in LED attached to pin 13 on the
  19.     board, the LED is optional.
  20.  
  21.   created by David Cuartielles
  22.   modified 30 Aug 2011
  23.   By Tom Igoe
  24.  
  25.   This example code is in the public domain.
  26.  
  27.   http://www.arduino.cc/en/Tutorial/AnalogInput
  28. */
  29.  
  30. int sensorPin = A0;    // select the input pin for the potentiometer
  31. int ledPin = 13;      // select the pin for the LED
  32. int sensorValue = 0;  // variable to store the value coming from the sensor
  33.  
  34. void setup() {
  35.   // declare the ledPin as an OUTPUT:
  36.   pinMode(ledPin, OUTPUT);
  37.   Serial.begin(9600);
  38. }
  39.  
  40. void loop() {
  41.   // read the value from the sensor:
  42.   double cal = 5.079;
  43.   sensorValue = analogRead(sensorPin);
  44.   double voltValue = (sensorValue * cal) / 1024;
  45.   double celsiusValue = (voltValue * 100) - 273.15;
  46.   Serial.println(celsiusValue);
  47.   delay(500);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment