Serial Control of LED on Arduino Pin 13
Description:
This program allows the user to control the LED connected to pin 13 of the Arduino using
the serial monitor. When the program starts, the LED is off. Sending '1' via the serial
monitor turns the LED on, and sending '0' turns it off. This can be tested using a physical
Arduino or the Tinkercad Arduino simulator.
C Program:
// Project: Serial Control of LED on Pin 13
// Author: NITHYA SRI D
// Description: The user can control the LED via the serial monitor.
// Send '1' to turn the LED on and '0' to turn the LED off.
const int ledPin = 13; // Pin connected to the LED
char inputChar; // Variable to store serial input
void setup() {
pinMode(ledPin, OUTPUT); // Set pin 13 as output
digitalWrite(ledPin, LOW); // Start with LED off
[Link](9600); // Initialize serial communication at 9600 baud
}
void loop() {
if ([Link]() > 0) { // Check if data is available
inputChar = [Link](); // Read one character
if (inputChar == '1') {
digitalWrite(ledPin, HIGH); // Turn LED on
}
else if (inputChar == '0') {
digitalWrite(ledPin, LOW); // Turn LED off
}
}
}