Skip to content

Commit 3962340

Browse files
authored
Merge pull request #3 from KAbhijeet2105/master
Added new example TemperatureAlert
2 parents d0b9aa5 + 1c6a6f5 commit 3962340

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
HTS221 - Temperature Alert
3+
This example reads data from the on-board HTS221 sensor of the
4+
Nano 33 BLE Sense. If the temperature increases above a certain limit, it turns the buzzer on.
5+
The circuit:
6+
- Arduino Nano 33 BLE Sense
7+
- Active buzzer module connected to pin 9 and GND
8+
9+
written by K.Abhijeet
10+
This example code is in the public domain
11+
*/
12+
13+
#include <Arduino_HTS221.h>
14+
15+
float tempLimit = 37; // set your temperature limit in °C
16+
17+
void setup() {
18+
Serial.begin(9600);
19+
while (!Serial);
20+
21+
pinMode(9, OUTPUT);
22+
23+
if (!HTS.begin()) {
24+
Serial.println("Failed to initialize humidity temperature sensor!");
25+
while (1);
26+
}
27+
}
28+
29+
void loop() {
30+
31+
float temperature = HTS.readTemperature(); // read the sensor value
32+
33+
Serial.print("Temperature = "); // print the sensor value
34+
Serial.print(temperature);
35+
Serial.println(" °C");
36+
37+
if (temperature > tempLimit)
38+
{
39+
digitalWrite(9, HIGH);
40+
delay(500);
41+
digitalWrite(9, LOW);
42+
delay(500);
43+
}
44+
else
45+
{
46+
delay(2000); // wait a while before displaying the next reading If the temperature is below the limit
47+
}
48+
}

0 commit comments

Comments
 (0)