User Tools

Site Tools


amc:ss2025:group-g:start

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
amc:ss2025:group-g:start [2025/07/29 22:53] – [References] 29478_students.hsrwamc:ss2025:group-g:start [2025/07/29 23:57] (current) – [Explanation Video] 29478_students.hsrw
Line 65: Line 65:
  
  
-The prototype (Figure 3.1) successfully read the data collected from the sensors and sent it over MQTT to the Ubidots MQTT broker; the data received by the server was then available to be displayed in the dashboard (Figure 3.2). The air temperature and humidity sensor used was a DHT11 unit since it showed more accurate results than the DHT22 unit available when compared to a more expensive reference unit. The microcontroller used was the ESP32S3 connected directly to the host computer, since the more specific board did not function as intended, as will be discussed in the next chapter.+The prototype (Figure 3.1) successfully read the data collected from the sensors and sent it over MQTT to the Ubidots MQTT broker; the data received by the server was then available to be displayed in the dashboard (Figure 3.2). The air temperature and humidity sensor used was a DHT11 unit since it showed more accurate results than the DHT22 unit available when compared to a more expensive reference unit. The microcontroller used was the ESP32S3 connected directly to the host computer, since the more specific board did not function as intended, as will be discussed in the next chapter.  
 +  
 +The code developed for it is shown below with comments where needed.
    
 {{ :amc:ss2025:group-g:img_5119.jpeg?700 |Figure 3.1: Prototype smart weather station using a breadboard.}}  {{ :amc:ss2025:group-g:img_5119.jpeg?700 |Figure 3.1: Prototype smart weather station using a breadboard.}} 
