Urgent Help Neededd

Hi once again
I need a project assistance from you guys
I have a science project and get stuck at one point.

Pls help me

I am building a rain detecting project which is based on bluetooth.
To brief
I want to control the whole project via bluetooth if A button pressed rain sensor start working and detect rain and when there is rain share raining on serial port and turn on alarm as well as buzzer.

Secondly when press B do switch of the sensor and light and buzzer and do not detect rain

Thirdly when press C
Detect Rain and send raining on Serial monitor and do not turn on buzzer and led

Here is my code

int data;
int rainled = 5;
int rainbuz = 8;
int value=analogRead(A0);
//int rainsensor  = A0;
//int rainvalue = analogRead(rainsensor);
void setup() {
   Serial.begin(9600);
   pinMode(rainled , OUTPUT);
   pinMode(rainbuz , OUTPUT);
   

}
void loop(){
  digitalWrite(A0, LOW);
  digitalWrite(rainled, LOW);
  digitalWrite(rainbuz, LOW);
  if(Serial.available() > 0){
    data = Serial.read();

     if (data == 'A'){
      rainon();
     }
  if (data == 'B'){
      rainof();
     }
     if (data== 'C'){
      rainallof();
     }
  }
}
  void rainon(){
    digitalWrite(A0,HIGH);
    if (value<700){
    Serial.println("Heavy Rain");
   digitalWrite(rainled , HIGH);
   digitalWrite(rainbuz , HIGH);
  }

  else
   digitalWrite(rainled , LOW);
   digitalWrite(rainbuz , LOW);
  }
void rainof(){
   digitalWrite(rainled , LOW);
   digitalWrite(rainbuz , LOW);
  digitalWrite(A0, LOW);
}

void rainallof(){
  digitalWrite(A0,HIGH);
    if (value<700){
    Serial.println("Heavy Rain");
   digitalWrite(rainled , LOW);
   digitalWrite(rainbuz , LOW);
}
 else
   digitalWrite(rainled , LOW);
   digitalWrite(rainbuz , LOW);
  }

Here is my circuit

Thanks in advance hope you understand my project as well as urgency of problem

What is your question exactly?

The thing what I am trying to do it is not happening

1 Like

I want to control the whole project via bluetooth if A button pressed rain sensor start working and detect rain and when there is rain share raining on serial port and turn on alarm as well as buzzer.

Secondly when press B do switch of the sensor and light and buzzer and do not detect rain

Thirdly when press C
Detect Rain and send raining on Serial monitor and do not turn on buzzer and led

these all A B and C button will be press by bluetooth app

it is not a question.
What's wrong with your code? Is it compiled?
Is it works not as expected?
If so - please explain in detail, what are you expecting from code and what are you get now. What is the difference between the cases.

I do not know what's wrong with my code that's why I am taking advice from experts like you

Yes that correct it is not working as expected

How can I do more brief ok, let me try
Look suppose I have 5 Components

  1. Arduino uno
  2. Rain Sensor
  3. Buzzer
  4. LED
  5. Bluetooth HC-05 Module

So I want to control the project via mobile through connecting mobile bluetooth with HC-05 included in project.

When I press A Button Rain Sensor got activate and when there is raining Led and Buzzer also get Turn On

When I press B button Rain Sensor got disabled and led and buzzer also get turn of no detection should be made by rain sensor\

When I press C button rain sensor get activate but this time LED and buzzer should not get turn on only Aert message by serial monitor as written in the code.

But now the issue is things are not going as think all the work and code are getting spoil.
Bluetooth is not turn on sensor or turning of sensor bluetooth is not displaying anything also it is connected properly

Pls find the circuit diagram

Hope you now understand and able to help me urgently

what's the urgency? school project due today?

Why is there a digitalWrite to A0?
Initializing value to analogRead(A0) only sets the initial value of the variable, it does not automatically update after that.

Yessssss

What do you mean to say sorry to say but I am not able to understand is there anything wrong in my code can you pls assist me to right it or suggest ay other code or any other action so that my project can complete by today.
Working on the project from last 3 days

You will need to use analogRead to get the current data from the rain sensor, just having that in the declaration of the variable value does not continuously update the variable.

Sorry, I have work, do not have time to help this morning.

Could u pls just help me for a while it is very important for me in line "int value=analogRead(A0);" in the code I have do this.
Could you pls tell the line which I am doing mistake or could you pls share me the updated code

well, we won't do your homework for you.

what you need is some sort of state machine where the commands you get from Serial modify the mode you are in and then based on the mode, you decide what you want to check and do.

this could help you get started:

const byte rainLedPin = 5;
const byte rainBuzzerPin = 8;
const byte rainSensorPin = A0;

enum : byte {OFF_MODE, QUIET_MODE, ACTIVE_MODE} mode = OFF_MODE;

void allOff() {
  digitalWrite(rainLedPin , LOW);
  digitalWrite(rainBuzzerPin , LOW);
}

void setup() {
  pinMode(rainLedPin , OUTPUT);
  pinMode(rainBuzzerPin , OUTPUT);
  Serial.begin(9600);
}

void loop() {
  switch (Serial.read()) { // will return -1 if there is nothing to read
    case 'A':
      allOff();
      mode = ACTIVE_MODE;
      break;

    case 'B':
      allOff();
      mode = OFF_MODE;
      break;

    case 'C':
      allOff();
      mode = QUIET_MODE;
      break;

    default: break; // ignore anything else
  }

  switch (mode) {
    case OFF_MODE: break; // Nothing to do

    case QUIET_MODE:
      // do something here
      break;

    case ACTIVE_MODE:
      // do something here
      break;
  }
}

PS: hint - you'll need an analogRead() when you want to get the value of the sensor.

your code won't compile because you forget to close the rainon() procedure:

It is already been closed in the code

Thankyou so much I have no words to describe how big problem you have solved.

I Have last one more query.
How to turn on and of any sensor like rain sensor through bluetooth lets say how to send HIGH and LOW Output so that sensor can turn of and on

Tried this but it won't work
digitalWrite(2 , HIGH);

On 2 I have connected VCC pin to pin 2

the sensor you have is always 'ON' as you feed it with 5V from the board.

if you switch this to a regular pin, like pin 2 (give it a name, like sensorPowerPin, don't use PIN numbers directly in the code it's not readable) instead of 5V, you need first to check how much current the sensor requires and the pin won't be able to provide a lot (20mA as run rate, 40mA peak). if this works, then setting the pin to HIGH will send current into the sensor and LOW will deactivate it.

so go look at the specification for


and see if it can be powered by a pin.

but you could also keep the sensor powered and when you don't need the sensor, just don't read the value on pin A0

PS: the adaptor board has a potentiometer and digital output so you could fine tune when rain is detected by turning the potentiometer and use the digital output instead of the analog one. this way you wouldn't have to hardcode the threshold value 700 in your code

Thankyou

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