Created
February 13, 2014 12:10
-
-
Save phodal/8973993 to your computer and use it in GitHub Desktop.
arduino with hc-sr04 lm35
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int trigPin = 13; | |
const int echoPin = 12; | |
float temp; | |
int tempPin = 0; | |
void setup() { | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
long duration, inches, cm; | |
pinMode(trigPin, OUTPUT); | |
digitalWrite(trigPin, LOW); | |
delayMicroseconds(2); | |
digitalWrite(trigPin, HIGH); | |
delayMicroseconds(10); | |
digitalWrite(trigPin, LOW); | |
pinMode(echoPin, INPUT); | |
duration = pulseIn(echoPin, HIGH); | |
cm = microsecondsToCentimeters(duration); | |
Serial.print(cm); | |
Serial.print("cm"); | |
Serial.println(); | |
temp = analogRead(tempPin); | |
temp = temp * 0.48828125; | |
Serial.println(temp); | |
delay(1000); | |
} | |
long microsecondsToInches(long microseconds) | |
{ | |
return microseconds / 74 / 2; | |
} | |
long microsecondsToCentimeters(long microseconds) | |
{ | |
return microseconds / 29 / 2; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment