0
int mamank=13;
void setup() {
  pinMode (mamank,OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(A0);
  Serial.println(sensorValue);
  if(sensorValue>550)digitalWrite(mamank,HIGH);
  else if(sensorValue<500)digitalWrite(mamank,LOW);
  delay(100);       
}

-----------------------------------------------AND this code----------------------

int red=2;
int green=3;
int blue=4;

void setup () {
  pinMode (red,OUTPUT);
  pinMode (green,OUTPUT);
  pinMode (blue,OUTPUT);
  Serial.begin (9600);}

void loop() {
  // read the input on analog pin 0:
  int value = analogRead(A1);

  if (value > 500) {
    Serial.println("Very heavy Rain");
    digitalWrite (red,HIGH);
    digitalWrite(green,LOW);
    digitalWrite(blue,LOW);}
  else if ((value > 300) && (value <= 500)) {
    Serial.println("AVERAGE Rain");
    digitalWrite (green,HIGH);
    digitalWrite (red,LOW);
    }
  else{
    Serial.println("Dry Weather");
    digitalWrite (blue,HIGH);
    digitalWrite (red,LOW);
    digitalWrite (green,LOW);
  delay(100);
  }
  }
0
0

Put the stuff before setup() together, fix any duplicates:

int mamank=13; <<< pin assignment? If yes, this can be byte
int red=2; <<< pin assignment? If yes, this can be byte
int green=3; <<< pin assignment? If yes, this can be byte
int blue=4; <<< pin assignment? If yes, this can be byte

Put the stuff in setup() together, fix any duplicates

void setup() { 
pinMode (mamank,OUTPUT); 
Serial.begin(9600);
pinMode (red,OUTPUT); 
pinMode (green,OUTPUT); 
pinMode (blue,OUTPUT); 
Serial.begin(9600);  <<< duplicate, so delete this line
}

Put the stuff in loop() together, then check the desired functionality:

void loop() { 
int sensorValue = analogRead(A0); 
Serial.println(sensorValue); 
if (sensorValue>550) {
digitalWrite(mamank,HIGH); 
}
else if (sensorValue<500) {
digitalWrite(mamank,LOW); 
}
delay(100);
// read the input on analog pin 0: 
int value = analogRead(A1);
if (value > 500) { 
Serial.println("Very heavy Rain"); 
digitalWrite (red,HIGH); 
digitalWrite(green,LOW); 
digitalWrite(blue,LOW);
} 
else if ((value > 300) && (value <= 500)) { 
digitalWrite (green,HIGH); 
digitalWrite (red,LOW); 
} 
else { 
Serial.println("Dry Weather"); 
digitalWrite (blue,HIGH); 
digitalWrite (red,LOW); 
digitalWrite (green,LOW); 
delay(100); 
} 

}
3
  • What happens when sensorValue is 500 to 550? No change on the output?
    – CrossRoads
    Jan 23 '20 at 15:35
  • it change ,which is not functioning is the one after it
    – jazzz juzz
    Jan 23 '20 at 15:38
  • Thank you this works well, thank you very much man
    – jazzz juzz
    Jan 23 '20 at 15:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.