forked from Kairos-T/Temp-Dist-Measurement
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SMP_Code.ino
31 lines (22 loc) · 807 Bytes
/
SMP_Code.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <NewPing.h>
#define TRIGGER_PIN 9
#define ECHO_PIN 10
#define MAX_DISTANCE 140
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
const int temperaturePin = A0;
void setup() {
Serial.begin(9600); // Starts the serial communication
}
void loop() {
int analogValue = analogRead(temperaturePin);
float temperatureCelsius = map(analogValue, 0, 1023, -40, 125);
float temperatureKelvin = temperatureCelsius + 273.15;
Serial.print("Temperature: ");
Serial.print(temperatureKelvin);
Serial.print(" K");
unsigned int distance = sonar.ping_median(); // Do multiple pings (default=5), discard out-of-range pings, and return median in microseconds
Serial.print(" Distance: ");
Serial.print(distance);
Serial.println(" mm");
delay(1000);
}