User Tools

Site Tools


inhabitat:kaunas:day02

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
inhabitat:kaunas:day02 [2026/05/29 09:01] jan.sonntaginhabitat:kaunas:day02 [2026/05/29 09:05] (current) jan.sonntag
Line 21: Line 21:
  
 We are using the **DFRobot Analog Capacitive Soil Moisture Sensor**. We are using the **DFRobot Analog Capacitive Soil Moisture Sensor**.
- 
-{{ :day2:soil_sensor.jpg?400 |}} 
-<wrap em>📷 PLACEHOLDER — Insert a photo of the DFRobot capacitive soil moisture sensor here.</wrap> 
  
 ===== 2. Connecting the Sensor to the DOIT ESP32 ===== ===== 2. Connecting the Sensor to the DOIT ESP32 =====
Line 40: Line 37:
   * Double-check GND is shared between the sensor and the board.   * Double-check GND is shared between the sensor and the board.
  
-{{ :day2:wiring_diagram.png?500 |}} +<WRAP center round tip 60%> 
-<wrap em>📷 PLACEHOLDER — Insert the wiring diagram photo showing+Here an example to connect to similiar MCU. Make sure to check the Pinout of your specific board! 
 +</WRAP> 
 + 
 +<imgcaption image3|Wiring of the analog sensor>{{ https://raw.githubusercontent.com/EOLab-HSRW/intro-to-iot/master/diagrams/wemos-soil_bb.png?400 |}}</imgcaption> 
 +<imgcaption image4|Schematic>{{ https://raw.githubusercontent.com/EOLab-HSRW/intro-to-iot/master/diagrams/wemos-soil_schematic.png?400 |}}</imgcaption> 
 + 
 +===== 3. Reading the Sensor with the Serial Monitor ===== 
 + 
 +Before we send data anywhere, we want to **see** it. The easiest way is the 
 +**Serial Monitor**. 
 + 
 +**Serial** is a way for the ESP32 to send text back to your computer over the 
 +USB cable. By calling ''Serial.begin()'' once at startup and then 
 +''Serial.println()'' whenever we have something to show, we can print our 
 +sensor readings to the screen in real time. This is incredibly useful for 
 +checking that everything is wired correctly and that the numbers change when 
 +you touch the sensor or place it in soil. 
 + 
 +Open the Serial Monitor in PlatformIO and make sure the **baud rate matches** 
 +the value you set in ''Serial.begin()'' (commonly 115200). 
 + 
 +<code cpp> 
 +// PLACEHOLDER — Sensor reading code 
 +// This should: 
 +//   - start Serial at the chosen baud rate in setup() 
 +//   - read the analog value from the sensor pin 
 +//   - print the value to the Serial Monitor in loop() 
 +//   - add a short delay so the output is readable 
 +</code> 
 + 
 +Once uploaded, you should see numbers scrolling in the Serial Monitor. 
 +Try touching the sensor or dipping it into soil/water — the value should change. 
 + 
 +===== 4. Connecting to WiFi ===== 
 + 
 +Now that the board works on its own, let's get it online. The ESP32 has 
 +built-in WiFi, so we just need to give it the **network name (SSID)** and 
 +**password** of our workshop access point. 
 + 
 +In ''setup()'' we tell the ESP32 to connect, then wait in a short loop until 
 +the connection succeeds. We can print the status to Serial so we know when 
 +we're online. 
 + 
 +<code cpp> 
 +// PLACEHOLDER — WiFi connection code 
 +// This should: 
 +//   - include the WiFi library 
 +//   - store the SSID and password 
 +//   - start the connection in setup() 
 +//   - wait until connected, printing progress to Serial 
 +//   - print the assigned IP address once connected 
 +</code> 
 + 
 +When it works, the Serial Monitor will show that the ESP32 has joined the 
 +network and received an IP address. 
 + 
 +===== 5. Introducing MQTT ===== 
 + 
 +**MQTT** is a lightweight messaging protocol that is very popular in IoT. The 
 +idea is simple: devices send ("**publish**") messages to a central server (the 
 +"**broker**"), and other devices can listen ("**subscribe**") for them. Today 
 +we will only **publish** — sending messages out. We will not subscribe. 
 + 
 +{{pdfjs 500px>:latinet:unicaes:workshops:mqtt.pdf?75}} 
 + 
 +===== 6. Publishing a Message to the Broker ===== 
 + 
 +For our final step, we connect to the **MQTT broker** and send a single 
 +message of **your choosing** — any text string you like, for example 
 +''"hello from my esp32"''
 + 
 +  * This is **not** the soil moisture value. That's a separate exercise. Here we are just proving we can talk to the broker by sending a simple string. 
 +  * We connect to the broker, then publish our chosen string to a **topic**. 
 + 
 +<code cpp> 
 +// PLACEHOLDER — MQTT publish code 
 +// This should: 
 +//   - include the MQTT client library 
 +//   - set the broker address and port 
 +//   - connect to the broker in setup() (after WiFi is connected) 
 +//   - publish a single text string of your choosing to a topic 
 +//   - print confirmation to Serial 
 +</code> 
 + 
 +Pick any message you want and send it. 🎉 
 + 
 +===== Recap ===== 
 + 
 +By the end of today you have: 
 +  * Learned how a capacitive soil moisture sensor works 
 +  * Wired it to the DOIT ESP32 
 +  * Read its value in the Serial Monitor 
 +  * Connected the ESP32 to WiFi 
 +  * Learned the basics of MQTT 
 +  * Published your own message to the MQTT broker
inhabitat/kaunas/day02.1780038117.txt.gz · Last modified: 2026/05/29 09:01 by jan.sonntag