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
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
Arduino uno
Rain Sensor
Buzzer
LED
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
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.
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
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.
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);
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.
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