C 0 de
C 0 de
2.
#include <PulseSensorPlayground.h>
const int pulsePin = A0; // Analog pin where the pulse sensor is connected
void setup() {
Serial.begin(9600);
void loop() {
// Read the value from the sensor
int signal = pulseSensor.getBeatsPerMinute();
void setup() {
lcd.begin();
lcd.backlight();
// Print initial message
lcd.setCursor(0, 0);
lcd.print("System Monitor");
lcd.setCursor(0, 1);
lcd.print("Initializing...");
delay(2000);
}
void loop() {
// Update system stats
float networkUtilization = getNetworkUtilization();
float cpuLoad = getCPULoad();
float diskSpace = getDiskSpace();
// Display system stats on LCD
lcd.clear(); // Clear the LCD screen
lcd.setCursor(0, 0);
lcd.print("Network: ");
lcd.print(networkUtilization);
lcd.print("%");
lcd.setCursor(0, 1);
lcd.print("CPU: ");
lcd.print(cpuLoad);
lcd.print("% Disk: ");
lcd.print(diskSpace);
lcd.print("GB");
delay(5000); // Delay for 5 seconds before updating again
}
4.
// Define pin numbers
const int gasPin = A0;
const int ledPin = 8;
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(ledPin, OUTPUT); // Set LED pin as output
}
void loop() {
// Read gas sensor value
int gasValue = analogRead(gasPin);
// Map gas sensor value to LED brightness
int brightness = map(gasValue, 0, 1023, 0, 255);
// Display gas sensor value on serial monitor
Serial.print("Gas Level: ");
Serial.println(gasValue);
// Turn on LED based on gas sensor value
analogWrite(ledPin, brightness);
delay(1000); // Delay for 1 second
}
5.
import RPi.GPIO as GPIO
import time
# Setup GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(pir_pin, GPIO.IN)
GPIO.setup(led_pin, GPIO.OUT)
else :
6.
import time
import board
import adafruit_dht
import thingspeak
from rpi_lcd import LCD
while True:
try:
# Read the sensor data
temperature_c = sensor.temperature
temperature_f = temperature_c * (9 / 5) + 32
humidity = sensor.humidity
7.
import RPi.GPIO as GPIO
import smtplib
from email.mime.text import MIMEText
import time
# Email settings
EMAIL_ADDRESS = '[email protected]' # Your email address
EMAIL_PASSWORD = ' ' # Your email password
TO_EMAIL = '' # Recipient's email address
# Set up GPIO
WPIN = 4
BUZZERPIN=17
GPIO.setmode(GPIO.BCM)
GPIO.setup(WPIN, GPIO.IN)
GPIO.setup(BUZZERPIN, GPIO.OUT)
try:
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as server:
server.login(EMAIL_ADDRESS, EMAIL_PASSWORD)
server.send_message(msg)
print("Email sent successfully")
except Exception as e:
print(f"Failed to send email: {e}")
# Main loop
try:
print("Water Sensor with email (CTRL+C to exit)")
time.sleep(2)
print("Ready")
while True:
if GPIO.input(WPIN): # If water is detected
print("Water sensor is wet!")
GPIO.output(BUZZERPIN,True)
send_email()
time.sleep(5) # Delay to avoid multiple detections
GPIO.output(BUZZERPIN,False)
except KeyboardInterrupt:
print("Program terminated")
finally:
GPIO.cleanup() # Clean up GPIO on exit
8.
import time
import RPi.GPIO as GPIO
import thingspeak
BUZZER_PIN = 33
LDR_PIN = 3
LED = 11
def setup_gpio():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(BUZZER_PIN, GPIO.OUT)
GPIO.setup(LDR_PIN, GPIO.IN)
GPIO.setup(LED, GPIO.OUT)
def ldr():
channel = thingspeak.Channel(id=channel_id, api_key=write_key)
while True:
ldr_value = GPIO.input(LDR_PIN)
if ldr_value == 1:
print("High: Switch on buzzer")
GPIO.output(BUZZER_PIN, True)
print("LED ON")
GPIO.output(LED, True)
else:
print("Low: Don't switch on buzzer")
GPIO.output(BUZZER_PIN, False)
print("LED OFF")
GPIO.output(LED, False)
time.sleep(0.3)
LDRData = ldr_value
BuzzerData = 1 if ldr_value == 1 else 0
if __name__ == "__main__":
setup_gpio() # Initialize GPIO once
try:
ldr() # Start the LDR monitoring loop
except KeyboardInterrupt:
print("Program interrupted")
finally:
GPIO.cleanup() # Clean up GPIO settings