Help me make a code with 4 water sensor, 4 LED, 3 Water pump
this was my code but its still not work. NEED HELP ASAP
Help me make a code with 4 water sensor, 4 LED, 3 Water pump
this was my code but its still not work. NEED HELP ASAP
int pump2 =2;
int pump3 =3;
int pump4 =4;
int led1 =6;
int led2 =7;
int led3 =8;
int led4 =9;
int air1 =10;
int air2 =11;
int air3 =12;
int air4 =13;
void setup () {
pinMode(pump2, OUTPUT);
pinMode(pump3, OUTPUT);
pinMode(pump4, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(air1, INPUT);
pinMode(air2, INPUT);
pinMode(air3, INPUT);
Serial.begin(9600);
}
void loop() {
int value1=digitalRead(air1);
int value2=digitalRead(air2);
int value3=digitalRead(air3);
int value4=digitalRead(air4);
Serial.println(value1);
Serial.println(value2);
Serial.println(value3);
Serial.println(value4);
delay(1000);
if (value1 == HIGH){
digitalWrite(Led1,HIGH);
Serial.println("BASAH");
}
if (value1 == LOW) {
digitalWrite(led1,LOW);
Serial.println("KERING");
}
if (value2 == HIGH){
digitalWrite(Led2,HIGH);
digitalWrite(pump1,HIGH);
Serial.println("BASAH");
}
if (value2 == LOW) {
digitalWrite(led2,LOW);
digitalWrite(pump1,LOW);
Serial.println("KERING");
}
if (value3 == HIGH){
digitalWrite(Led3,HIGH);
digitalWrite(pump2,HIGH);
Serial.println("BASAH");
}
if (value3 == LOW) {
digitalWrite(led3,LOW);
digitalWrite(pump2,LOW);
Serial.println("KERING");
}
if (value4 == HIGH){
digitalWrite(Led4,HIGH);
digitalWrite(pump3,HIGH);
Serial.println("BASAH");
}
if (value4 == LOW) {
digitalWrite(led4,LOW);
digitalWrite(pump3,LOW);
Serial.println("KERING");
}
}
Welcome to the forum
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
What should the code do and what does it actually do ?
How is the project powered and how are the pumps powered ?
int pump2 =2;
int pump3 =3;
int pump4 =4;
int led1 =6;
int led2 =7;
int led3 =8;
int led4 =9;
int air1 =10;
int air2 =11;
int air3 =12;
int air4 =13;
void setup () {
pinMode(pump2, OUTPUT);
pinMode(pump3, OUTPUT);
pinMode(pump4, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(air1, INPUT);
pinMode(air2, INPUT);
pinMode(air3, INPUT);
Serial.begin(9600);
}
void loop() {
int value1=digitalRead(air1);
int value2=digitalRead(air2);
int value3=digitalRead(air3);
int value4=digitalRead(air4);
Serial.println(value1);
Serial.println(value2);
Serial.println(value3);
Serial.println(value4);
delay(1000);
if (value1 == HIGH){
digitalWrite(Led1,HIGH);
Serial.println("BASAH");
}
if (value1 == LOW) {
digitalWrite(led1,LOW);
Serial.println("KERING");
}
if (value2 == HIGH){
digitalWrite(Led2,HIGH);
digitalWrite(pump1,HIGH);
Serial.println("BASAH");
}
if (value2 == LOW) {
digitalWrite(led2,LOW);
digitalWrite(pump1,LOW);
Serial.println("KERING");
}
if (value3 == HIGH){
digitalWrite(Led3,HIGH);
digitalWrite(pump2,HIGH);
Serial.println("BASAH");
}
if (value3 == LOW) {
digitalWrite(led3,LOW);
digitalWrite(pump2,LOW);
Serial.println("KERING");
}
if (value4 == HIGH){
digitalWrite(Led4,HIGH);
digitalWrite(pump3,HIGH);
Serial.println("BASAH");
}
if (value4 == LOW) {
digitalWrite(led4,LOW);
digitalWrite(pump3,LOW);
Serial.println("KERING");
}
}
type or paste code here
the water sensor supposed to activate the LED and Water pump
so the first and Lowest level is the first water level
Level 1 :
-LED
Level 2 :
-LED no.2
-Water Pump no.1
Level 3 :
-LED no. 3
-Water pump no 2
Level 4:
-LED no. 4
-Water pump no. 3
Im using Relay to On/Off the water Pump
The relay is powered by 9V battery
Not a PP3 battery by any chance ?
If so then it probably can't supply enough current because it is designed to power smoke detectors and has a very low current capacity
But the small water pump is working, when my teacher make the code. But i still dont know the working code
Do the values that you see printed make sense ?
I am just wondering, in this part "(value1 == HIGH)"..........To me that means "is exactly equal to".
Then what is the value of "HIGH" ?
Should it not be "(value1 = HIGH)" ?
titles with "ASAP" slooooow dooooown the solution.
if this is your very first day on Arduino-Forum make sure to
The new member has to get to Discourse trust level one on the forum, which is a pretty trivial matter:
Get to trust level 1 by…
otherwise after 10 postings you can't post anymore for 24 hours
I'm sure you are in high pressure to finish the project but that's your problem not your potential helpers problem.
invest 60 minutes in providing detailed information about your project to save 6 hours = 3600 minutes to get your project up and running.
This detailed information is:
a hand-drawn schematic how you have things wired together
exact type of microcontroller you are using
power-supply that you are using
do your relays have there own power-supply or aure you supplying them from the microcontroller?
do your pumps have there own power-supply or are you supplying them from the microcontroller ?
post the technical specs of your relays and your pumps
if you can't tell them post pictures of the relays and pumps where any kind of numbers written on them can be read. Make sure that it is really readable
best regards Stefan
No
A digital input is other HIGH or LOW and == is used to test equality whereas = is used to set a variable to a value
Thnx Bob, of course, guess I'm still asleep, sorry for the confusion.............
Im really sorry, My teacher code that he wrote on my laptop is gone. So i panicked so that the project is working. Im really sorry
4 times "BASAH" and 4 times "KERING" makes debugging not easier.
If valuex isn't high, it is low.
if (value1 == HIGH){
digitalWrite(Led1,HIGH);
Serial.println("BASAH");
}
if (value1 == LOW) {
digitalWrite(led1,LOW);
Serial.println("KERING");
}
Can written as
if (value1){
digitalWrite(Led1,HIGH);
Serial.println("BASAH 1");
}
else {
digitalWrite(Led1,LOW);
Serial.println("KERING 1");
}
Attent on typos led1 ≠ Led1
The OP should not ignore the question asked with post#9
Is the OP using one of these,
this posting has zero information that could help making your project work.
Maybe except that you feel more relaxed after posting it.
If you are hoping for ready to use code. It is very unlikely that somebody posts ready to use code.
The reason is the "ASAP" in the title
and insufficient information about your hardware.
What exact of microcontroller are you using?
what kind of power-supply?
what type of relay or relay-modul are you using?
is the relay-module low-active or high-active?
how much current do the relay draw?
what is the input-voltage needed by the relays?
It might be that your teacher had he hardware up and running
Are you using the same small waterpump?
What are the specs of this "small water-pump?"
voltage? current?
You should at least post pictures or links of the components that you are using.
For making progress with the code you could use the wokwi-simulator
best regards Stefan
Yes, im using that battery
thank you for your feedback. ill try to be better next time. Thank you kind sir ![]()