-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBastWAN_Continuous_Ranging.ino
96 lines (92 loc) · 3.16 KB
/
BastWAN_Continuous_Ranging.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "Seeed_vl53l0x.h"
#include "DHT12.h"
#include <Wire.h> //The DHT12 uses I2C comunication.
#include <SparkFunMLX90614.h> //Click here to get the library: http://librarymanager/All#Qwiic_IR_Thermometer by SparkFun
DHT12 dht12; //Preset scale CELSIUS and ID 0x5c.
Seeed_vl53l0x VL53L0X;
IRTherm therm; // Create an IRTherm object to interact with throughout
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
#define SERIAL SerialUSB
#else
#define SERIAL Serial
#endif
uint8_t hitCounts = 0;
void setup() {
analogReference(AR_DEFAULT); //set the reference voltage 1.1V,the distinguishability can up to 1mV.
VL53L0X_Error Status = VL53L0X_ERROR_NONE;
SERIAL.begin(115200);
SERIAL.flush();
delay(3000);
SERIAL.println("\n\nContinuous ranging...");
pinMode(A0, OUTPUT);
analogWrite(A0, 0);
Status = VL53L0X.VL53L0X_common_init();
if (VL53L0X_ERROR_NONE != Status) {
SERIAL.println("start vl53l0x mesurement failed!");
VL53L0X.print_pal_error(Status);
while (1);
}
VL53L0X.VL53L0X_continuous_ranging_init();
if (VL53L0X_ERROR_NONE != Status) {
SERIAL.println("start vl53l0x mesurement failed!");
VL53L0X.print_pal_error(Status);
while (1);
}
Wire.begin(); //Join I2C bus
SERIAL.print("IR thermometer ");
if (therm.begin() == false) {
// Initialize thermal IR sensor
SERIAL.println("did not acknowledge! Freezing!");
while (1);
}
SERIAL.println("acknowledged.");
therm.setUnit(TEMP_C); // Set the library's units to Celsius
if (therm.readID()) {
// Read from the ID registers
// If the read succeeded, print the ID:
Serial.println("ID: 0x" + String(therm.getIDH(), HEX) + String(therm.getIDL(), HEX));
}
Serial.println(String(therm.readEmissivity()));
}
void loop() {
float ds;
VL53L0X_RangingMeasurementData_t RangingMeasurementData;
VL53L0X.PerformContinuousRangingMeasurement(&RangingMeasurementData);
if (RangingMeasurementData.RangeMilliMeter >= 2000) {
//SERIAL.println("out of range");
} else {
ds = RangingMeasurementData.RangeMilliMeter / 10.0;
if (ds < 15.0) {
hitCounts += 1;
if (hitCounts == 10) {
SERIAL.print("distance: ");
SERIAL.print(ds);
SERIAL.println(" cm");
analogWrite(A0, 255);
SERIAL.println("\nSwitching on!");
SERIAL.print(" . T: "); SERIAL.print(dht12.readTemperature()); SERIAL.println(" C");
SERIAL.print(" . H: "); SERIAL.print(dht12.readHumidity()); SERIAL.println("%");
if (therm.read()) {
// On success, read() will return 1, on fail 0.
// Use the object() and ambient() functions to grab the object and ambient
// temperatures.
// They'll be floats, calculated out to the unit you set with setUnit().
Serial.print("Object: " + String(therm.object(), 2));
Serial.println("* C");
Serial.print("Ambient: " + String(therm.ambient(), 2));
Serial.println("* C");
}
}
} else {
// SERIAL.print("distance: ");
// SERIAL.print(ds);
// SERIAL.println(" cm");
if (hitCounts > 0) {
analogWrite(A0, 0);
hitCounts = 0;
SERIAL.println("\nSwitching off!");
}
}
}
delay(100);
}