Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a circuit design i made in TinkerCAD. I am trying to use the green LED with variable brightness as a function of the

This is a circuit design i made in TinkerCAD. I am trying to use the green LED with variable brightness as a function of the Ultrasonic sensor reading. The three Red LEDs are a warning indicator if the sensor's values exceed a certain threshold. The LCD1602 is used to display the measured values in a proper sequence. My code is attached below. Please show me how I can display my potentiometer readings on the LCD as well as incorporate the temperature sensor

This is my code:

#include float time = 0,distance=0;

LiquidCrystal lcd(2,3,4,5,6,7); int num=1;

// defines pins numbers const int trigPin = 10; const int echoPin = 11; const int buzzer = 12; const int ledR = 13; const int ledY = 9; const int ledG = 8; const int ledB = 1;

// defines variables long duration; int safetyDistance;

void setup() { pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output pinMode(echoPin, INPUT); // Sets the echoPin as an Input pinMode(buzzer, OUTPUT); pinMode(ledR, OUTPUT); pinMode(ledG, OUTPUT); pinMode(ledY, OUTPUT); pinMode(ledB, OUTPUT); lcd.begin(16, 2); lcd.print("Ultrasonic"); lcd.setCursor(0,1); lcd.print("Distance Meter"); delay(2000); lcd.clear(); lcd.print("Circuit Digest"); delay(2000); }

void loop() { lcd.clear(); digitalWrite(trigPin, HIGH); delay(2); digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

// Calculating the distance distance= duration*0.034/2; lcd.setCursor(5,1); lcd.print(float(distance/100)); lcd.setCursor(11,1); lcd.print("m"); delay(500); safetyDistance = distance; if (safetyDistance <= 5) { digitalWrite(buzzer, HIGH); digitalWrite(ledR, HIGH); delay (50); digitalWrite(ledR, LOW); delay (50); digitalWrite(ledY, LOW); digitalWrite(ledG, LOW); digitalWrite(ledB, LOW); } else if (safetyDistance <= 10 && safetyDistance > 5 ) { digitalWrite(buzzer, HIGH); digitalWrite(ledY, HIGH); delay(100); digitalWrite(buzzer, LOW); digitalWrite(ledY, LOW); delay(100); digitalWrite(ledR, LOW); digitalWrite(ledG, LOW); digitalWrite(ledB, LOW); } else if (safetyDistance <= 15 && safetyDistance > 10) { digitalWrite(buzzer, LOW); digitalWrite(ledG, HIGH); digitalWrite(ledY, LOW); digitalWrite(ledR, LOW); digitalWrite(ledB, LOW); } else if (safetyDistance <= 20 && safetyDistance > 15) { digitalWrite(buzzer,LOW); digitalWrite(ledB, HIGH); digitalWrite(ledY, LOW); digitalWrite(ledG, LOW); digitalWrite(ledR, LOW); } else { digitalWrite(buzzer, LOW); digitalWrite(ledR, LOW); digitalWrite(ledY, LOW); digitalWrite(ledG, LOW); digitalWrite(ledB, LOW);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

Students also viewed these Databases questions