CS3691 Arduino Platform and Programs
CS3691 Arduino Platform and Programs
Arduino programs are written in a simplified version of C/C++ and uploaded using USB cable through the Arduino IDE.
1. LED Blinking
Aim:
To blink an LED connected to digital pin 13 of Arduino UNO.
Program:
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}
Output:
The LED connected to pin 13 will blink ON for 1 second and OFF for 1 second repeatedly.
Result:
The LED blinking program was successfully executed and verified.
Aim:
To control an LED using a push button connected to Arduino UNO.
Program:
void setup() {
pinMode(2, INPUT);
pinMode(13, OUTPUT);
CS3691 - Embedded System and IoT Lab - Arduino Programs
}
void loop() {
int state = digitalRead(2);
if(state == HIGH) {
digitalWrite(13, HIGH);
} else {
digitalWrite(13, LOW);
}
}
Output:
When the button is pressed, the LED turns ON. When released, the LED turns OFF.
Result:
Button control of LED was implemented and verified successfully.
Aim:
To turn ON an LED in darkness using an LDR sensor connected to Arduino UNO.
Program:
int ldrPin = A0;
int ledPin = 13;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int ldrValue = analogRead(ldrPin);
Serial.println(ldrValue);
if(ldrValue < 300) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
delay(500);
}
Output:
In low light, the LED turns ON. In bright light, the LED turns OFF. LDR values are displayed on Serial Monitor.
Result:
The LDR-based LED control was executed successfully and tested under different light conditions.