Arduino Forum

Using Arduino => Programming Questions => Topic started by: SOS1 on Apr 24, 2018, 09:12 pm

Title: Need help with coding :
Post by: SOS1 on Apr 24, 2018, 09:12 pm
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.

(https://cdn.instructables.com/FQQ/GVZY/IO0GB5FS/FQQGVZYIO0GB5FS.LARGE.jpg)


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

(https://wiki.eprolabs.com/images/thumb/3/38/HC-05.jpg/250px-HC-05.jpg)

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);
}
}
Title: Re: Need help with coding :
Post by: TolpuddleSartre on Apr 24, 2018, 09:23 pm
Can't you just post the code?

My phone doesn't open .ino files.
Title: Re: Need help with coding :
Post by: SOS1 on Apr 24, 2018, 10:26 pm
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.
Title: Re: Need help with coding :
Post by: J-M-L on Apr 24, 2018, 10:50 pm
So without any shame stole the code from here (http://blog.arduinosensors.nl/2016/11/03/arduino-flood-alarm-using-simple-water-level-sensor/) and now you want someone to modify it to meet your project needs?

Quote
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...
Title: Re: Need help with coding :
Post by: TolpuddleSartre on Apr 24, 2018, 10:53 pm
Code: [Select]
val = analogRead(A0);
Serial.println(val);
if (val == 1)
The chances of an analogRead consistently returning a one are pretty remote.
Title: Re: Need help with coding :
Post by: J-M-L on Apr 24, 2018, 11:19 pm
Code: [Select]
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...
Title: Re: Need help with coding :
Post by: outsider on Apr 25, 2018, 12:11 am
"val" is a boolean, it can only be 1 or 0. Guess it flips at 512.
Title: Re: Need help with coding :
Post by: GarethMoffatt on Apr 25, 2018, 04:03 am
My guess is that a Boolean assigned from analog read is 1 unless the analog returns 0.... so basically always 1.
Title: Re: Need help with coding :
Post by: J-M-L on Apr 25, 2018, 10:58 pm
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 :)