IOT Assignment 2
IOT Assignment 2
##
//Program to
#include <LiquidCrystal.h
LiquidCrystal lcd(2, 3, 4, 5, 6, 7)
int sw = 10
int outputPin = 9; // set you output pi
int inputPin = 8; // set your input pi
long distance
long cm
void setup()
Serial.begin(9600); // set your baud rat
pinMode(outputPin, OUTPUT)
pinMode(inputPin,INPUT)
pinMode(sw, OUTPUT)
lcd.begin(16, 2)
lcd.setCursor(0, 0)
lcd.print("ENGINEERS GARAGE")
lcd.setCursor(0, 2)
lcd.print("Distance=")
void loop(
int SW=digitalRead(sw)
digitalWrite(outputPin, LOW)
delayMicroseconds(2)
digitalWrite(outputPin, HIGH)
delayMicroseconds(10)
digitalWrite(outputPin, LOW);
distance = pulseIn(inputPin, HIGH); //it now initalizes before
setup to speed up the proces
cm= distance/58; //I don't like reusing the same variable
name, it probably works fine though,
//but i don't really trust it,
besides you have plenty of memory for it
if (SW == HIGH
Serial.println(cm);
delay(500)
lcd.setCursor(10, 2)
lcd.print(cm)
lcd.print(" cm")
delay(100)
}
>
lcd.setCursor(10, 2)
// lcd.print(cm+1)
lcd.print("O of R "); // out of rang
delay(100)
Serial.println(cm);
delay(500); // this will slow down your readings to 2 per second
it should help when watching the Serial termina
// if this helps then start to shrink it down to 100 then 10 then
1,
maybe even go to microsecond delays or remove completely if it
stops freezin
##
Circuit Diagram
}