MNU ICI334 Lab2
MNU ICI334 Lab2
Overview
Arduino IDE
Sketches
2
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
Arduino IDE
• The Arduino IDE enables you to write and edit code and convert this code into instructions that NodeMCU
hardware understands.
3
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
4
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
5
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
6
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
7
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
• Now, connect your NodeMCU ESP8266, and install the CH340 Driver. • Install the CP2102 Driver.
8
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
Sketches
• A sketch is the name that Arduino uses for a program.
• There are two special functions that are a part of every Arduino sketch: setup() and loop().
• The setup() is called once when the sketch starts.
• It’s a good place to do setup tasks like setting pin modes.
• The loop() function is called over and over and is the heart of most sketches.
• You need to include both functions in your sketch, even if you don’t need them for anything.
9
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
10
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
11
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
12
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
13
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
14
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
15
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
16
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
❑ Components
1) NodeMCU ESP8266 V3
2) LED
3) Photoresistor
4) 330Ω Resistor
5) 10KΩ Resistor
6) Jumpers
7) Breadboard
17
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
Photoresistor: Steps
1) Connect breadboard power (+) and ground (-) rails to NodeMCU 3.3V and GND, respectively.
18
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
Photoresistor: Steps
2) Drag a photoresistor to your breadboard, so its legs plug into two different rows.
19
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
Photoresistor: Steps
3) Create a wire connecting one photoresistor leg to power.
20
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
Photoresistor: Steps
4) Drag a 10KΩ resistor to connect the other photoresistor leg to the ground.
21
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
Photoresistor: Steps
5) Connect the photoresistor leg that is connected with the ground to the NodeMCU A0 pin.
22
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
Photoresistor: Steps
6) Plug the LED into two different breadboard rows.
23
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
Photoresistor: Steps
7) The cathode (shorter leg) connects to one leg of a resistor of 330Ω, and the other resistor leg to the ground.
24
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
Photoresistor: Steps
8) Wire up the LED anode (longer leg) to NodeMCU pin D1.
25
ICI334 IOT Protocols Dr. Abdelwahab Fawzy
Photoresistor: Code