BASIC4MCU | 질문게시판 | 앱인벤터에서 아두이노에서 보낸 데이터를 어떻게 분류해야할지 모르겠어요..
페이지 정보
작성자 쥬노유노 작성일2019-06-08 21:57 조회5,071회 댓글1건본문
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
LiquidCrystal_I2C lcd(0x27, 20,4);
#define DHTPIN 24
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
int Led5 = 22;
int Shock = 32;
int val2;
int fire = 23;
int led1 = 29;
int speaker1 = 30;
int val1 = 0;
double value=0;
double oldValue=0;
int rawValue=0;
int raw = 0;
int cds1=A1;
int led2=45;
int micro = A0;
int ledPower = 3;
int led5 = 26;
int led6 = 27;
int samplingTime = 280;
int deltaTime = 40;
int sleepTime = 9680;
float voMeasured = 0;
float calcVoltage = 0;
float dustdensity = 0;
int sensorPin=A4;
int motorA1Pin=7;
int motorA2Pin=8;
int flag=0;
#include <Servo.h>
#define TRIG 14
#define ECHO 15
int motorA3 = 5;
Servo servo;
Servo servo2;
#include <EEPROM.h>
#define S0 46
#define S1 47
#define S2 48
#define S3 49
#define color 9
int frequency0 = 0;
int frequency1 = 0;
int frequency2 = 0;
int motorA5=42;
int led3 = 28;
#include <Servo.h>
#include <EEPROM.h>
#define S0 46
#define S1 47
#define S2 48
#define S3 49
#define color 9
int frequency0 = 0;
int frequency1 = 0;
int frequency2 = 0;
int motorA5=42;
Servo servo1;
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
pinMode(Led5, OUTPUT);
pinMode(Shock, INPUT);
pinMode(led1, OUTPUT);
pinMode(speaker1, OUTPUT);
pinMode(fire, INPUT);
pinMode(led2, OUTPUT);
pinMode(cds1, INPUT);
pinMode(ledPower,OUTPUT);
dht.begin();
lcd.begin();
lcd.backlight();
pinMode(motorA1Pin, OUTPUT);
pinMode(motorA2Pin, OUTPUT);
pinMode(sensorPin, INPUT);
int cds=analogRead(sensorPin);
if(cds < 400){flag = 0;}
else if(cds >= 400){flag = 1;}
pinMode(TRIG, OUTPUT);
pinMode(ECHO, INPUT);
pinMode(motorA3, OUTPUT);
long distance = pulseIn(ECHO, HIGH)/58.2;
servo.attach(motorA3);
servo2.attach(motorA3);
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(color, INPUT);
pinMode(motorA5, OUTPUT);
digitalWrite(S0,HIGH);
digitalWrite(S1,LOW);
digitalWrite(S2,LOW);
digitalWrite(S3,LOW);
frequency0 = pulseIn(color, LOW);
Serial.print("R= ");
Serial.print(frequency0);
Serial.print(" ");
EEPROM.write(0, frequency0);
digitalWrite(S2,HIGH);
digitalWrite(S3,HIGH);
frequency1 = pulseIn(color, LOW);
Serial.print("G= ");
Serial.print(frequency1);
Serial.print(" ");
EEPROM.write(1, frequency1);
digitalWrite(S2,LOW);
digitalWrite(S3,HIGH);
frequency2 = pulseIn(color, LOW);
Serial.print("B= ");
Serial.print(frequency2);
Serial.println(" ");
EEPROM.write(2, frequency2);
servo1.attach(motorA5);
}
int state1 = LOW;
unsigned long prev_time1 = 0;
int state2 = LOW;
unsigned long prev_time2 = 0;
int state5 = LOW;
unsigned long prev_time5 = 0;
int state11 = LOW;
int state12 = LOW;
int state13 = LOW;
unsigned long prev_time11 = 0;
unsigned long prev_time12 = 0;
unsigned long prev_time13 = 0;
int state3 = LOW;
int state4 = LOW;
unsigned long prev_time3 = 0;
unsigned long prev_time4 = 0;
int state8 = LOW;
unsigned long prev_time8 = 0;
int state17 = LOW;
unsigned long prev_time17 = 0;
void loop() {
val2 = digitalRead(Shock);
unsigned long current_time1 = millis();
if (current_time1-prev_time1 > 1000) {
if(val2 == HIGH){
state1 = HIGH;
digitalWrite(Led5, state1);
playTone(300,160);
Serial.print("지진발생!!!");
Serial1.println("지진발생!!!");
delay(100);
digitalWrite(Led5, LOW);
}
prev_time1 = current_time1;
state1 = LOW;
}
else {
digitalWrite(Led5, LOW);
playTone(0,0);
}
val1=digitalRead(fire);
unsigned long current_time2 = millis();
if (current_time2-prev_time2 > 1000){
if(val1==HIGH){
state2 = HIGH;
digitalWrite(led1,state2);
playTone(300,160);
Serial.print("불이야!!!");
Serial1.println("불이야!!!");
delay(100);
digitalWrite(led1, LOW);
}
prev_time2 = current_time2;
state2 = LOW;
}
else {
digitalWrite(led1,LOW);
playTone(0,0);
}
rawValue=analogRead(A5);
raw = rawValue/10;
value=(0.75*oldValue+(1-0.75)*rawValue);
Serial.print(raw);
Serial.print(", ");
Serial.println(value);
Serial1.print(raw);
Serial1.print(", ");
Serial1.println(value);
oldValue=value;
delay(200);
int cds2=analogRead(cds1);
unsigned long current_time5 = millis();
if (current_time5 - prev_time5 > 1000){
cds2=map(cds2, 0, 1023, 0, 255);
cds2=constrain(cds2, 0, 255);
analogWrite(led2, cds2);
prev_time5 = current_time5;
}
digitalWrite(ledPower,LOW);
delayMicroseconds(samplingTime);
voMeasured = analogRead(micro);
delayMicroseconds(deltaTime);
digitalWrite(ledPower,HIGH);
delayMicroseconds(sleepTime);
calcVoltage = voMeasured * (5.0 / 1024);
dustdensity = -(0.17 * calcVoltage - 0.1)*1000;
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
unsigned long current_time11 = millis();
unsigned long current_time12 = millis();
unsigned long current_time13 = millis();
Serial.print((int)temperature);
Serial.print("*C, ");
Serial1.print("Temp: ");
Serial1.print(temperature,0);
Serial1.println("*C");
Serial.print((int)humidity);
Serial.print("%, ");
Serial1.print("Humi: ");
Serial1.print(humidity,0);
Serial1.println("%");
Serial.print(dustdensity);
Serial.println("ug/m3");
Serial1.print("Dust: ");
Serial1.print(dustdensity,0);
Serial1.println("ug/m3");
String temp = "Temp : ";
temp += (String)temperature;
temp += "C";
String humi = "Humi : ";
humi += (String)humidity;
humi += "%";
String Dust = "Dust : ";
Dust += (String)dustdensity;
Dust += "ug/m3";
lcd.setCursor(0, 0);
lcd.print(temp);
lcd.setCursor(0, 1);
lcd.print(humi);
lcd.setCursor(0, 2);
lcd.print(Dust);
lcd.setCursor(0, 3);
if (current_time11-prev_time11>1000){
if (dustdensity>100){
lcd.print("Use your mask!!");
}
else if ((dustdensity>60) && (dustdensity<=100)){
lcd.print("Just normal day.");
}
else if (dustdensity<=60){
lcd.print("It's a clear day*^^*");
}
prev_time11 = current_time11;
}
if (current_time12-prev_time12>1000){
if (temperature<=15){
state12 = HIGH;
digitalWrite(led5,state12);
}
prev_time12 = current_time12;
state12 = LOW;
}
if (current_time13-prev_time13>1000){
if (temperature>=30){
state13 = HIGH;
digitalWrite(led6,state13);
}
prev_time13 = current_time13;
state13 = LOW;
}
else {
digitalWrite(led5,LOW);
digitalWrite(led6,LOW);
}
int cds=analogRead(sensorPin);
unsigned long current_time3 = millis();
unsigned long current_time4 = millis();
if (current_time3 - prev_time3 > 1000){
if(cds<400 && flag==0){
Cutton_On();
flag=1;
}
prev_time3 = current_time3;
}
if (current_time4 - prev_time4 > 1000){
if(cds>=400 && flag==1){
Cutton_Off();
flag=0;
}
prev_time4 = current_time4;
}
digitalWrite(TRIG, LOW);
delayMicroseconds(2);
digitalWrite(TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG, LOW);
long distance = pulseIn(ECHO, HIGH)/58.2;
Serial.println(distance);
unsigned long current_time8 = millis();
if (current_time8-prev_time8>1000){
if (distance < 10){
servo.write(120);
servo2.write(120);
}
else {
servo.write(0);
servo2.write(0);
}
prev_time8 = current_time8;
}
digitalWrite(S2,LOW);
digitalWrite(S3,LOW);
frequency0 = pulseIn(color, LOW);
Serial.print("R= ");
Serial.print(frequency0);
Serial.print(" ");
digitalWrite(S2,HIGH);
digitalWrite(S3,HIGH);
frequency1 = pulseIn(color, LOW);
Serial.print("G= ");
Serial.print(frequency1);
Serial.print(" ");
digitalWrite(S2,LOW);
digitalWrite(S3,HIGH);
frequency2 = pulseIn(color, LOW);
Serial.print("B= ");
Serial.print(frequency2);
Serial.println(" ");
unsigned long current_time17 = millis();
if (current_time17-prev_time17>1000){
if ((frequency0 >= (EEPROM.read(0)-5)) && (frequency0 <= (EEPROM.read(0)+5)) &&
(frequency1 >= (EEPROM.read(1)-5)) && (frequency1 <= (EEPROM.read(1)+5)) &&
(frequency2 >= (EEPROM.read(2)-5)) && (frequency2 <= (EEPROM.read(2)+5)) ){
servo1.write(0);
}
else {
servo1.write(120);
}
prev_time17=current_time17;
state17=LOW;
}
}
void playTone(long duration,int freq){
duration*=1000;
int period=(1.0/freq)*1000000;
long elapsed_time=0;
while(elapsed_time<duration){
digitalWrite(speaker1,HIGH);
delayMicroseconds(period/2);
digitalWrite(speaker1,LOW);
delayMicroseconds(period/2);
elapsed_time+=(period);
}
}
void Cutton_On(){
digitalWrite(motorA1Pin, HIGH);
digitalWrite(motorA2Pin, LOW);
delay(3000);
digitalWrite(motorA1Pin, LOW);
}
void Cutton_Off(){
digitalWrite(motorA1Pin, LOW);
digitalWrite(motorA2Pin, HIGH);
delay(3000);
digitalWrite(motorA2Pin, LOW);
}
여기서 온도 값 따로 습도 값 따로 미세먼지 값 따로 심박 센서 값 따로 화재감지 센서, 지진감지센서 데이터를 따로해서 어플로 표현해주고 싶은데 어떻게 해야하나요..?
댓글 1
조회수 5,071master님의 댓글
master 작성일
https://www.google.com/search?q=%EC%95%84%EB%91%90%EC%9D%B4%EB%85%B8+%EC%95%B1%EC%9D%B8%EB%B2%A4%ED%84%B0+GPS&pws=0&gl=us&gws_rd=cr
GPS는 컴마(',')를 구분자로해서 여러가지 데이터를 전송합니다.
GPS 예제를 공부한 후 각각의 센서값 사이에 컴마를 추가해서 전송해보세요