0% found this document useful (0 votes)
47 views10 pages

IOT Lab Exp

This code uses an ultrasonic sensor and Arduino to monitor water level in a tank. It displays the water level on an LCD screen and controls a motor and buzzer based on the level. If the level is below 12cm, the motor turns off and buzzer sounds. If above 30cm, the motor turns on. It stores the motor state in a variable to prevent repeated triggering.

Uploaded by

sri kanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views10 pages

IOT Lab Exp

This code uses an ultrasonic sensor and Arduino to monitor water level in a tank. It displays the water level on an LCD screen and controls a motor and buzzer based on the level. If the level is below 12cm, the motor turns off and buzzer sounds. If above 30cm, the motor turns on. It stores the motor state in a variable to prevent repeated triggering.

Uploaded by

sri kanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

int trig=9;

int echo=7;

int motor=2;

int a,distance;

void setup()

Serial.begin(9600);

pinMode(trig,OUTPUT);

pinMode(motor,OUTPUT);

pinMode(echo,INPUT);

void loop()

digitalWrite(trig, LOW);

delayMicroseconds(5); // Wait for 5 microsecond(s)


digitalWrite(trig, HIGH);

delayMicroseconds(5); // Wait for 10 microsecond(s)

digitalWrite(trig, LOW);

a=pulseIn(echo,HIGH);

distance=a*0.034/2;

if(distance < 50)

digitalWrite(motor, HIGH);

delay(200);

digitalWrite(motor, LOW);

delay(3000);

else

digitalWrite(motor, LOW);

}
Analog read using potentiometer

void setup() {

// initialize serial communication at 9600 bits per second:

Serial.begin(9600);

// the loop routine runs over and over again forever:

void loop() {

// read the input on analog pin 0:

int sensorValue = analogRead(A0);

// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):

float voltage = sensorValue * (5.0 / 1023.0);


// print out the value you read:

Serial.println(voltage);

#include <LiquidCrystal.h>

#define trigger 10

#define echo 11

#define motor 8

#define buzzer 12

LiquidCrystal lcd(7,6,5,4,3,2);

float time=0,distance=0;
int temp=0;

void setup()

lcd.begin(16,2);

pinMode(trigger,OUTPUT);

pinMode(echo,INPUT);

pinMode(motor, OUTPUT);

pinMode(buzzer, OUTPUT);

lcd.print(" Water Level ");

lcd.setCursor(0,1);

lcd.print(" Indicator ");

delay(2000);

}
void loop()

lcd.clear();

digitalWrite(trigger,LOW);

delayMicroseconds(2);

digitalWrite(trigger,HIGH);

delayMicroseconds(10);

digitalWrite(trigger,LOW);

delayMicroseconds(2);

time=pulseIn(echo,HIGH);

distance=time*340/20000;
lcd.clear();

lcd.print("Water Space In ");

lcd.setCursor(0,1);

lcd.print("Tank is: ");

lcd.print(distance);

lcd.print("Cm");

delay(2000);

if(distance<12 && temp==0)

digitalWrite(motor, LOW);

digitalWrite(buzzer, HIGH);

lcd.clear();

lcd.print("Water Tank Full ");


lcd.setCursor(0,1);

lcd.print("Motor Turned OFF");

delay(2000);

digitalWrite(buzzer, LOW);

delay(3000);

temp=1;

else if(distance<12 && temp==1)

digitalWrite(motor, LOW);

lcd.clear();
lcd.print("Water Tank Full ");

lcd.setCursor(0,1);

lcd.print("Motor Turned OFF");

delay(5000);

else if(distance>30)

digitalWrite(motor, HIGH);

lcd.clear();

lcd.print("LOW Water Level");

lcd.setCursor(0,1);

lcd.print("Motor Turned ON");


delay(5000);

temp=0;

https://www.tinkercad.com/things/hjkq9cWoRnC-car-parking-system-by-arduino

https://www.tinkercad.com/things/1RjtSRlriWu-automated-car-parking-system

You might also like