Go Down

Topic: Need help with coding : (Read 367 times) previous topic - next topic

SOS1

Apr 24, 2018, 09:12 pm Last Edit: Apr 24, 2018, 10:30 pm by SOS1
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);
}
}

TolpuddleSartre

Can't you just post the code?

My phone doesn't open .ino files.

SOS1

#2
Apr 24, 2018, 10:26 pm Last Edit: Apr 24, 2018, 10:28 pm by SOS1
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.

J-M-L

#3
Apr 24, 2018, 10:50 pm Last Edit: Apr 24, 2018, 10:51 pm by J-M-L
So without any shame stole the code from here 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...
Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

TolpuddleSartre

Code: [Select]
val = analogRead(A0);
Serial.println(val);
if (val == 1)
The chances of an analogRead consistently returning a one are pretty remote.

J-M-L

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...
Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

outsider

#6
Apr 25, 2018, 12:11 am Last Edit: Apr 25, 2018, 12:12 am by outsider
"val" is a boolean, it can only be 1 or 0. Guess it flips at 512.

GarethMoffatt

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

J-M-L

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 :)
Hello - Please do not PM me for help,  others will benefit as well if you post your question publicly on the forums.
Bonjour Pas de messages privés SVP, postez dans le forum directement pour que ça profite à tous

Go Up