66d4523741098e13a4c290f7_WiFi_Module_ESP8266
66d4523741098e13a4c290f7_WiFi_Module_ESP8266
Hardware Required
Arduino or Genuino Board
ESP8266 Wifi module
Breadboard
LED
Wires
Pushbutton
Resistor
Theory
The Arduino Uno WiFi is an Arduino Uno with an integrated WiFi
module. The board is based on the ATmega328P with an
ESP8266WiFi Module integrated. The ESP8266WiFi Module is a self
contained SoC with integrated TCP/IP protocol stack that can give
access to your WiFi network (or the device can act as an access
point). One useful feature of Uno WiFi is support for OTA (over-the-
air) programming, either for transfer of Arduino sketches or WiFi
firmware.
Code
Board NodeMCU 1.0(ESP-12E Module)
1. #define BLYNK_PRINT Serial
2. #include <ESP8266WiFi.h>
3. #include <BlynkSimpleEsp8266.h>
4. #include <SoftwareSerial.h>
5. #include <SimpleTimer.h>
6.
7. #define BLYNK_TEMPLATE_ID "..."
8. #define BLYNK_TEMPLATE_NAME "..."
9.
10. #define led D2
11.
12. char auth[] = "Blynk auth code";
13. char ssid[] = "WiFi Name"
14. char pass[] = "WiFi Password";
15.
16. SimpleTimer timer;
17.
18. //Truyền dữ liệu sensor
19. void myTimerEvent()
20. {
21. Blynk.virtualWrite(V1, millis() / 1000);
22.
23. int analogValue = analogRead(A0);
24. float millivolts = (analogValue/ 1024.0) *3300;
25. float celsius = millivolts/10; //Tính toán dữ liệu
26. Blynk.virtualWrite(V2, celsius);
27. }
28. //Bật tắt LED
29. BLYNK_WRITE(V10){
30. int pinvalue = param.asInt();
31. if (pinvalue == 0) {
32. digitalWrite(led, LOW);
33. } else {
34. digitalWrite(led, HIGH);}
35. }
36.
37.
38.
39.
40.
41. void setup()
42. {
43. Serial.begin(9600);
44. Blynk.begin(auth, ssid, pass);
45. pinMode(led, OUTPUT);
46. timer.setInterval(1000L, myTimerEvent);
47. }
48.
49. void loop()
50. {
51. if (Serial.available() == 0 )
52. {
53. Blynk.run();
54. timer.run(); // Initiates BlynkTimer
55. }
56. }
Demonstrations
(Demonstrations with photos of experiments)
Before coding the project, we need to be able to connect 2 devices to Arduino IDE in order to
upload codes on the devices.
1. We need to install CH340 driver in order to connect to ESP8266. Then download ESP8266 board
(Tools -> Board -> Boards manager -> Search for “esp8266” by ESP8266 community)
2. We use Blynk to support our project. So that we have to install Blynk library (Sketch -> Include
library -> Manage library -> Search for “Blynk” by Volodymyr Shymanskyy) .
3. Adding crucial library:
SimpleTimer.h(Sketch -> Include library -> ADD .ZIP library...)
ESP8266WiFi.h (File -> Preferences -> Additional Boards Manager URLs: -> add this link)
References
https://docs.arduino.cc/retired/getting-started-guides/
ArduinoUnoWiFi
https://www.youtube.com/watch?v=lp93f4tFqh4&t=924s
https://www.youtube.com/watch?v=MM9Fj6bwHLk
https://www.youtube.com/watch?v=vDm1zhqS-wE