how to solve the code problem when i made music Fire alarm by arduino? - Page 1
Forum section: electronics / general

author: david-electrical
author_rank: Newbie
timestamp: May 27, 2016, 09:37:53 am
content: When i made music fire alarm by arduino,i met a problem,the errow shows: empty character constantthe sensor perception the fire,then ARDUINO control buzzer,when fire closer then music to alarmint flame=A5;int Beep=9;int length=15;char notes[]="ccggaagffeeddc ";int beats[]={1,1,1,1,1,1,2,1,1,1,1,1,1,2,4};int tempo=300;int val=0;void playTone(int tone ,int duration){for(long i=0;i<duration*1000L;i+=tone*2) {digitalWrite(Beep,HIGH);delayMicroseconds(tone);digitalWrite(Beep,LOW);delayMicroseconds(tone);}}void playNote(char note,int duration ){char names[]={'c','d','e','f','g','a','b','C'};int tones[]={1915,1700,1519,1432,1275,1136,1014,956};for(int i=0;i<8;i++){if(names==note)playTone(tones,duration);}}void setup(){pinMode(Beep,OUTPUT);pinMode(flame,INPUT);Serial.begin(9600);}void loop() {val=analogRead(flame);Serial.println(val);if(val>=600){ digitalWrite(Beep,HIGH);for(int i=0;i<length;i++){if(notes=='')delay(beats*tempo);elseplayNote(notes,beats*tempo);delay(tempo/2);}}else {digitalWrite(Beep,LOW);}}

author: Mechatrommer
author_rank: Super Contributor
timestamp: May 27, 2016, 10:01:03 am
content: 1st thing 1st.. make proper indentation...

author: obiwanjacobi
author_rank: Super Contributor
timestamp: May 27, 2016, 10:13:40 am
content: Code:int flame = A5;int Beep = 9;int length = 15;char notes[] = "ccggaagffeeddc ";int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };int tempo = 300;int val = 0;void playTone(int tone, int duration){for (long i = 0; i<duration * 1000L; i += tone * 2){digitalWrite(Beep, HIGH);delayMicroseconds(tone);digitalWrite(Beep, LOW);delayMicroseconds(tone);}}void playNote(char note, int duration){char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };for (int i = 0; i<8; i++){if (names == note)playTone(tones, duration);}}void setup(){pinMode(Beep, OUTPUT);pinMode(flame, INPUT);Serial.begin(9600);}void loop(){val = analogRead(flame);Serial.println(val);if (val >= 600){digitalWrite(Beep, HIGH);for (int i = 0; i<length; i++){if (notes == '')delay(beats*tempo);elseplayNote(notes, beats*tempo);delay(tempo / 2);}}else{digitalWrite(Beep, LOW);}}

author: hendorog
author_rank: Super Contributor
timestamp: May 27, 2016, 10:39:06 am
content: I think line 44, which is:Code:if (notes == '')should instead be this:Code:if (notes == '')Same issue on line 25 as wellCode:if (names == note)Edit: And line 47Code:playNote(notes, beats*tempo);Edit: and there is another one too, but you can find that one

author: botcrusher
author_rank: Regular Contributor
timestamp: May 27, 2016, 12:07:58 pm
content: I just want to point out that in most jurisdictions this is100% against fire codeeven presuming your code is bullet proof, until you have it actually approved by a fire marshal / your local group residing over fire law, this is a big nope.

author: dannyf
author_rank: Super Contributor
timestamp: May 27, 2016, 12:44:50 pm
content: QuoteThat's an interesting innovation we can live without: soothing and comforting music when the fire is raging.

author: botcrusher
author_rank: Regular Contributor
timestamp: May 29, 2016, 04:29:04 am
content: Interestingly, HK fire code has a section on alarm parameters, of which one condition is that it is of a certain tone so that it remains recognisable. Making it sing a tune violates that, and removes the urgency from the alarm. Who would exit the building to a hood song?

author: jnz
author_rank: Frequent Contributor
timestamp: May 29, 2016, 05:09:33 am
content: Quote from: botcrusher on May 29, 2016, 04:29:04 amIm fairly sure you meant GOOD song... But I want to beleive you really meant hood song. In which case I look forward to the dual discussions about STM F0 vs NXP 1100 peripheral sets while making analogies to Kendrick's Maad City and Alright, or Lupe Fiasco's Prisoner 1&2, or even what "hood" means in terms of good or bad and if JCole is "hood" still despite Role Modelz being excellent or if something more oscure like Tech N9ne is "hood"-enough.

author: Mechatrommer
author_rank: Super Contributor
timestamp: May 29, 2016, 06:16:22 am
content: just a suggestion...(ps: i'd be surprised if someone come edit this post saying this is a weird and dangerous advice...)

author: botcrusher
author_rank: Regular Contributor
timestamp: May 29, 2016, 07:09:50 pm
content: Oh lol. Yes, i meant "good"But that's hilarious

author: timb
author_rank: Super Contributor
timestamp: May 29, 2016, 07:33:36 pm
content: Quote from: Mechatrommer on May 29, 2016, 06:16:22 amBut... Don't you want to know why we keep starting fires? It's my desire! (My desire!) Danger! Danger! High Voltage! When we touch, when we kiss! Fire in the disco, fire in the disco! Fire in the...Taco Bell... Fire in the disco, fire in the gates of hell! Danger, danger! High Voltage...https://youtu.be/2a4gyJsY0mc

author: stmdude
author_rank: Frequent Contributor
timestamp: May 29, 2016, 07:51:04 pm
content: The "empty character constant" message comes from code like this:Code:a = '';Note that there isn't a character inside the single-quotes. That's not allowed in C.In your code:Code:if (notes == '')you're basically comparing with nothing.Quote from: dannyf on May 27, 2016, 12:44:50 pmMusic to die for/by?