This repository contains various Arduino sketches created for experimenting with microcontrollers and IoT applications as part of my microdegree program at Tallinn University (TLU). These sketches are designed to work with the LOLIN(WEMOS) D1 R2 & mini board and utilize various components and sensors to demonstrate different functionalities.
A basic sketch that blinks the built-in LED on the LOLIN(WEMOS) D1 R2 & mini board. This is a great starting point for beginners to understand how to control digital outputs.
NB! Wemos mini's built-in LED operates inversely to the commands. For more information, read this discussion.
A fun sketch that controls an LED to create a disco light effect. It demonstrates the use of loops and delays to create patterns with LEDs.
This sketch interfaces with a display module to show text or graphics. It's useful for learning how to send data to a display and refresh its content.
- Required Libraries:
Adafruit GFX Library
Adafruit SSD1306
OneWire
An advanced version of the display sketch that shows how to render bitmap images on a display. This example includes displaying a face graphic, teaching how to handle image data.
This sketch reads data from a Passive Infrared (PIR) sensor to detect motion. It's ideal for creating simple motion-sensing projects.
A sketch that demonstrates how to control a relay switch using the microcontroller. This is useful for understanding how to interact with higher voltage circuits safely.
A general sketch for interfacing with various sensors, such as temperature and humidity sensors. This sketch provides a template for reading sensor data and processing it for different applications.
- Required Libraries:
DHT sensor library
A variation of the Blink sketch that adds serial communication. It allows you to control the blinking of the LED via commands sent over the serial port, illustrating basic serial communication.
A cloud-connected project that monitors temperature and humidity while enabling remote control of two light switches through the Arduino IoT Cloud. Features a configurable dashboard with real-time data updates and switch controls.
- Required Libraries:
DHT sensor library
Arduino_ConnectionHandler
- Add your Wi-Fi credentials and cloud credentials in the
thingProperties.h
file. - Configure the Arduino IoT Cloud Dashboard to display temperature, humidity, and relay status and control. Ensure that the cloud variables are linked correctly for real-time updates.
- The relays can be controlled via the dashboard switches, while temperature and humidity readings are updated every 10 seconds.
A pair of MQTT-based sketches to set up communication between two Wemos D1 Mini ESP8266 boards:
- wemos_mini_MQTT_publisher: Publishes temperature data from a DHT sensor and controls two relays. Data and relay states are sent to an MQTT broker.
- wemos_mini_MQTT_receiver: Displays the received temperature and relay states on an OLED screen and mirrors the relay control.
-
Libraries:
PubSubClient
- For MQTT communication between the devices and the broker.DHT sensor library
- For reading temperature data from the DHT sensor (in the publisher sketch).Adafruit GFX Library
andAdafruit SSD1306
- For OLED display control (in the receiver sketch).
-
MQTT Broker: An MQTT broker is required to handle communication between the publisher and receiver. You can use a local broker like Mosquitto or an online service.
- Add your Wi-Fi credentials in the
arduino_secrets.h
file for both the publisher and receiver projects. - Set up an MQTT broker (e.g., Mosquitto) on your local network or use an external service.
- In the wemos_mini_MQTT_publisher sketch, define the broker's IP address and port:
const char* mqtt_server = "YOUR_BROKER_IP"; const int port = 1883;
- LOLIN(WEMOS) D1 R2 & mini board
- Arduino IDE installed on your computer
- Basic understanding of Arduino programming and electronics
- Download the Arduino IDE from the official website.
- Install the necessary libraries for each sketch. This can be done through the Arduino Library Manager in the Arduino IDE:
- Go to Sketch > Include Library > Manage Libraries...
- Search for the required library and click "Install".
- Connect your LOLIN(WEMOS) D1 R2 & mini board to your computer via USB and select the correct board and port in the Arduino IDE (
BOARD: LOLIN(WEMOS) D1 R2 & mini
,PORT: COM3
). - To add the LOLIN(WEMOS) D1 R2 & mini board to the Arduino IDE:
- Open the Arduino IDE.
- Go to File > Preferences.
- In the "Additional Board Manager URLs" field, add
http://arduino.esp8266.com/stable/package_esp8266com_index.json
. - Go to Tools > Board > Boards Manager....
- Search for "ESP8266" and install the "ESP8266 by ESP8266 Community".
- If you need a USB driver for your board, follow the instructions provided in this Getting Started Guide.
- Open a sketch file in the Arduino IDE.
- Compile and upload the sketch to your board.
- Follow the specific instructions or setup for each sketch, which are detailed in the comments within the code.
These sketches are part of the course HKC0239 - Mikrokontrollerid ja asjade internet IoT offered from August 26, 2024, to September 14, 2024. More information about the course can be found here.