Requirements
- Arduino Board
- Led
- Arduino IDE
Part 1
To build this circuit connect the led positive side(+) to the digital pin -13 and negative side(-) to the Gnd.
Figure 1: Ddigital pin -13
Part 2
Connect the Arduino board to your computer through USB cable it gives the external power supply to your board
Part 3
Write the following source code to control your led ON and OFF.
Program
- int led = 13;
- void setup()
- {
- Serial.begin(9600);
- pinMode(led, OUTPUT);
- }
- void loop()
- {
- char data = Serial.read();
- switch (data)
- {
- case 'ON':
- digitalWrite(led, HIGH);
- break;
- case 'OFF':
- digitalWrite(led, LOW);
- break;
- }
- }
Part 4 After your source code complete compile and upload your source code to the arduino board after the uploading process. In the Arduino IDE right side corner we have the serial monitor window. Just right click and gives the command ON and press send. The LED will glow and gives command OFF; after the command the led will turn off,
Figure 2: Arduino IDE
Explanation Set the led in the digitalpin-13 void setup() one type of function is used to initialize the variables, pinMode, etc the setup() function will run only once, after each powerup or reset of the arduino board and void loop() it is fully based up on our conditions, how it works and what process it want to do is called loop() function and here we are using the switch statement. It is the selection control statement based upon the condition it will work.
digitaWrite(led,HIGH) supplies 5 volts to the digital pin13 and digitalWrite(led,LOW) take the 13 pin back to the 0 volts, based upon these statements the led will generate the output.