Skip to content

Commit e049e1b

Browse files
committed
Added new example TemperatureAlert
1 parent 0f309b2 commit e049e1b

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
-Buzzer module connected at pin 9
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+
if (temperature > tempLimit)
34+
{
35+
digitalWrite(9, HIGH);
36+
delay(500);
37+
digitalWrite(9, LOW);
38+
delay(500);
39+
}
40+
else
41+
{
42+
digitalWrite(9, LOW);
43+
delay(2000);
44+
}
45+
Serial.print("Temperature = "); // print the sensor value
46+
Serial.print(temperature);
47+
Serial.println(" °C");
48+
49+
}

0 commit comments

Comments
 (0)