Hardware components | ||||||
![]() |
| × | 2 | |||
| × | 2 | ||||
![]() |
| × | 2 | |||
| × | 2 | ||||
Software apps and online services | ||||||
![]() |
|
It's always kinda hard to study in the SSHS library. Maybe it's because there's too much CO2 in there.
우리가 개발한 디바이스는 주변 공기의 CO2 농도를 측정하여 다른 디바이스와 통신을 합니다.
그 결과, 여러 개의 디바이스에서 각각 측정한 CO2 농도를 알 수 있고, 학교에서 CO2가 적은 위치가 어디인지 알 수 있습니다.
디바이스의 사용을 돕는 설명용 앱도 만들었습니다.
#include <MQ135.h>
#include <VirtualWire.h>
const int SEND_PIN = 12; //
const int GET_PIN = 11; //
const int BOARD_NUM = 1; //
const int MAP_WIDTH = 40; //
const int MAP_HEIGHT = 20; //
const int PPM_STANDARD = 1000;
#define ANALOGPIN A0 // Define Analog PIN on Arduino Board
MQ135 gasSensor = {ANALOGPIN};
struct LocalData{
int x, y; // x, y
char place_name[10];
int co2_ppm;
};
char print_map[MAP_HEIGHT][MAP_WIDTH]; // map
void setup() {
vw_set_tx_pin(SEND_PIN);
vw_set_rx_pin(GET_PIN);
vw_setup(2000);
vw_rx_start();
Serial.begin(9600);
//
float rzero = gasSensor.getRZero();
delay(3000);
Serial.print("MQ135 RZERO Calibration Value : ");
Serial.println(rzero);
mapInitialize();
}
void loop() {
// put your main code here, to run repeatedly:
sendData(getCo2Ppm());
int board, value;
if (getData(board, value)){
//Serial.print("Got Data ");
//Serial.print(board);
//Serial.print("_");
//Serial.println(value);
//board
printUserInterface(getLocalData(board, value));
}
delay(1000);
}
void sendData(int co2_ppm){
char send_char[VW_MAX_MESSAGE_LEN];
String send_str = String(BOARD_NUM)+String("_")+String(co2_ppm);
strcpy(send_char, send_str.c_str());
vw_send((uint8_t*)send_char, strlen(send_char));
vw_wait_tx();
}
bool getData(int& board, int& co2_ppm){
char get_value[VW_MAX_MESSAGE_LEN];
byte message_length = VW_MAX_MESSAGE_LEN;
bool is_valid = vw_get_message((uint8_t*)get_value, &message_length) ;
if (!is_valid) return false; //
String get_str(get_value);
board = get_str.substring(0,1).toInt();
co2_ppm = get_str.substring(2).toInt();
if (board == BOARD_NUM) return true; //
return true;
}
int getCo2Ppm(){ //CO2 PPM
float ppm = gasSensor.getPPM();
//Serial.println("XXXX");
//Serial.println(ppm);
return(int(ppm));
}
LocalData* const getLocalData(int board, int co2_ppm){ // CO2 PPM LocalData
LocalData* const data_ptr = new LocalData;
//x, y
switch(board){
case 0:
data_ptr->x=5;
data_ptr->y=5;
strcpy(data_ptr->place_name, "");
break;
case 1:
data_ptr->x=10;
data_ptr->y=10;
strcpy(data_ptr->place_name, "");
break;
}
data_ptr->co2_ppm = co2_ppm;
return data_ptr;
}
void mapInitialize(){ //map
for (int _y = 0; _y < MAP_HEIGHT; _y++){
for (int _x = 0; _x < MAP_WIDTH; _x++){
print_map[_y][_x] = ' ';
}
}
}
void printUserInterface(LocalData* const data){
int x = data->x;
int y = data->y;
//
print_map[y][x] = 'O';
print_map[y-1][x+2]=':';
if(data->co2_ppm < PPM_STANDARD) print_map[y-1][x+3] = ')';
else if(data->co2_ppm > PPM_STANDARD
) print_map[y-1][x+3] = '(';
String place_name = data->place_name;
int pos = 0;
for (char c : place_name){
print_map[y][x+2 + (pos)++] = c;
}
//CO2
String s(data->co2_ppm);
s += "PPM ";
pos = 0;
for (char c : s){
print_map[y+1][x+2 + (pos)++] = c;
}
for(int _x=0; _x < MAP_WIDTH; _x++){
//
Serial.print('_');
}
Serial.println("");
for(int _y = 0; _y < MAP_HEIGHT; _y++){
for(int _x = 0; _x < MAP_WIDTH; _x++){
Serial.print(print_map[_y][_x]);
}
Serial.println("");
}
}
Comments