Wind Direction Indicator Using Infrared Line Tracking Sensor - Group 8

by s64634 in Circuits > Microcontrollers

135 Views, 1 Favorites, 0 Comments

Wind Direction Indicator Using Infrared Line Tracking Sensor - Group 8

photo_2024-01-25_17-18-54.jpg
photo_2024-01-25_17-17-07.jpg

This Wind Direction Indicator, created for the IoT subject's final project, utilizes an Infrared Line Tracking Sensor. Implemented at the UMT Research Center in Kenyir Lake, the sensor accurately determines wind direction, and its LED can be remotely controlled.

The project's objective is to design and implement a Wind Direction Indicator with precise wind direction determination. Additionally, the goal is to enable remote control via a mobile phone for convenient activation or deactivation of the sensor

The project's scope covers the development and deployment of the Wind Direction Indicator at the UMT Research Center in Kenyir Lake. It enhances wind direction monitoring and control in that specific location, integrating advanced sensor technology and mobile communication for a comprehensive operational solution.

Supplies

photo_2024-01-25_17-24-57.jpg
FAG78MTLR4XOS44.png

To built the Wind Direction Indicator, we will need:

  • ESP32
  • Arduino TCTRT5000 Infrared IR Line Follower
  • Micro-USB to USB cable
  • USB adapter
  • 1 blue LED
  • Resistor
  • Male-to-male jumper wires
  • Male-to-female jumper wires
  • 1 Breadboard

also some tools:

  • Soldering iron
  • Arrow carbon
  • Container
  • Drill
  • Hot glue gun
  • Tape
  • Computer

Design and Set Up the Circuit

photo_2024-01-25_17-17-18.jpg
photo_2024-01-25_17-15-56.jpg

The image used in this report is very brief but revealing regarding the specifics of circuit design, and it provides an accurate 2D representation. This visual presentation acts as a starting point in understanding the schematic map and also how various components are related to each other.

Assemble Things

photo_2024-01-25_17-16-32.jpg
photo_2024-01-25_17-16-36.jpg
photo_2024-01-25_17-16-10.jpg

This is the images of the assembled system.

Write the Code

#include <WiFi.h>

#include <MQTT.h>

#include <cstdlib>  


int led1_pin = 13;

#define WIFI_SSID       "FSKMPocketWiFi"

#define WIFI_PASSWORD     "88888888"

#define MQTT_HOST       "broker.hivemq.com"

#define MQTT_PREFIX_TOPIC   "csm3313_umt/group08"

#define MQTT_SUBSCRIBE_TOPIC1 "/led01"


int infraredPins[] = {2, 5, 34, 32};

const char* directions[] = {"Wind from North", "Wind from South", "Wind from West", "Wind from East"};

const int numSensors = 4;

#define MQTT_TOPIC      "csm3313_umt/group08/wdir"


WiFiClient net;

MQTTClient mqtt(1024);

unsigned long lastMillis = 0;


void connectToWiFi() {

 Serial.print("Connecting to Wi-Fi '" + String(WIFI_SSID) + "' ...");


 // Connect to WiFi

 WiFi.begin(WIFI_SSID, WIFI_PASSWORD);


 // while wifi not connected yet, print '.'

 // then after it connected, get out of the loop

 Serial.println("Connecting to WiFi...");

 while (WiFi.status() != WL_CONNECTED) {

  delay(500);

  Serial.print(".");

 }

 // print a new line, then print WiFi connected and the IP address

 Serial.println("");

 Serial.println("WiFi connected");

 // Print the IP address

 Serial.println(WiFi.localIP());

}


void messageReceived(String topic, String payload) {

 Serial.println("Incoming Status from topic " + topic + " -> " + payload);


 // check if the topic equals MQTT_SUBSCRIBE_TOPIC1

 if (topic == (String(MQTT_PREFIX_TOPIC) + String(MQTT_SUBSCRIBE_TOPIC1))) {

  if (payload == "1") {

   digitalWrite(led1_pin, HIGH);

   Serial.println("LED1 turned ON");

  } else if (payload == "0") {

   digitalWrite(led1_pin, LOW);

   Serial.println("LED1 turned OFF");

  }

 } else {

  Serial.println("Command does not match.");

 }

}


void connectToMqttBroker() {

 Serial.print("Connecting to '" + String(WIFI_SSID) + "' ...");


 mqtt.begin(MQTT_HOST, net);

 mqtt.onMessage(messageReceived);


 String uniqueString = String(WIFI_SSID) + "-" + String(random(1, 98)) + String(random(99, 999));

 char uniqueClientID[uniqueString.length() + 1];


 uniqueString.toCharArray(uniqueClientID, uniqueString.length() + 1);


 while (!mqtt.connect(uniqueClientID)) {

  Serial.print(".");

  delay(500);

 }


 Serial.println(" connected!");


 Serial.println("Subscribe to: " + String(MQTT_PREFIX_TOPIC) + String(MQTT_SUBSCRIBE_TOPIC1));

 mqtt.subscribe(String(MQTT_PREFIX_TOPIC) + String(MQTT_SUBSCRIBE_TOPIC1));

}


