EXPERIMENT NO 2
Controlling
LED Using Switch
Aim:
Controlling
LED using a DIP Switch.
Description:
Understanding the working of DIP switch. When the switch is turned on,
the LED is turned on, and when it is turned off, the LED is turned off.
Hardware Requirement:
ESP32 IoT Development Kit and FRC Cable
Procedure:
1.
Connect P1 port and SV13(Digital Input
Switch) port and connect P2 port and SV2(LED) port using FRC cable as shown
above.
2.
Connect the USB
cable to the board.
3.
Open Arduino IDE .Select DOIT
ESP32 DEVKIT V1in boards and select COM port.
4.
Now Write the program, verify and
Upload it.
5.
Now, when the switch is turned
on, LED gets On.
Program:
const
int
Switch[8]={34,
35,
32,
33,
36,
39,
25,
26}; //declaring
DIP Switches(Port P1)
const
int
Led[8]={23,
22,
21,
19,
18,
5,
17,
16}; //declaring LEDs (Port P2)
for(int i=0;i<8;i++)
{
pinMode(Switch[i],INPUT);
pinMode(Led[i],OUTPUT);
delay(20);
}
}
{
for(int
i=0;
i<8;i++)
{
digitalWrite(Led[i],digitalRead(Switch[i]));
//
Reads the state of each switches and replicate it on LEDs
}
delay(1000);
}
No comments:
Post a Comment