Line 72: Line 74:
 {{ :amc:ss2025:group-g:screenshot_2025-07-29_at_12.34.24.png?800 |Figure 3.2: Ubidots dashboard showing the measurements so far, as well as the variable names and devices in use.}} {{ :amc:ss2025:group-g:screenshot_2025-07-29_at_12.34.24.png?800 |Figure 3.2: Ubidots dashboard showing the measurements so far, as well as the variable names and devices in use.}}
  
 +<code>#include <DHT.h>
 +#include <WiFi.h>
 +#include <MQTTClient.h>
 +#include <UbidotsESPMQTT.h>
 +
 +// Defining sensor variables
 +#define DHTPIN 4
 +#define DHTTYPE DHT11
 +#define SOILPIN 5
 +#define LDRPIN 6
 +DHT dht(DHTPIN, DHTTYPE);
 +
 +// Defining MQTT/Dashboard variables
 +#define TOKEN "BBUS-elnIUM3JpLzaEsk3gpvkznDG8GCZUV"
 +#define WIFINAME "FRITZ!Box 7520 TE_EXT"
 +#define WIFIPASS "Coffee.Luna"
 +#define DEVICE_LABEL "esp32-mcu"
 +#define VAR_LABEL_1 "air_temp"
 +#define VAR_LABEL_2 "air_hum"
 +#define VAR_LABEL_3 "soil_moist"
 +#define VAR_LABEL_4 "light_int"
 +Ubidots client(TOKEN);
 +bool connected = false;
 +
 +// Defining sleep variables
 +#define uS_FACTOR 1000000
 +#define PUBLISH_FREQUENCY 60
 +RTC_DATA_ATTR int bootCount = 0;
 +
 +const int airStd = 3550;
 +const int waterStd = 1560;
 +int soilMoistPerc = 0;
 +int soilMoist = 0;
 +int hum = 0;
 +float tempC = 0;
 +int light = 0;
 +int lightPerc = 0;
 +const int minLight = 0;
 +const int maxLight = 3409;
 +
 +
 +// Auxiliary Function for Ubidots connection
 +void callback(char *topic, byte *payload, unsigned int length)  {
 +  Serial.print("Message arrived [");
 +  Serial.print(topic);
 +  Serial.print("] ");
 +  for (int i = 0; i < length; i++)  {
 +    Serial.print((char)payload[i]);
 +  }
 +  Serial.println();
 +}
 +
 +void soilMoistPrint(int soil_moisture, int air_standard, int water_standard)  {
 +  soilMoistPerc = map(soil_moisture, air_standard, water_standard, 0, 100);
 +
 +  if (soilMoistPerc < 0) {
 +    soilMoistPerc = 0;
 +  }
 +  else if (soilMoistPerc > 100) {
 +    soilMoistPerc = 100;
 +  }
 +  Serial.print("Soil Moisture: ");
 +  Serial.print(soilMoistPerc);
 +  Serial.println("%");
 +  Serial.println("---------------------------");
 +}
 +
 +void dhtOutPrint(int humidity, float temperature_C) {
 +  if (isnan(humidity) | isnan(temperature_C)) {
 +    Serial.println("Reading Failed!");
 +  }
 +  else {
 +    Serial.print("Humidity: ");
 +    Serial.print(humidity);
 +    Serial.print("%");
 +    Serial.print(" | ");
 +    Serial.print("Temperature: ");
 +    Serial.println(temperature_C);
 +
 +  }
 +  
 +}
 +
 +void lightOutPrint(int light, int minimum, int maximum)  {
 +  lightPerc = map(light, minimum, maximum, 0, 100);
 +  Serial.print("Light Intensity: ");
 +  Serial.print(lightPerc);
 +  Serial.println("%");
 +}
 +
 +void setup() {
 +  // put your setup code here, to run once:
 +  Serial.begin(115200);
 +  delay(1000);
 +  dht.begin();
 +
 +  ++bootCount;
 +  Serial.println("Boot number " + String(bootCount));
 +  esp_sleep_enable_timer_wakeup(PUBLISH_FREQUENCY * uS_FACTOR);
 +
 +  client.setDebug(true);
 +  client.wifiConnection(WIFINAME, WIFIPASS);
 +  client.begin(callback);
 +
 +  if (!connected)  {
 +    Serial.println("Not connected, attempting to connect");
 +    connected = client.connect();
 +  }
 +  
 +  Serial.println(connected);
 +
 +  light = analogRead(LDRPIN);
 +  //lightOutPrint(light, minLight, maxLight); Debugging method for LDR
 +  
 +  hum = dht.readHumidity();
 +  tempC = dht.readTemperature();
 +  //dhtOutPrint(hum, tempC);  Debugging method for DHT sensor
 +
 +  soilMoist = analogRead(SOILPIN);
 +  //soilMoistPrint(soilMoist, airStd, waterStd);  Debugging method for soil moisture sensor
 +  
 +  if (connected) {
 +    client.add(VAR_LABEL_1, tempC);
 +    client.add(VAR_LABEL_2, hum);
 +    client.add(VAR_LABEL_3, soilMoistPerc);
 +    client.add(VAR_LABEL_4, lightPerc);
 +    client.ubidotsPublish(DEVICE_LABEL);
 +    client.loop();
 +  }
 +
 +  Serial.println("Going to sleep");
 +  Serial.flush();
 +  esp_deep_sleep_start();
 +
 +}
  
 +void loop() {
 +  // put your main code here, to run repeatedly:
 +  
 +}
 +</code>
 ====== 4. Discussion ====== ====== 4. Discussion ======
 ''(by Khayman F. Carneiro)'' ''(by Khayman F. Carneiro)''
Line 119: Line 261:
 * Enhanced Dashboard: Add mobile compatibility, as well as increase interaction via charts, trends, and data download capabilities to the dashboard. * Enhanced Dashboard: Add mobile compatibility, as well as increase interaction via charts, trends, and data download capabilities to the dashboard.
 * Enhanced Functionality: Connect multiple stations to monitor wider regions such as farms or school campuses. * Enhanced Functionality: Connect multiple stations to monitor wider regions such as farms or school campuses.
 +
 +====== Explanation Video ====== 
 + 
 +The videos showing the explanation and demo are zipped below. Also included is the schematic file showing how everything is connected. Uploaded here for the size of the zipped file is still too large for Moodle.
 + 
 +{{ :amc:ss2025:group-g:final_project_folder.zip |}}
  
 ====== References ====== ====== References ======
amc/ss2025/group-g/start.1753822402.txt.gz · Last modified: 2025/07/29 22:53 by 29478_students.hsrw