Need help with coding :

Hello guys and gals, i'm making a flood sensor that is connected to a Bluetooth module, that can send a message to my phone when it registers water.

The problem is that i have little to no idea how to code, and the deadline for finishing my project is in 2 weeks, everything is fine and dandy except the part where i have to make the Bluetooth module send a message to my phone.

I don't know how i would code this, so i would really appreciate it if somebody could help me with it. So far i have a water sensor with a buzzer and LED that activates when the sensor detects water. I just need help with coding the Bluetooth module.

I have attached a file with the code i have right now.

EDIT:
Here's the schematics of the Arduino with sensor, LED and buzzer. I understand i will need to use a external board to fit the Bluetooth module aswell if i'm correct.

Image of the Bluetooth module (HC-05) i'm using:

Here's the code:
int WaterAlarm = 1;
int Buzzer = 9;
int Led = 10;
boolean val;

int tones[] = {261, 277, 293, 311, 329, 349, 369, 392, 415, 440, 466, 493, 523 ,554};

void setup() {
Serial.begin(9600);
pinMode (WaterAlarm, INPUT);
pinMode (Buzzer, OUTPUT);
pinMode (Led, OUTPUT);

}

void loop() {

val = analogRead(A0);
Serial.println(val);
if (val == 1)
{
digitalWrite(Led, HIGH);
digitalWrite(Buzzer, HIGH);
tone(Buzzer, tones[6]);
delay(200);
digitalWrite(Led, LOW);
digitalWrite(Buzzer, LOW);
noTone(Buzzer);
delay(200);
digitalWrite(Led, HIGH);
digitalWrite(Buzzer, HIGH);
tone(Buzzer, tones[14]);
delay(200);
digitalWrite(Led, LOW);
digitalWrite(Buzzer, LOW);
noTone(Buzzer);
delay(200);
}
else
{
digitalWrite(Led, LOW);
digitalWrite(Buzzer, LOW);
}
}

Code_Flood_Sensor.ino (865 Bytes)

Can't you just post the code?

My phone doesn't open .ino files.

TolpuddleSartre:
Can't you just post the code?

My phone doesn't open .ino files.

Hi, I've updated my post with the code you requested and additionally added schematics of my Arduino and Bluetooth module.

So without any shame stole the code from here and now you want someone to modify it to meet your project needs?

the deadline for finishing my project is in 2 weeks

I don't think the community here wants to help anyone cheat.

do something about it - study, propose your modifications and we might help...

val = analogRead(A0);
Serial.println(val);
if (val == 1)

The chances of an analogRead consistently returning a one are pretty remote.

TolpuddleSartre:

val = analogRead(A0);

Serial.println(val);
if (val == 1)


The chances of an analogRead consistently returning a one are pretty remote.

That’s the part OP modified compared to original source code.. OP’s innovation and contribution...

"val" is a boolean, it can only be 1 or 0. Guess it flips at 512.

My guess is that a Boolean assigned from analog read is 1 unless the analog returns 0.... so basically always 1.

GarethMoffatt:
My guess is that a Boolean assigned from analog read is 1 unless the analog returns 0.... so basically always 1.

It’s a very good guess... as i said OP’s contribution to science :slight_smile: