File tree 1 file changed +48
-0
lines changed
examples/TemperatureAlert 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments