CS3691 Arduino Lab Full Details
CS3691 Arduino Lab Full Details
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.
Aim:
To control an LED using a push button connected to pin 2 of Arduino UNO.
Program:
void setup() {
pinMode(2, INPUT);
pinMode(13, OUTPUT);
}
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 the button is released, the LED turns OFF.
Aim:
To turn ON/OFF an LED based on ambient light using an LDR sensor.
Program:
int ldrPin = A0;
int ledPin = 13;
CS3691 - Embedded System and IoT Lab - Arduino Programs
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 dark light conditions, the LED turns ON. In bright conditions, the LED turns OFF. The LDR value is shown in the Serial
Monitor.
Aim:
To measure and display the temperature using LM35 temperature sensor.
Program:
int sensorPin = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int reading = analogRead(sensorPin);
float voltage = reading * 5.0 / 1024.0;
float temperatureC = voltage * 100;
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" °C");
delay(1000);
}
Output:
The Serial Monitor displays the temperature in degrees Celsius updated every second.