I'm in a bit over my head, and I'm not on Scuba.
This is my first Arduino Project, and it's not doing what I want it to. I did cheat, getting the code from ChatGPT. I want to read the pressure of my shop air compressor on my phone. It's set for 85psi to 130psi and I have it controlled by Alexa.
I'm using a 5V linear pressure sensor from Amazon. 0.5V=0psi and 4.5V=200psi. I have set the SSID and Password for my home network and have tried to push it to use an unused IP: .120. When I ping that, another IP (.96) pings back. Here is my sketch:
#include <WiFiS3.h>
// WiFi credentials
const char* ssid = "Heckawee";
const char* password = "4075090947";
// Static IP configuration
IPAddress local_IP(192, 168, 77, 120);
IPAddress gateway(192, 168, 77, 1);
IPAddress subnet(255, 255, 255, 0);
// Web server on port 80
WiFiServer server(80);
// Sensor settings
const int sensorPin = A0; // Analog pin for sensor
const float minVoltage = 0.5; // Minimum sensor voltage
const float maxVoltage = 4.5; // Maximum sensor voltage
const float minPSI = 0; // Minimum PSI
const float maxPSI = 200; // Maximum PSI
void setup() {
Serial.begin(115200);
// Connect to WiFi
WiFi.config(local_IP, gateway, subnet);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi...");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("\nWiFi connected.");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
server.begin();
}
void loop() {
WiFiClient client = server.available();
if (client) {
Serial.println("New client connected.");
String request = "";
while (client.available()) {
char c = client.read();
request += c;
if (c == '\n' && request.endsWith("\r\n\r\n")) break;
}
// Read sensor
int rawValue = analogRead(sensorPin);
float voltage = (rawValue / 1023.0) * 5.0;
float psi = ((voltage - minVoltage) / (maxVoltage - minVoltage)) * (maxPSI - minPSI);
// Send response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
client.println("<!DOCTYPE html><html><head><title>PSI Monitor</title></head><body>");
client.println("<h1>Pressure Sensor Data</h1>");
client.println("<p>Current PSI: " + String(psi, 2) + " PSI</p>");
client.println("</body></html>");
delay(10);
client.stop();
Serial.println("Client disconnected.");
}
}

