This project shows you how to build a temperature alert system that will allow you to manually trigger a fan to turn on or off from hyper links.
NOTE:
This project can be a bit “quirky” as written. Auto refresh does not work well on Google Chrome. This should be taken purely as a learning experiment, and not something to be copy/pasted to a real environment.
Functional Parts in the Project:
- Arduino WiFi Rev 2 – https://store.arduino.cc/usa/arduino-uno-wifi-rev2
- L298N Motor Module – https://amzn.to/2Xa9uiR
- 200mm 12v Fan – https://amzn.to/2X40nQt
- Analog Temperature Sensor – https://amzn.to/2Rkkl3k
- Breadboard Kit – https://amzn.to/2Xih5ei
- 560 Piece Jumper Wire Kit – https://amzn.to/2MsCLjL
- DC 2.1mm Power Adapter – https://amzn.to/2xzn5kk
- 12V 2A Power Supply – https://amzn.to/2Xv3GM0
#include <SPI.h>
#include <WiFiNINA.h>
#define tempSensor A5
#define enA 8
#define in1 9
#define in2 10
char ssid[] = "test";
char pass[] = "";
int keyIndex = 0;
int status = WL_IDLE_STATUS;
WiFiServer server(80);
String readString;
int highTemp = 82;
int goodTemp = 76;
void setup() {
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
analogWrite(enA, 255);
Serial.begin(9600);
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to Network named: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
delay(10000);
}
server.begin();
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
}
void loop() {
int reading = analogRead(tempSensor);
float voltage = reading * 5;
voltage /= 1024.0;
float temperatureC = (voltage - 0.5) * 100 ;
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
WiFiClient client = server.available();
if (client) {
Serial.println("new client");
while (client.connected())
{
if (client.available())
{
char c = client.read();
if (readString.length() < 100)
{
readString += c;
Serial.write(c);
if (c == '\n') {
client.println("<head><meta http-equiv=\"refresh\" content=\"5\"></head>");
if (temperatureF >= highTemp) {
client.print("<h1 style=\"color:red; font-size:400px; margin-bottom: 10px;\">");
client.print(temperatureF);
client.println("</h1>");
client.println("<a href=\"/?fanon\"\">Turn On Fan</a>");
client.println("<br />");
client.println("<br />");
client.println("<a href=\"/?fanoff\"\">Turn Off Fan</a><br />");
}
else if (temperatureF < highTemp && temperatureF >= goodTemp) {
client.print("<h1 style=\"color:yellow; font-size:400px; margin-bottom: 10px;\">");
client.print(temperatureF);
client.println("</h1>");
client.println("<a href=\"/?fanon\"\">Turn On Fan</a>");
client.println("<br />");
client.println("<br />");
client.println("<a href=\"/?fanoff\"\">Turn Off Fan</a><br />");
}
else {
client.print("<h1 style=\"color:green; font-size:400px; margin-bottom: 10px;\">");
client.print(temperatureF);
client.println("</h1>");
client.println("<a href=\"/?fanon\"\">Turn On Fan</a>");
client.println("<br />");
client.println("<br />");
client.println("<a href=\"/?fanoff\"\">Turn Off Fan</a><br />");
}
delay(1);
if (readString.indexOf("?fanon") > 0)
{
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
delay(1);
}
else {
if (readString.indexOf("?fanoff") > 0)
{
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
delay(1);
}
}
readString = "";
delay(1);
client.stop();
Serial.println("client disonnected");
}
}
}
}
}
}
Be the first to comment