BASIC4MCU | 질문게시판 | 아두이노-앱인벤터 관련 질문입니다.
페이지 정보
작성자 아하어렵다 작성일2021-06-09 22:17 조회7,863회 댓글3건본문
안녕하세요. 아두이노 우노, 아두이노 그로브 베이스 쉴드, L298P 모터 드라이버 쉴드를 가지고 앱 기반 공기청정기를 만드는 중인 사람입니다. 다름이 아니라 아래의 아두이노 코딩을 업로드하여 공기청정기를 구동하는 것과 'Arduino BlueControl' 이라는 앱을 통해 입력한 숫자값을 블루투스 센서(HC-06)를 통해 공기청정기를 구동하는 것에 문제가 없습니다만, 앱인벤터를 통해 해당 디자인과 블록 코딩으로 실행시 블루투스 연결, 해제만 가능하고 미세먼지 농도, 온습도를 포함하는 기타 센서들의 값들이 앱 상에서 표시되지 않고, 각 단계별로 설정한 버튼도 작동하지 않음을 발견하게 되었습니다. 2주를 고민하고 수정했는데 변함이 없어서 도움을 구하고자 질문을 올립니다. 각 코딩은 아래에 첨부했습니다.
<아두이노 코딩>
#include
#include
#include
#include
#define DHTPIN 4
#define LED_PIN 6 // neo pixel 6번 핀
#define PPD42NS 8 // PPD42NS input D8
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
#include "CO2Sensor.h"
Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, LED_PIN, NEO_GRB + NEO_KHZ800);
unsigned long duration;
unsigned long starttime;
unsigned long endtime;
unsigned long sampletime_ms = 15000 ; /* 30초 동안 미세먼지 양 누적 */
unsigned long lowpulseoccupancy = 0;
float ratio = 0; /* 비율값 저장 */
float concentration = 0; /* 농도값 저장 */
float ugm3 = 0;
int discom = 0;
CO2Sensor co2Sensor(A2, 0.99, 100);
int E1 = 10;
int M1 = 12;
SoftwareSerial BT(2, 3);//블루투스 모듈 선언
char data; // 블루투스 통신을 통해 받은 값을 저장하는 변수를 만들어줍니다.
void setup()
{
int i;
Serial.begin(9600);
BT.begin(9600);
pinMode(LED_PIN, OUTPUT);
pinMode(PPD42NS, INPUT);
pinMode(M1, OUTPUT);
strip.begin();
strip.setBrightness(50);
strip.show();
starttime = millis();//get the current time;
digitalWrite(M1, HIGH);
analogWrite(E1, 200);
for (i = 0; i < 5; i++)
{
colorWipe(strip.Color(255, 0, 0), 90);
colorWipe(strip.Color(255, 255, 0), 90);
colorWipe(strip.Color(0, 255, 0), 90);
colorWipe(strip.Color(0, 0, 255), 90);
}
Serial.println("Start");
co2Sensor.calibrate();
strip.begin();
strip.setBrightness(50);
strip.show(); // Initialize all pixels to 'off'
}
void loop()
{
byte h = dht.readHumidity();
byte t = dht.readTemperature();
int val = co2Sensor.read();
duration = pulseIn(PPD42NS, LOW);
lowpulseoccupancy = lowpulseoccupancy + duration;
endtime = millis();
if (BT.available()) // 블루투스 모듈을 통해 새로운 값을 받으면 (회로도 1에서 값을 보내면)
{
data = BT.read();
switch (data) {
case'0':
while (BT.available() == 0)
device_off();
break;
case'1':
break; // 자동모드
case'2':
while (BT.available() == 0)
phase2();
break;
case'3':
while (BT.available() == 0)
phase3();
break;
case'4':
while (BT.available() == 0)
phase4();
break;
}
} else if ((endtime - starttime) > sampletime_ms) //if the sampel time == 15s
{
colorWipe(strip.Color(0, 0, 0), 100);// led 초기화
delay(1000);
ratio = lowpulseoccupancy / (sampletime_ms * 10.0); /* 백분율로 계산 */
concentration = 1.1*pow(ratio, 3)-3.8*pow(ratio, 2)+520*ratio+0.62; /* using spec sheet curve */
ugm3 = concentration * 100 / 13000; /*m3당 마이크로그램 미세먼지 값*/
discom = 0.81 * t + 0.01 * h * (0.99 * t - 14.3) + 46.3;
if (lowpulseoccupancy) {
if (ugm3 > 75) {
phase4();
} else if (ugm3 > 35) {
phase3();
} else if (ugm3 > 15) {
phase2();
} else {
phase1();
}
}
Serial.print("lowpulseoccupancy: ");
Serial.print(lowpulseoccupancy);
Serial.print(" ratio: " );
Serial.print(ratio);
Serial.print(" ugm3: ");
Serial.println(ugm3); /*미세먼지 농도(단위:마이크로그램)*/
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" C");
Serial.print("Discomfort index: ");
Serial.println(discom);
Serial.print("CO2 value: ");
Serial.println(val);
BT.print(ugm3);
BT.print("|");
BT.print(t);
BT.print("|");
BT.print(h);
BT.print("|");
BT.print(discom);
BT.print("|");
BT.print(val);
if (val > 1000 ) {
Serial.println ("Exceed safe value of 1000ppm, ventilate!" );
}
lowpulseoccupancy = 0; /*초기화*/
starttime = millis();/*시작 시간 초기화*/
}
}
void device_off()
{
digitalWrite(M1, HIGH);
analogWrite(E1, 0);
colorWipe(strip.Color(0, 0, 0), 100); // 공기청정기 off
}
void phase1()
{
digitalWrite(M1, HIGH);
analogWrite(E1, 0);
colorWipe(strip.Color(0, 0, 255), 100); // blue
}
void phase2()
{
digitalWrite(M1, HIGH);
analogWrite(E1, 150);
colorWipe(strip.Color(0, 255, 0), 100); // green
}
void phase3()
{
digitalWrite(M1, HIGH);
analogWrite(E1, 200);
colorWipe(strip.Color(255, 255, 0), 100); // yellow
}
void phase4()
{
digitalWrite(M1, HIGH);
analogWrite(E1, 255);
colorWipe(strip.Color(255, 0, 0), 100); // Red
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
< 앱인벤터 블록 코딩 >
< 앱 인벤터 디자인 >
댓글 3
조회수 7,863아하어렵다님의 댓글
아하어렵다 작성일
아두이노 코딩 #include 뒤의 글자가 자꾸 지워지네요 ㅠㅠ
본문 #include 뒤의 글자는
#include <SoftwareSerial.h>
#include <Adafruit_NeoPixel.h>
#include <CO2Sensor.h>
#include <DHT.h>
입니다
master님의 댓글
master 작성일
#include 뒤의 글자가 지워지는 이유는 네이버에서 작성한 코드를 복사했을 때 발생하는 문제입니다.
네이버측에서 삭제하는 것과 마찬가지죠, 원 소스코드를 복사해야지 문제가 생기지 않습니다.
master님의 댓글
master 작성일
여러바이트 전송하는 것은 쉽지 않습니다.
시리얼데이터 전송예제를 많이 공부한 후에 시도해보세요