void setup(void) {

 Serial.begin(115200);

 pinMode(led1_pin, OUTPUT);

 digitalWrite(led1_pin, LOW);


 for (int i = 0; i < numSensors; i++) {

  pinMode(infraredPins[i], INPUT);

  if (infraredPins[i] == 34 || infraredPins[i] == 32) {

   digitalWrite(infraredPins[i], LOW); // Set the default state to LOW for pins 34 and 32

  }

 }


 connectToWiFi();

 connectToMqttBroker();

 Serial.println();


}


void loop() {

 mqtt.loop();


 for (int i = 0; i < numSensors; i++) {

  int sensorValue = digitalRead(infraredPins[i]);


  if (sensorValue == LOW) { // If sensor detects a white surface

   unsigned long currentMillis = millis();

   String message = String(directions[i]);

   Serial.println(message); // Print the direction and timestamp

   mqtt.publish(MQTT_TOPIC, message); // Publish direction and timestamp to MQTT topic

  }

 }


 delay(10000); // delay for 10s

}

Create a Dashboard Using NodeRed

photo_2024-01-25_17-18-33.jpg
photo_2024-01-25_17-16-17.jpg

Wind Direction Dashboard Setup:

1. Open Node-RED.

2. In the palette, select "dashboard."

3. Add the MQTT node to the workspace.

4. Double-click the node to edit its properties.

5. Create a new MQTT broker setup by clicking the pencil icon.

6. Enter "broker.hivemq.com:1883" in the server field.

7. Click "add" to confirm adding the MQTT broker.

9. Name the node "GetWindDirData."

10. Leave other configurations as default.

11. Click the "Done" button to confirm the MQTT node properties configuration.

12. Add a debug node to the workspace and connect it to the MQTT node.

13. Add a function node named "function1" to the workspace.

14. Add a text node from the output UI for the dashboard, name it for time and date, and connect it to the "function1" node.

15. Add another function node named "function2" to the workspace.

16. Add a text node from the output UI for the dashboard, name it for wind direction data, and connect it to the "function2" node.

17. Connect both function nodes to the MQTT node.

18. Click the deploy button to redeploy the flow.

19. Observe the incoming JSON payload on Node-RED's debug sidebar from the MQTT topic published by ESP32, with a time interval of 5 seconds.

Led Setup:

1. Add a switch node to the workspace and name it "led01."

2. Add a function node connected to the switch node, and name it "led01_func."

3. Add an MQTT node connected to the function node, and name it "led01."

4. Click the deploy button to redeploy the flow.

5. Observe the incoming JSON payload on Node-RED's debug sidebar from the MQTT topic published by ESP32, with a time interval of 5 seconds.

Mobile Applications Subscribe to MQTT Through a Broker

FPHR300LRJ81Z6C.png
FYYPNVQLRQD9SMG.png

Once you have successfully created a dashboard using Node-RED, the subsequent step involves configuring MQTT client applications to enable the visualization of data on your mobile phone.

The following steps outline the process for setting up MQTT Client Apps on a mobile phone:

1. Download the MyMQTT application from either Google Play or the Apple Store.

2. Configure the broker connection by specifying the host (broker.hivemq.com), port (1883), and protocol (MQTT V3).

3. Click the "Connect" button to establish a connection with the broker server.

4. Access the subscribe functionality by clicking on the subscribe icon.

5. Enter the subscribe topic as follows: csm3313_umt/group08/wdir.

6. Click the "Subscribe" button to confirm the subscription.

7. Navigate to the Dashboard feature to receive sensor data each time it is published by the ESP32.

Implement and Deploy

photo_2024-01-25_17-16-02.jpg
photo_2024-01-25_17-16-45.jpg
photo_2024-01-25_17-16-47.jpg
photo_2024-01-25_17-16-52.jpg
photo_2024-01-25_17-17-01.jpg
photo_2024-01-25_17-16-50 (2).jpg
  1. The image above depicts the process of deploying the system in its environment.
  2. Place the assembled circuit in a transparent container to ensure waterproofing when deploying.
  3. Secure all the wires with a glue gun to keep them in place.
  4. Seal the transparent container with tape to secure and prevent water from entering.
  5. Find a suitable location to deploy the sensor. The sensor should be positioned at a high place for accurate wind measurements.
  6. The north sensor need to be manually position toward real north in order to make it works.
  7. For this project, we chose to deploy the sensor on top of the houseboat roof.
  8. The sensor receives power through a USB cable connected to a power socket in the houseboat.
  9. Make sure to secure the sensor and ensure it doesn't move.

Receive and Read the Data

FOKSUQ7LRQD9VQP.png

Post-deployment, the ESP32 generates data accessible on the dashboard every 5 seconds, enabling real-time monitoring for quick insights into environmental conditions and system performance. This feature enhances system efficiency and responsiveness.

Video Guide

Navigating the Wind: Line Detection Sensor Insights

This video serves as a comprehensive guide through the entire process. Watching it will greatly enhance your understanding of the subject. Thank you for taking the time to read this. We hope you find the video enjoyable and informative!