Basic DIY Arduino Wifi Node
by mewanthahayesh in Circuits > Arduino
267 Views, 1 Favorites, 0 Comments
Basic DIY Arduino Wifi Node
DIY WiFi Node PrototypeThis tutorial shows the design of a simple WiFi node using Arduino and ESP8266 module. Upon completion, this will be able to transmit sensor readings to a cloud TCP server periodically.
Parts Required:
- Arduino board – Any Arduino (or compatible) board would be fine
- ESP8266 module – ESP8266 ESP-01S with serial communication (RX, TX) is used in this project.
- LDR
- Resistors: 1 x 10K, 1 x 510R (for LED – optional)
- Voltage regulators – 1 x fixed 5V regulator, 1 x 5V to 3.3V regulator module
- LM7805 – fixed 5V regulator
- AMS1117 – 5V to 3.3V regulator
- Capacitors: 2 x >= 1uF capacitors for 5V regulator bypass
- LED – optional
- Diode – for reverse input voltage protection. Any general-purpose diode is fine. As a reference, I have used a 1N4001 diode.
The above parts can be purchased online cheaply. See links for the parts below:
- Arduino board
- Arduino Mini – http://www.ebay.com.au/itm/282969040900
- Arduino Nano – http://www.ebay.com.au/itm/264112738794
ESP8266 module – http://www.ebay.com.au/itm/303168449170
AMS1117 based module (5v-3.3)- http://www.ebay.com.au/itm/262975187141
Resistors, capacitors, diodes and also other components mentioned above can be easily found in local electronics/hardware stores.
Circuit Diagram
The above diagram (left) shows the interconnection between modules and components. Please make sure bypass capacitors are added at the input and output of the fixed 5V regulator even though it is not illustrated below.
Since built-in UART (RX0, TX0) is used for programming the Arduino, software serial should be used (unless using Arduino Mega) for serial communication to the ESP8266. I have used digital pins 8 and 9 for RX and TX respectively (i.e. ESP TX —>D8, ESP RX <—D9).
The circuit can be powered using a 9V battery or 5V from the USB port. Note: If intended to power using 5V USB port, there is no need for a fixed 5V regulator.
I’ve decided to solder the components into a perf board, however, the circuit can also be implemented on a breadboard. A finished design that is left outside for LDR sensor value logging is shown above (right).
Arduino Code
Code can be found on GitHub: https://github.com/mewanthahayesh/ArduinoBasicWif...
To connect to the Wifi network, please uncomment the following lines of codes, as shown above (right), in the setup function of the code.
In addition, please make sure the IP and port of your server are set up properly for a successful connection, as shown above (left).
TCP Server
Below is the code used in this project for the TCP server. The code is written in Golang, however, it can be written in any programming language.
This code can be installed on a local server or a cloud server. This project focuses on using the AWS platform. See youtube video below on how to set up a free-tier EC2 instance in AWS.
The following link explains how to set up the golang environment in Linux: https://www.linode.com/docs/development/go/instal...
TCP Server Code
package main import ( "fmt" "net" "os" "time" ) const ( CONN_HOST = "" CONN_PORT = "1234" CONN_TYPE = "tcp" ) func main() { // Listen for incoming connections. l, err := net.Listen(CONN_TYPE, CONN_HOST+":"+CONN_PORT) if err != nil { fmt.Println("Error listening:", err.Error()) os.Exit(1) } // Close the listener when the application closes. defer l.Close() fmt.Println("Listening on " + CONN_HOST + ":" + CONN_PORT) for { // Listen for an incoming connection. conn, err := l.Accept() if err != nil { fmt.Println("Error accepting: ", err.Error()) os.Exit(1) } // Handle connections in a new goroutine. go handleRequest(conn) } } // Handles incoming requests. func handleRequest(conn net.Conn) { // Make a buffer to hold incoming data. buf := make([]byte, 1024) // Read the incoming connection into the buffer. _, err := conn.Read(buf) if err != nil { fmt.Println("Error reading:", err.Error()) } fmt.Print(time.Now().UTC()) fmt.Println("Message Received: ",string(buf)) // Send a response back to person contacting us. conn.Write([]byte("Message received.")) // Close the connection when you're done with it. conn.Close() }
Upon programming the wifi node with the Arduino code provided, and TCP server up and running, LDR sensor data can be logged. Shown above is a record of the logs sent from the Wifi node indicating LDR sensor readings.
Conclusion
The wifi node used in this project is programmed to send LDR data every 15 seconds to the cloud TCP server. Sending data increases the power consumption of the whole system. Given the system was powered with a brand new 9V battery, it was able to send data successfully for about 10 hours with this configuration.
This issue can be improved by increasing the time between sending LDR information to the cloud and put the Arduino and ESP modules into appropriate sleep modes.