Arduino code to circuit board and flowchart

Do you know how to make the circuit board for this code?

#include<LiquidCrystal.h> // include the library code for lcd
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //
#define echopin 9 // echo pin
#define trigpin 8 // Trigger pin

int maximumRange = 50;
long duration, distance;

void setup() {
lcd.begin(16,2);
Serial.begin (9600);
pinMode (trigpin, OUTPUT);
pinMode (echopin, INPUT );
pinMode (4, OUTPUT);
pinMode (13,OUTPUT);
}

void loop ()
{

{
digitalWrite(trigpin,LOW);
delayMicroseconds(2);
digitalWrite(trigpin,HIGH);
delayMicroseconds(10);
duration=pulseIn (echopin,HIGH);
distance= duration/58.2;
delay (50);
Serial.println(distance);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("WATER LEVEL :");
lcd.print(distance);
delay(0);

}

if (distance <= 90){
  digitalWrite (13,HIGH);// connect to relay(motor)
  digitalWrite (7,HIGH);
  lcd.setCursor(0,1);
  lcd.print("TANK IS FULL");
  delay(0);
  }
  
  else if (distance >=10) {
    digitalWrite (7,LOW); // connect to relay(motor)
    digitalWrite (13,LOW);
    lcd.setCursor(0,1);
    lcd.print("PUMP STARTED");
    delay(1000);
    
    }
    }

Yes. Post the schematic and I'm sure ppl will have ideas about how to make the circuit board.

a7

1 Like

I mean, draw the schematic diagram for the code provided. :slight_smile:

Haha. OK I see.

Where did the code come from? Did not that source supply other information like the parts you need and... how they are to be connected to power and the Arduino?

What does the code do?

a7

https://forum.arduino.cc/uploads/short-url/pQHnOt90fYJmoCSRhLpko9IbgLy.pdf

2 Likes

do you really need a schematic/PCB for this?
doesn't the above indicate how to connect an LCD and ultrasonic sensor?

Tell us exactly what you need.

Who wrote that sketch ?

What components do you have ?

You still mean you want us to draw a schematic diagram, right?

It is your code, your project. I don't see how you wrote all that the code with no idea of what you are connecting or how it should be connected.

Where did you learn how to write code for an LCD? Did none of those places show how to connect an LCD?

Where did you learn how to write code for an ultrasonic range finder? Did none of those places show how to connect an ultrasonic range finder?

How is the power to the pump being controlled?

You've recently added in some idea of solar panels being involved.

We could guess but maybe only come close enough to make providing such guess work a step in the wrong direction.

TBH your own guessing would be better than all of us doing.

a7

Do you mean flowchart?
Code doesn’t have "schematics", hardware does.
You START with a hardware schematic and write code to match the hardware. You don't write random code and then try and figure out what the hardware does. Hardware is a GIVEN!
Perhaps there is a language or terminology issue?

Drawing of idea.

[edit: needed a relay, added corrected debug code and this simulation]

#include<LiquidCrystal.h> // include the library code for lcd
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // RS, EN, D4, D5, D6, D7 // VSS, RW, K - GND // VDD, A - 5V
#define echopin 9 // echo pin
#define trigpin 8 // Trigger pin

int maximumRange = 50;
long duration, distance;

void setup() {
  randomSeed(analogRead(A0)); // debug
  lcd.begin(16, 2);
  Serial.begin (9600);
  pinMode (trigpin, OUTPUT);
  pinMode (echopin, INPUT );
  pinMode (4, OUTPUT);
  pinMode (13, OUTPUT);
}

void loop ()
{
  digitalWrite(trigpin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigpin, HIGH);
  delayMicroseconds(10);
  duration = pulseIn (echopin, HIGH);
  distance = duration / 58.2;
  delay (50);

  distance = random(10, 100); // debug values for water level

  Serial.println(distance);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("WATER LEVEL: ");
  lcd.print(distance);
  delay(10);

  if (distance >= 90) {
    digitalWrite (13, LOW); // turn LED OFF
    digitalWrite (7, LOW); // disconnect relay(motor)
    lcd.setCursor(0, 1);
    lcd.print("TANK IS FULL");
    delay(1000);
  }

  else if (distance <= 20) {
    digitalWrite (7, HIGH); // connect relay(motor)
    digitalWrite (13, HIGH); // turn LED ON
    lcd.setCursor(0, 1);
    lcd.print("PUMP STARTED");
    delay(1000);
  }

  else if (distance > 10 && distance < 90)
    digitalWrite(7, LOW); // pump is off
}
2 Likes

Ok, next step is actual part numbers and THEN we can talk wiring.

Thank you Sir!

Is there a way for you to update this? The "END" is in a "connector" (circle) when it should be in a "terminator" oval (as the start is). I like it.

can you create a flowchart based on the information above?

Yes, I can.

1 Like

Can you make it for me?

No.

A flowchart is a description of your code in picture-form.

You can draw it by hand (you do not need to use a computer).

  • Start with a "terminal" symbol (latin for "end point").
  • initialize hardware and variables inside an "initialization" symbol
  • input and output inside rhomboid (slanted rectangle)
  • decisions (if..then, switch...case, while..do) inside a "decision" (rhombus)
  • process in a rectangle
  • loop using connectors (circle)

Make one. You will see how easy it is, and doing it will make you think about how your program works... or does not work.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.