You are on page 1of 6

Ram Prabath 20BCE0931

SLOT: A2+TA2

Programme Name & Branch: B. Tech (CSE)


Course Name & Code: Internet of Things & CSE3009
Class Number (s): VL2023240103902
Faculty Name (s): Prof. K. Balakrishna
Question 1:
Architecture Diagram:
Question 2:
// Define the pins
const int waterLevelSensor = A0; // Water level sensor connected to A0
const int motorControlPin = 7; // Motor control connected to pin 7

// Define the water level thresholds


const int waterLevel50Percent = 512; // Assuming 1023 is 100%, 512 is ~50%
const int waterLevel100Percent = 1023; // Assuming 1023 is 100%

void setup() {
pinMode(waterLevelSensor, INPUT);
pinMode(motorControlPin, OUTPUT);
Serial.begin(9600); // Start serial communication at 9600 baud
}

void loop() {
int waterLevel = analogRead(waterLevelSensor); // Read the water level
float percentage = (waterLevel / 1023.0) * 100; // Convert to percentage

// Check the water level and turn the motor on or off accordingly
if (percentage < 50) {
digitalWrite(motorControlPin, HIGH); // Turn on RO motor
Serial.println("Water level is below 50%, motor switched ON");
} else if (percentage >= 100) {
digitalWrite(motorControlPin, LOW); // Turn off RO motor
Serial.println("Water level reached 100%, motor switched OFF");
}

// Display the current water level percentage


Serial.print("Current water level: ");
Serial.print(percentage);
Serial.println("%");

// Wait for 10 minutes before the next check


delay(600000); // Delay for 10 minutes (600000 milliseconds)
}

Question 3:
import RPi.GPIO as GPIO
import time
import os

# Assuming the temperature sensor is connected to pin 4


temp_sensor_pin = 4
# Assuming the relay is connected to pin 17
heater_relay_pin = 17
# Setup the GPIO pins
GPIO.setmode(GPIO.BCM)
GPIO.setup(heater_relay_pin, GPIO.OUT)

# Function to read temperature from the sensor


def read_temp():
# Replace with the actual code to read from your temperature sensor
# This is just a placeholder
temperature = os.popen("vcgencmd measure_temp").readline()
temperature = temperature.replace("temp=","").replace("'C\n","")
return float(temperature)

# Function to control the heater


def control_heater(temp):
if temp < 10:
GPIO.output(heater_relay_pin, GPIO.HIGH) # Turn on the heater
print("Room temperature is below 10C. Heater ON.")
else:
GPIO.output(heater_relay_pin, GPIO.LOW) # Turn off the heater
print("Room temperature is above 10C. Heater OFF.")

try:
while True:
temp = read_temp()
print(f"Current room temperature: {temp}C")
control_heater(temp)
time.sleep(60) # Wait for 1 minute before reading the temperature again
except KeyboardInterrupt:
# Clean up the GPIO on CTRL+C exit
GPIO.cleanup()

# Clean up the GPIO on normal exit


GPIO.cleanup()

Thank you
Ram Prabath 20BCE0931

You might also like