DIYables Web Apps Chat
WebChat Example - Setup Instructions
Overview
The WebChat example demonstrates how to create an interactive chat interface between a web browser and Arduino. Designed for Arduino Uno R4 WiFi and DIYables STEM V4 IoT educational platform with enhanced IoT capabilities and seamless integration with built-in sensors. The Arduino can respond intelligently to messages and control hardware based on chat commands.

Features
- Real-time Chat: Instant messaging via WebSocket
- Intelligent Responses: Arduino provides contextual replies
- LED Control: Control built-in LED via chat commands
- User Recognition: Arduino remembers your name
- Message History: View conversation history
- Responsive Design: Works on desktop and mobile
- Platform Extensible: Currently implemented for Arduino Uno R4 WiFi, but can be extended for other hardware platforms. See DIYables_WebApps_ESP32
Hardware Preparation
Or you can buy the following kits:
1 | × | DIYables STEM V4 IoT Starter Kit (Arduino included) | |
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Setup Instructions
Detailed Instructions
Follow these instructions step by step:
- If this is your first time using the Arduino Uno R4 WiFi/DIYables STEM V4 IoT, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/DIYables STEM V4 IoT in the Arduino IDE.
- Connect the Arduino Uno R4/DIYables STEM V4 IoT board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
- Navigate to the Libraries icon on the left bar of the Arduino IDE.
- Search "DIYables WebApps", then find the DIYables WebApps library by DIYables
- Click Install button to install the library.

- You will be asked for installing some other library dependencies
- Click Install All button to install all library dependencies.

- On Arduino IDE, Go to File Examples DIYables WebApps WebChat example, or copy the above code and paste it to the editor of Arduino IDE
- Configure WiFi credentials in the code by updating these lines:
- Click Upload button on Arduino IDE to upload code to Arduino UNO R4/DIYables STEM V4 IoT
- Open the Serial Monitor
- Check out the result on Serial Monitor. It looks like the below
- If you do not see anything, reboot Arduino board.
- Take note of the IP address displayed, and enter this address into the address bar of a web browser on your smartphone or PC.
- Example: http://192.168.0.2
- You will see the home page like below image:

- Click to the Chat link, you will see the Web Chat app's UI like the below:

- Or you can also access the page directly by IP address followed by /chat. For example: http://192.168.0.2/chat
- Start chatting with your Arduino! Type your name when prompted and try commands like "led on", "hello", or "help" to interact with your Arduino.
How to Use
Starting a Conversation
- Open the chat interface in your browser
- Type your name when prompted
- Start chatting with your Arduino!
Chat Commands
The Arduino recognizes these special commands:
LED Control
- "led on" or "turn on led" → Turns on built-in LED
- "led off" or "turn off led" → Turns off built-in LED
- "blink" or "blink led" → Makes LED blink
Information Commands
- "hello" or "hi" → Friendly greeting
- "help" → Shows available commands
- "time" → Shows Arduino uptime
- "status" → Shows system status
Questions
- "how are you?" → Arduino shares its status
- "what can you do?" → Lists capabilities
- "what is your name?" → Arduino introduces itself
Example Conversation
Creative Customization - Build Your Interactive Assistant
Transform this basic chat example into something amazing! The modular design allows you to adapt and expand the functionality to create your own unique interactive Arduino assistant.
Code Structure
Main Components
- WebApp Server: Manages HTTP and WebSocket connections
- Chat Page: Provides the web interface
- Message Handler: Processes incoming chat messages
- Response Generator: Creates intelligent replies
Key Functions
Adding Custom Commands
To add new chat commands, modify the handleChatMessage function:
Customization Options
Modify Arduino Personality
Edit the response messages to change Arduino's personality:
Add Hardware Control
Extend LED control to other components:
Change Web Interface Theme
The chat interface can be customized by modifying CSS in the library files:
- Colors: Edit gradient backgrounds
- Fonts: Change font families
- Layout: Adjust spacing and sizing
Troubleshooting
Common Issues
1. Arduino not responding to messages
- Check Serial Monitor for error messages
- Verify WebSocket connection status
- Refresh the browser page
2. WiFi connection failed
- Double-check SSID and password
- Ensure 2.4GHz network (not 5GHz)
- Check signal strength
3. Can't access chat page
- Verify IP address is correct
- Check if Arduino is still connected to WiFi
- Try accessing home page first: http://[IP]/
4. LED not responding to commands
- Check wiring (built-in LED should work by default)
- Verify commands are spelled correctly
- Check Serial Monitor for debug messages
Debug Tips
Enable debug mode by adding this line in setup():
Monitor Serial output to see:
- Incoming messages
- Command parsing
- Response generation
- Hardware actions
Advanced Features
Multiple Client Support
The chat supports multiple users simultaneously:
- Each user has a unique session
- Arduino remembers individual names
- Broadcast messages to all users
Message Persistence
Add message logging to EEPROM:
Integration with Sensors
Connect sensors and make them accessible via chat:
Next Steps
After mastering the Chat example, try:
- WebMonitor - For debugging and development
- DigitalPins - For controlling multiple outputs
- Joystick - For directional control
- MultipleWebApps - Combining all features
Support
For additional help:
- Check the API Reference documentation
- Visit DIYables tutorials: https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-diyables-webapps
- Arduino community forums