Commit e8d5d660 authored by elijah vasquez's avatar elijah vasquez 🦍

push

parents
#include <SPI.h>
#include <WiFiNINA.h>
#include <ThingSpeak.h>
#include <math.h>
// Internet capability
WiFiClient client;
char ssid[] = "VM0729577";
char pass[] = "fch2sfdgCrS9";
int status = WL_IDLE_STATUS;
// ThingSpeak connectivity
unsigned long channelNo = 2401967;
const char * writeAPI = "Y4XA01Y4PZSJXXJB";
// Definitions
const int B = 4275; // B value of the thermistor
const int R0 = 100000; // R0 = 100k resistance
const int pinTempSensor = A0; // Sensor connected at A0
const int buzzerPin = 4; // Buzzer pin
const int ledPin = 3; // LED pin
// Debug for Serial
#if defined(ARDUINO_ARCH_AVR)
#define debug Serial
#elif defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
#define debug SerialUSB
#else
#define debug Serial
#endif
// Buzzer sound
#define TONE_1 100
void setup()
{
Serial.begin(9600);
WiFi.begin(ssid, pass);
ThingSpeak.begin(client);
}
void loop()
{
int a = analogRead(pinTempSensor);
float R = 1023.0 / a - 1.0;
R = R0 * R;
// Kelvin to Celsius
// Due to undervolting of 5V pin (4.95V), actual temperature is
// 5 degrees Celsius higher than normal, so a calibration
// of -5 was made
float temp = 1.0 / (log(R / R0) / B + 1 / 293.15) - 273.15;
Serial.println(F("TEMPERATURE "));
Serial.println(temp);
delay(3000);
// main device function
if (temp > 24 || temp < 15)
{
// 2 quick flashes and beeps every 3 seconds
digitalWrite(ledPin, HIGH);
digitalWrite(buzzerPin, HIGH);
tone(buzzerPin, TONE_1);
delay(100);
noTone(buzzerPin);
digitalWrite(ledPin, LOW);
digitalWrite(buzzerPin, LOW);
delay(100);
digitalWrite(ledPin, HIGH);
digitalWrite(buzzerPin, HIGH);
tone(buzzerPin, TONE_1);
delay(100);
noTone(buzzerPin);
digitalWrite(ledPin, LOW);
digitalWrite(buzzerPin, LOW);
delay(3000);
}
// LED will flash but no sound when under comfort level
else if (temp < 19)
{
digitalWrite(ledPin, LOW);
delay(100);
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(100);
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(100);
digitalWrite(ledPin, HIGH);
delay(3000);
}
// LED will stay on when idle
else
{
digitalWrite(ledPin, HIGH);
}
ThingSpeak.setField(1,temp);
ThingSpeak.writeFields(channelNo, writeAPI);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment