Docsity

IoT Experiments with ESP8266 NodeMCU: Home Automation and Sensor Integration, Lecture notes of History of Law

Toggle sidebar
bg1
INDUSTRIAL INTERNET OF THINGS(20EC52I)
EXPERIMENT N0-01(a)
Interfacing of LED using NODEMCU ESP8266
Aim: Interfacing LED using NODEMCU ESP8266
Apparatus Required:
• ESP8266 NODEMCU
• LED
• Connecting Wires
• Bread board
• Arduino IDE (software)
• 220Ω Resistor
Circuit diagram:
Procedure:-
• Connect anode of Led to D1 pin of NODEMCU and cathode pin of LED to GND pin
of NODEMCU
• In the program code create delay between ON period and OFF period of LED to
observe the output
• Upload the code to NODEMCU through micro USB cable from Arduino IDE
Code:-
#define LED_PIN D1
void setup() {
S.J.(GOVT.) POLYTHNIC) POLYTECHNIC 1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54

Partial preview of the text

Download IoT Experiments with ESP8266 NodeMCU: Home Automation and Sensor Integration and more Lecture notes History of Law in PDF only on Docsity!

INDUSTRIAL INTERNET OF THINGS(20EC52I)

EXPERIMENT N0-01(a)

Interfacing of LED using NODEMCU ESP

Aim: Interfacing LED using NODEMCU ESP Apparatus Required:

  • ESP8266 NODEMCU
  • LED
  • Connecting Wires
  • Bread board
  • Arduino IDE (software)
  • 220Ω Resistor Circuit diagram: Procedure:-
  • Connect anode of Led to D1 pin of NODEMCU and cathode pin of LED to GND pin of NODEMCU
  • In the program code create delay between ON period and OFF period of LED to observe the output
  • Upload the code to NODEMCU through micro USB cable from Arduino IDE Code:- #define LED_PIN D void setup() {

pinMode(LED_PIN, OUTPUT); // Set D1 (GPIO 5) as an output } void loop() { digitalWrite(LED_PIN, HIGH); // Turn the LED on delay(1000); // Delay for 1 second (1000 milliseconds) digitalWrite(LED_PIN, LOW); // Turn the LED off delay(1000); // Delay for 1second (1000 milliseconds) } Result:-interfacing of LED using NODEMCU ESP8266 is completed successfully.

void loop() { int buttonState = digitalRead(BUTTON_PIN); // Read the state of the button if (buttonState == LOW) { // Button is pressed (LOW) digitalWrite(LED_PIN, HIGH); // Turn on the LED } else { // Button is released (HIGH) digitalWrite(LED_PIN, LOW); // Turn off the LED } } Procedure:-

  • Connect anode of Led to D1 pin of NODEMCU and cathode pin of LED to GND pin of NODEMCU
  • Connect 1 side of the push button with D2 pin of NODEMCU and connectivity pin to GND pin of NODEMCU
  • Other leg of push button should be connected to 3.3V of NODEMCU
  • In the program code create delay between ON period and OFF period of LED to observe the output
  • Upload the code to NODEMCU through micro USB cable from Arduino IDE Result:- interfacing of LED and switch using NODEMCU ESP8266 is completed successfully.

INDUSTRIAL INTERNET OF THINGS(20EC52I)

Experiment-01(c)

Interfacing LED with NODEMCU to display Binary number from 0 to 7

Aim:- Interfacing LED with NODEMCU to display Binary number from 0 to 7 Apparatus Required:

  • ESP8266 NODEMCU
  • LED
  • Connecting Wires
  • Bread board
  • Arduino IDE (software)
  • 220Ω Resistor Circuit diagram:- Code:- void setup() { // put your setup code here, to run once: pinMode(D7,OUTPUT); pinMode(D6,OUTPUT);

delay(1000); digitalWrite(D5, HIGH); digitalWrite(D6,HIGH); digitalWrite(D7,HIGH); delay(1000); } Procedure:-

  • Connect the connection as shown in the circuit diagram.
  • Write the program code in order from “000” to “111”.
  • In the program code create delay between on order to another order of LED display to observe the output for 1second.
  • Upload the code to NODEMCU through micro USB cable from Arduino IDE. Result:- Interfacing of LED with NODEMCU to display binary number from 0 to 7 is completed successfully.

INDUSTRIAL INTERNET OF THINGS(20EC52I)

Experiment-

Demonstration of LoRAWAN communication.

Aim: To send and receive messages from long distances using the LoRa module. Apparatus Required:

• LoRa module.

• Nodemcu.

• Jumpers.

Circuit Diagram: Transmitter section:

Receiver Section:

PIN configuration: 1 GND-GND. 2 NSS-D8. 3 MOSI-D7. 4 MOS0-D6. 5 SCK-D5. 6 GND-GND. 7 3.3v-3.3v. 8 GND-GND. 9 RESET-D0. 10 DIO0-D

Serial.println(data); LoRa.beginPacket(); LoRa.print(data); LoRa.endPacket(); delay(3000); } Code of Reciever section: #include <LoRa.h> #define SS 15 #define RST 16 #define DIO0 2 void setup() { Serial.begin(9600); while (!Serial); Serial.println("Receiver Host"); LoRa.setPins(SS, RST, DIO0); if (!LoRa.begin(433E6)) { Serial.println("LoRa Error"); while (1); } } void loop () { int packetSize = LoRa.parsePacket(); if (packetSize) { Serial.print("Receiving Data: "); while (LoRa.available()) { String data = LoRa.readString(); Serial.println(data); } } }

Procedure:

  • Rig up the ckt as shown in the ckt diagram.
  • Connect all the ground pins of NODEMCU ,either the pins used or not.
  • Because the grounding is important to the LoRa module.
  • Download the LoRa library in the managed library.
  • Upload the code to the NODEMCU.
  • Now send the message from one LoRa to another. Result :
  • Communication using the LoRa module is successfully implemented.

Serial.begin(9600); gsm.begin(9600); gsm.println("AT+CMGF=1"); delay(1000); gsm.println("AT+CMGS="+919880466676"\r"); //replace x by your number delay(1000); gsm.println("Good afternoon sir"); delay(100); gsm.println((char)26); delay(1000); } void loop(){ } PROCEDURE:  Make the connections as per the circuit diagram.  Connect arduino uno gnd to GSM gnd.  Connect GSM TX to arduino pin2.  Connect GSM RX to arduino pin3.  Insert the SIM in GSM SIM socket.  Give the power supply to GSM,and connect the Arduino to the laptop via data cable.  Go to Arduino ide software, copy the sketch and paste in a new file.  Replace your phone number and SMS in the sketch.(where you want to have the SMS)  Compile and upload the sketch to Arduino uno. Result : hence ,SMS is received in the device via GSM.

INDUSTRIAL INTERNET OF THINGS(20EC52I) Experiment- Design a simple MQTT protocol-based system. The Cloud application should blink the LED & monitor the temperature using the MQTT protocol. Aim: To demonstrate an experiment on and off NodeMCU led using mqtt lens. Apparatus required:

  • NodeMCU wifi module (esp8266)
  • Data cable
  • System installed with Arduino IDE Software
  • Mobile with internet access
  • LM35 temperature sensor
  • My MQTT app Circuit diagram: PROCEDURE:  Open Arduino IDE software.  Erase previous program and open New file>Examples>PubSubClient(installed library from manage library)>esp

unsigned long lastMsg = 0; #define MSG_BUFFER_SIZE(50) char msg[MSG_BUFFER_SIZE]; int value = 0; void setup_wifi() { delay(10); // We start by connecting to a WiFi network Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } randomSeed(micros()); Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); } void callback(char* topic, byte* payload, unsigned int length) { Serial.print("Message arrived ["); Serial.print(topic); Serial.print("] "); for (int i = 0; i < length; i++) { Serial.print((char)payload[i]); } Serial.println(); // Switch on the LED if an 1 was received as first character if ((char)payload[0] == '1') { digitalWrite(BUILTIN_LED, LOW); // Turn the LED on (Note that LOW is the voltage level

// but actually the LED is on; this is because // it is active low on the ESP-01) } else { digitalWrite(BUILTIN_LED, HIGH); // Turn the LED off by making the voltage HIGH } } void reconnect() { // Loop until we're reconnected while (!client.connected()) { Serial.print("Attempting MQTT connection..."); // Create a random client ID String clientId = "ESP8266Client-"; clientId += String(random(0xffff), HEX); // Attempt to connect if (client.connect(clientId.c_str())) { Serial.println("connected"); // Once connected, publish an announcement... client.publish("MQTT", "hello world"); // ... and resubscribe client.subscribe("TEMP"); } else { Serial.print("failed, rc="); Serial.print(client.state()); Serial.println(" try again in 5 seconds"); // Wait 5 seconds before retrying delay(5000); } } } void setup() { pinMode(BUILTIN_LED, OUTPUT); // Initialize the BUILTIN_LED pin as an output Serial.begin(115200); setup_wifi(); client.setServer(mqtt_server, 1883);

should get off.  In the same way, type 1 in message and publish, the NodeMCU led should get on.  We can also monitor and control the LED using MYMQTT app.

INDUSTRIAL INTERNET OF THINGS(20EC52I)

Experiment-05(a)

Simulate the network communication of peer to peer.

Aim: To simulate peer to peer communication Apparatus required:

  • Cisco packet tracer software. Circuit diagram: Procedure:
  • Open cisco packet tracer software. o Create a new file. o Rig up the circuit as shown in circuit diagram. o Select end devices and select or pick two pcs.
  • Select connection (lightning symbol) pick copper cross over it will automatically connect with two pcs.
  • Click on PC0 (desktop 0) select configure click fast Ethernet.
  • Go to IP Configure in place of ipv4 write “10.10.10.0” now the subnet mask will automatically update “255.255.255.0”.
  • Same procedure clicks on PC1 (desktop 1) select configure click fast Ethernet.
  • Ipv4 writes “10.10.10.1” now the subnet mask will automatically update “255.255.255.0”.
  • Click on the message box drag and drop message to both pcs.