Commit 8992ab7e authored by austin.blanke's avatar austin.blanke

Initial commit

parents
#include <WiFiNINA.h>
#include "arduino_secrets.h"
#include "ThingSpeak.h"
#include <math.h>
#include <Servo.h>
#define TS_ENABLE_SSL
Servo myservo;
unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;
char ssid[] = SECRET_SSID;
char usrnm[] = SECRET_USRNM;
char pass[] = SECRET_PASS;
WiFiClient client;
int a;
float temperature;
int B=3975; //B value of the thermistor
float resistance;
float tempThreshold = 21;
void setup()
{
Serial.begin(9600);
myservo.attach(4);
myservo.write(130);
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
while (true);
}
ThingSpeak.begin(client); //Initialize ThingSpeak
Serial.println("");
Serial.println("");
Serial.print("Temperature threshold is ");
Serial.println(tempThreshold);
Serial.println("");
Serial.println("");
}
void loop()
{
a=analogRead(0);
resistance=(float)(1023-a)*10000/a; //get the resistance of the sensor;
temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;//convert to temperature via datasheet&nbsp;;
// Connect or reconnect to WiFi
if(WiFi.status() != WL_CONNECTED){
Serial.print("Attempting to connect to SSID: ");
Serial.println(SECRET_SSID);
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(ssid, pass);
Serial.print(".");
delay(6000);
}
Serial.println("\nConnected.");
}
int x = ThingSpeak.writeField(myChannelNumber, 1, temperature, myWriteAPIKey);
if(x == 200){
Serial.println("Channel Temp updated");
}
else{
Serial.println("Error: " + String(x));
}
if(temperature < tempThreshold){
myservo.write(100); // sets the servo position according to the scaled value
delay(2000);
myservo.write(130);
Serial.println("Servo Activated!");
delay(300000);
}
Serial.print("Current temperature is ");
Serial.println(temperature);
delay(15000);
}
#define SECRET_SSID "ASK4 Wireless"
#define SECRET_USRNM ""
#define SECRET_PASS ""
#define SECRET_CH_ID "2401626"
#define SECRET_WRITE_APIKEY "6DEH0JTDYDX6MHKX"
#define SECRET_READ_APIKEY "Y4U4Z6P3BCTQIXA5"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Change Setpoint</title>
</head>
<body>
<div>
<h1>Current Room Temp</h1>
<iframe width="450" height="260" style="border: 1px solid #cccccc;" src="https://thingspeak.com/channels/2401626/widgets/784926"></iframe>
</div>
<div>
<h1>Room Temperature Over Time</h1>
<iframe width="450" height="260" style="border: 1px solid #cccccc;" src="https://thingspeak.com/channels/2401626/charts/1?bgcolor=%23ffffff&color=%23d62020&dynamic=true&results=60&type=line&update=15"></iframe>
</div>
</body>
</html>
\ No newline at end of file
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