Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with my tinkercad circuit it isnt working. I have code as well. // include the library code: #include // The ultrasonic sensor

I need help with my tinkercad circuit it isnt working. I have code as well.

// include the library code: #include

// The ultrasonic sensor pins are connected to pins 9 and 8 of the arduino #define trigger 9 #define echo 8 /* The lcd circuit: * LCD RS pin to digital pin 2 * LCD Enable pin to digital pin 3 * LCD D4 pin to digital pin 4 * LCD D5 pin to digital pin 5 * LCD D6 pin to digital pin 6 * LCD D7 pin to digital pin 7 * LCD R/W pin to ground * LCD VSS pin to ground * LCD VCC pin to 5V * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) */

// initialize the library with the numbers of the interface pins LiquidCrystal lcd(2, 3, 4, 5, 6, 7); float time=0,distance=0; const int MOTOR = 11; // the motor is connected to pin 11 void setup() { pinMode(trigger,OUTPUT); // set the trigger pin as an output pinMode(echo,INPUT); // set the echo pin as an input pinMode(MOTOR, OUTPUT);// set the relay pin as an output

// set up the LCD's number of columns and rows: lcd.begin(16, 2); lcd.setCursor(2,0); lcd.print("WATER LEVEL"); lcd.setCursor(1,1); lcd.print("CONTROL SYSTEM"); 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); // stores the time span between the transmitted and reflected waves distance=time*0.034/2; //formula to calculate the distance in cm lcd.setCursor(0,0); lcd.print("LEVEL:"); lcd.setCursor(0,1); lcd.print("MOTOR:"); delay(10); if(distance>=40.00) { digitalWrite(MOTOR, HIGH); lcd.setCursor(7,0); lcd.print("LOW"); lcd.setCursor(7,1); lcd.print("ON"); delay(1000); } else if(distance<20.00 && distance >10) { boolean motor_state1=digitalRead(MOTOR);// read the state of the motor pin if (motor_state1== HIGH) { lcd.setCursor(7,0); lcd.print("HIGH"); lcd.setCursor(7,1); lcd.print("ON"); delay(1000); } else { lcd.setCursor(7,0); lcd.print("HIGH"); lcd.setCursor(7,1); lcd.print("OFF"); delay(1000); } }

else if(distance<40.00 && distance >20) { boolean motor_state2=digitalRead(MOTOR); // read the state of the motor pin if (motor_state2== HIGH) { lcd.setCursor(7,0); lcd.print("MEDIUM"); lcd.setCursor(7,1); lcd.print("ON"); delay(1000); } else { lcd.setCursor(7,0); lcd.print("MEDIUM"); lcd.setCursor(7,1); lcd.print("OFF"); delay(1000); } }

else if(distance<=10.00)// check if water is full { digitalWrite(MOTOR, LOW); lcd.setCursor(7,0); lcd.print("FULL"); lcd.setCursor(7,1); lcd.print("OFF"); delay(1000); } delay(1000); }student submitted image, transcription available below

TIN KER CAD Powerful Allis-Gaaris All changes saved a @ O Simulator time: 00:00:09 27 Code Stop Simulation Export Share Ultrasonic Distance Sensor Components Basic HC-SR04 Name Search 1 . . . . . . . . . . . Resistor LED 15 Pushbutton Potentiometer VITA 1929. DIGITAL (PWM- O UNO TE RX ARDUINO Capacitor Slideswitch 11. ANALOG IN 9V Battery Coin Cell 3V TIN KER CAD Powerful Allis-Gaaris All changes saved a @ O Simulator time: 00:00:09 27 Code Stop Simulation Export Share Ultrasonic Distance Sensor Components Basic HC-SR04 Name Search 1 . . . . . . . . . . . Resistor LED 15 Pushbutton Potentiometer VITA 1929. DIGITAL (PWM- O UNO TE RX ARDUINO Capacitor Slideswitch 11. ANALOG IN 9V Battery Coin Cell 3V

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

Students also viewed these Accounting questions

Question

Organize and support your main points

Answered: 1 week ago

Question

Move smoothly from point to point

Answered: 1 week ago

Question

Outlining Your Speech?

Answered: 1 week ago