#include <Adafruit_ADS1X15.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
const char* ssid = "Wokwi-GUEST";
const char* password = "";
Adafruit_ADS1015 ads;
void setup() {
WiFi.begin("Wokwi-GUEST", "");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
// initialize serial communication at 115200 bits per second:
Serial.begin(115200);
//set the resolution to 12 bits (0-4096)
analogReadResolution(12);
ads.begin();
}
void loop() {
int16_t adcValue;
float voltage;
// read the analog / millivolts value for pin 2:
int analogValue = analogRead(2);
int analogVolts = analogReadMilliVolts(2);
delay(100); // delay in between reads for clear read from serial
// Read from AIN0 (assuming your sensor is connected to A0)
adcValue = ads.readADC_SingleEnded(0);
// Convert ADC value to voltage
voltage = ads.computeVolts(adcValue);
HTTPClient http;
StaticJsonDocument<200> doc;
doc["analog"] = analogValue;
doc["name"] = "OleksandrH";
doc["date"] = "05-23-2024";
String output;
serializeJson(doc, output);
String url = "http://dweet.io/dweet/for/KNUS-11-05";
http.begin(url);
http.addHeader("Content-Type", "application/json");
int httpCode = http.POST(output);
if (httpCode > 0)
{
String payload = http.getString();
Serial.println(payload);
}
else
{
Serial.println("Error on HTTP POST request");
}
http.end();
// Print the result
Serial.print("ADC Value: "); Serial.print(adcValue);
Serial.print(" Voltage: "); Serial.print(voltage); Serial.print(" V");
Serial.print(" Analog Value: "); Serial.print(analogValue);
//Serial.print("ADC millivolts value = %d\n",analogVolts);
Serial.println(" ");
delay(1000); // Delay for readability, adjust as needed
}