Skip to content

Added new example TemperatureAlert #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions examples/TemperatureAlert/TemperatureAlert.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
HTS221 - Temperature Alert
This example reads data from the on-board HTS221 sensor of the
Nano 33 BLE Sense. If the temperature increases above a certain limit, it turns the buzzer on.
The circuit:
- Arduino Nano 33 BLE Sense
- Active buzzer module connected to pin 9 and GND

written by K.Abhijeet
This example code is in the public domain
*/

#include <Arduino_HTS221.h>

float tempLimit = 37; // set your temperature limit in °C

void setup() {
Serial.begin(9600);
while (!Serial);

pinMode(9, OUTPUT);

if (!HTS.begin()) {
Serial.println("Failed to initialize humidity temperature sensor!");
while (1);
}
}

void loop() {

float temperature = HTS.readTemperature(); // read the sensor value

Serial.print("Temperature = "); // print the sensor value
Serial.print(temperature);
Serial.println(" °C");

if (temperature > tempLimit)
{
digitalWrite(9, HIGH);
delay(500);
digitalWrite(9, LOW);
delay(500);
}
else
{
delay(2000); // wait a while before displaying the next reading If the temperature is below the limit
}
}