week 1 lab
week 1 lab
.
TUESDAY: MONITOR LIGHT INTENSITY
void setup() {
// Initialize the serial communication for debugging
Serial.begin(9600);
void loop() {
// Read the analog value from the LDR pin (0-1023)
int lightIntensity = analogRead(ldrPin);
#include <LiquidCrystal.h>
void setup() {
lcd.begin(16, 2); // Set up the LCD's number of
columns and rows #include <LiquidCrystal.h>
lcd.setCursor(0, 0); // Move to the first line
(row 0) // Initialize LCD (RS, E, D4, D5, D6, D7)
lcd.print("BED TIE EEE"); // Print first line LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
lcd.setCursor(0, 1); // Move to the second line const int analogPin = A0; // Potentiometer input pin
(row 1) const float refVoltage = 5.0; // Arduino reference voltage
lcd.print("ATTACH 2025"); // Print second line
} void setup() {
lcd.begin(16, 2);
void loop() { lcd.print("Digital Voltmeter");
// No need to update the display continuously delay(2000);
} lcd.clear();
}
void loop() {
int analogValue = analogRead(analogPin); // Read from A0
float voltage = map(analogValue, 0, 1023, 0, 5000) / 1000.0; //
Convert to 0-5V
lcd.setCursor(0, 0);
lcd.print("DGT VOLTMETER: ");
lcd.setCursor(0, 1);
lcd.print("VOLTAGE = ");
lcd.setCursor(10, 1);
lcd.print(voltage, 2); // Display with 2 decimal places
lcd.print("V"); // Extra spaces to clear old values
#include <LiquidCrystal.h>
#include <LCD1602.h>
// Initialize LCD pins (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
#include <LiquidCrystal.h>
const int PIR_SENSOR = 2; // PIR sensor connected to Digital
// Initialize LCD pins (RS, E, D4, D5, D6, D7)
Pin 2
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup() {
const int LM35_PIN = A0; // LM35 connected to
pinMode(PIR_SENSOR, INPUT); // Set PIR sensor as input
analog pin A0
lcd.begin(16, 2); // Initialize 16x2 LCD
lcd.print("Waiting..."); // Default message
void setup() {
}
lcd.begin(16, 2); // Initialize LCD (16x2)
lcd.print("Temp: "); // Initial text
void loop() {
}
int motionDetected = digitalRead(PIR_SENSOR); // Read PIR
sensor
void loop() {
int sensorValue = analogRead(LM35_PIN); // Read
if (motionDetected == HIGH) { // If motion is detected
analog voltage from LM35
lcd.clear();
float voltage = sensorValue * (5.0 / 1023.0); //
lcd.setCursor(0, 0);
Convert to voltage
lcd.print("Motion Detected!");
float temperature = voltage * 10; // Convert to
delay(5000); // Keep message for 5 seconds
Celsius (LM35 gives 10mV per degree)
lcd.clear();
lcd.setCursor(0, 0);
lcd.setCursor(6, 0); // Move cursor to display
lcd.print("Waiting...");
temperature
}
lcd.print(temperature);
lcd.print(" C "); // Ensure extra spaces to clear
delay(500); // Small delay to prevent flickering
previous values
}
delay(1000); // Update every second
}