Skip to content

Add NCKU_Smart_Stove_Knob #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions arc_design_contest/2018/NCKU_Smart-stove-knob/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Smart Stove Konb Application
We designed this product for **aging society**. Most of the old in Taiwan live alone because their children work in the city. some of them forget that they are cooking while watching TV, chating, etc. So we designed this smart stove knob to turn off the stove when detecting smoke or the user leave more than three minutes. We aim to reduce the harm from the stove.
* [Introduction](#introduction)
* [Function](#function)
* [Algorithm](#algorithm)
* [System Architecture](#system-architecture)
* [Demo Video](https://v.youku.com/v_show/id_XMzYxMzEzODU1Ng==.html?spm=a2h3j.8428770.3416059.1)
* [Hardware and Software Setup](#hardware-and-software-setup)
* [Required Hardware](#required-hardware)
* [Required Software](#required-software)
* [Hardware Connection](#hardware-connection)
* [User Manual](#user-manual)
* [Before Running This Application](#before-running-this-application)
* [Run This Application](#run-this-application)

## Introduction

**Smart Stove Konb**

Smart Stove Konb reduces the possibilty of the house firing induced by the stove.

### Function

- Turn off the stove when
- Detecting smoke
- The user leave more than three minutes
- Times up when the user set when to turn off the stove(developing)
- Linking to the user's cellphone
- Set when to turn off the stove in the App(developing)
- Check if the stove is on when leaving home(developing)
 ![app][1]

### Algorithm
 ![algorithm][2]

### System Architecture
 ![architecture][3]

## Hardware and Software Setup
### Required Hardware
- 1 [DesignWare ARC EM Starter Kit(EMSK)][4]
- 2 [HM10 module][5]
- 1 [Arduino UNO board][6]
- 1 [Digilent PMOD TMP2][7]
- 1 [MQ2 gas sensor][8]
- 1 [PIR motion sensor module:DYP-ME003][9]
- 1 [servo motor SG90][10]

The list of haraware is shown in the picture following.

### Required Software
- Metaware or ARC GNU Toolset
- Serial port terminal, such as putty, tera-term or minicom
- Arduino

### Hardware Connection
1. EMSK acts as **hub** in this system. It receives stove condition from node, and sends control signal to turn off the stove.
- Connect **HM10** to **J1**
2. Arduino acts as **node** in this system. It gets the condition around the stove with temperature sensor, motion sensor, and smoke sensor. The Arduino board concludes received data, and send the judgement to hub.
- Connect **HM10** to Arduino board as the table below

| HM10 | Arduino |
|------|---------|
| RXD | D9 |
| TXD | D8 |
| GND | GND |
| VDD | 5V |
- Connect **PMOD TMP2** to Arduino board as the table below

| TMP2 | Arduino |
|------|---------|
| SCL | A5 |
| SDA | A4 |
| GND | GND |
| VDD | 5V |
- Connect **MQ2 gas sensor** to Arduino board as the table below
- Connect **motion sensor** to Arduino board as the table below

| motion sensor | Arduino |
|---------------|---------|
| OUT | D5 |
| GND | GND |
| VDD | 5V |
- Connect **servo motor** to Arduino board as the table below

| servo motor | Arduino |
|------------------------|---------|
| PWM input(orange line) | D3 |
| GND(brown line) | GND |
| VDD(red line) | 5V |

## User Manual
### Before Running This Application
Download src code from github and upload them to EMSK and Arduino board respectively.
### Run This Application
Upload src code to EMSK and Arduino board respectively, and open the terminal to observe how they communicate with each other.

| Source Folder | Board |
|------------------|---------|
| src/ARC | EMSK |
| src/Arduino/node | Arduino |


[1]:./doc/pic/app.png "app"
[2]:./doc/pic/algorithm.png "algorithm"
[3]:./doc/pic/system_architecture.png "system_architecture"

[4]:https://www.synopsys.com/dw/ipdir.php?ds=arc_em_starter_kit "DesignWare ARC EM Starter Kit(EMSK)"
[5]:https://goods.ruten.com.tw/item/show?21726620422161 "Ble HM10 module"
[6]:https://goods.ruten.com.tw/item/show?21404239751648
[7]:https://store.digilentinc.com/pmod-tmp2-temperature-sensor/
[8]:https://goods.ruten.com.tw/item/show?21209142783548
[9]:https://goods.ruten.com.tw/item/show?21210114921071
[10]:https://goods.ruten.com.tw/item/show?21211166622336

Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[.ShellClassInfo]
InfoTip=�o�O�b�u�W�@�Ϊ���Ƨ��C
IconFile=C:\Program Files\Google\Drive\googledrivesync.exe
IconIndex=12

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[.ShellClassInfo]
InfoTip=�o�O�b�u�W�@�Ϊ���Ƨ��C
IconFile=C:\Program Files\Google\Drive\googledrivesync.exe
IconIndex=12

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[.ShellClassInfo]
InfoTip=�o�O�b�u�W�@�Ϊ���Ƨ��C
IconFile=C:\Program Files\Google\Drive\googledrivesync.exe
IconIndex=12

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
50 changes: 50 additions & 0 deletions arc_design_contest/2018/NCKU_Smart-stove-knob/src/ARC/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "embARC.h"
#include "embARC_debug.h"

#include "board.h"
#include "dev_uart.h"

//uint32_t baudrate_list[] = {4800, 9600, 19200, 38400, 57600, 115200};

int main(void)
{
uint8_t state;
uint8_t motor;
uint32_t rcv_cnt;
uint32_t baudrate = UART_BAUDRATE_9600;
uint8_t stove_on_cnt = 0;
int t0 = 0;

/** change the init baudrate according to your ble module settings */
EMBARC_PRINTF("Init HM1X with baudrate %dbps\r\n", baudrate);
hm1x_init(baudrate);

while (1) {
rcv_cnt = hm1x_read(&state, sizeof(state));
if (rcv_cnt) {
if (state == 'h') { //stove is on
if (stove_on_cnt < 1) {
EMBARC_PRINTF("STOVE ON!\n");
stove_on_cnt++;
}
t0 = 0;
EMBARC_PRINTF("Cook is in the kitchen\n");
} else if (state == 's') {
EMBARC_PRINTF("It's smoking\n");
} else if (state == 'n') {//no human
t0++;
EMBARC_PRINTF("Cook has leaved for %d seconds\n", t0);
}
if((state == 's') || (t0 >= 10)){
EMBARC_PRINTF("Turn off the stove\n");
motor = 'r';
hm1x_write(&motor, sizeof(motor));
break;
}
}
}

return E_SYS; /* system error */
}

/** @} */
24 changes: 24 additions & 0 deletions arc_design_contest/2018/NCKU_Smart-stove-knob/src/ARC/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Application name
APPL ?= ARC_contest

#
# root dir of embARC
#
EMBARC_ROOT = ../../..

MID_SEL = common

# application source dirs
APPL_CSRC_DIR = .
APPL_ASMSRC_DIR = .

# application include dirs
APPL_INC_DIR = .

# include current project makefile
COMMON_COMPILE_PREREQUISITES += makefile

### Options above must be added before include options.mk ###
# include key embARC build system makefile
override EMBARC_ROOT := $(strip $(subst \,/,$(EMBARC_ROOT)))
include $(EMBARC_ROOT)/options/options.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@

#include <Wire.h> // call library
#define ADT7420_Adresse 0x4B // I2C adress of the Pmod TMP2
#define BT1_RxD 8
#define BT1_TxD 9
#define infrared_pin 5
#define smoke_pin 11

//Déclaration d'un port série
#include <SoftwareSerial.h>
#include <Servo.h>
Servo myservo;
SoftwareSerial BT1(BT1_RxD,BT1_TxD);

int MSB;
int LSB;
int valeur;
int temperature;
int stove_on_cnt=0;
char stove_condition=0;
int pos = 180; // variable to store the servo position
char dirction = 0;
int runtime = 0;
int smoke=0;
int human_state;

void setup()
{
Serial.begin(9600); // initialization of serial communication
myservo.attach(3); // attaches the servo on pin 9 to the servo object
myservo.write(pos);
Wire.begin(); // initialization of I2C communication
Init_ADT7420(); // initialisztion of Pmod AD2 module
BT1.begin(9600);
}

void loop()
{
if(runtime<1)
{
BT1.begin(9600);
if(BT1.available()>0)
{
dirction = BT1.read();
if(dirction == 'r')
{
for(pos = 180; pos >= 0; pos -= 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(20); // waits 15ms for the servo to reach the position
runtime++;
}
Serial.println("Stove has been turned off");
}
}
}
Wire.beginTransmission(ADT7420_Adresse); // Launch of the measure
Wire.endTransmission();
delay(10);
Wire.requestFrom(ADT7420_Adresse, 2); // Recovery of the two bytes MSB and LSB
if(Wire.available() <=2)
{
MSB = Wire.read();
LSB = Wire.read();
}
valeur=(MSB<<8)|LSB ;
temperature=valeur/128;
/*if (((valeur>>15)&1)==0) // If the temperature is positive
{
temperature=valeur/128;
}
else // If the temperature is negative
{
temperature=(valeur-65535)/128;
}
/* Serial.print("MSB="); // display in serial monitor
Serial.println(MSB);
Serial.print("LSB=");
Serial.println(LSB);
Serial.print("Valeur=");
Serial.println(valeur);
*/ Serial.print("Temperature=");
Serial.println(temperature);
//delay(100);
//if(temperature>=40)
//{
if(stove_on_cnt<1){
Serial.println("STOVE ON!");
stove_on_cnt++;
}
human_state = digitalRead(infrared_pin);
smoke = digitalRead(smoke_pin);
if(smoke == LOW) stove_condition = 's';
else if(human_state == HIGH) stove_condition = 'h';
else stove_condition = 'n';
//}
//else stove_condition = 'l';
BT1.write(stove_condition);
delay(1000);
}
// Initialization of Pmod TMP2 module
void Init_ADT7420(void)//temp
{
// Configuring the ADT7420 in 16 bit mode
Wire.beginTransmission(ADT7420_Adresse);
Wire.write(0x03);
Wire.write(0x80);
Wire.endTransmission();
}
50 changes: 50 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "embARC.h"
#include "embARC_debug.h"

#include "board.h"
#include "dev_uart.h"

//uint32_t baudrate_list[] = {4800, 9600, 19200, 38400, 57600, 115200};

int main(void)
{
uint8_t state;
uint8_t motor;
uint32_t rcv_cnt;
uint32_t baudrate = UART_BAUDRATE_9600;
uint8_t stove_on_cnt = 0;
int t0 = 0;

/** change the init baudrate according to your ble module settings */
EMBARC_PRINTF("Init HM1X with baudrate %dbps\r\n", baudrate);
hm1x_init(baudrate);

while (1) {
rcv_cnt = hm1x_read(&state, sizeof(state));
if (rcv_cnt) {
if (state == 'h') { //stove is on
if (stove_on_cnt < 1) {
EMBARC_PRINTF("STOVE ON!\n");
stove_on_cnt++;
}
t0 = 0;
EMBARC_PRINTF("Cook is in the kitchen\n");
} else if (state == 's') {
EMBARC_PRINTF("It's smoking\n");
} else if (state == 'n') {//no human
t0++;
EMBARC_PRINTF("Cook has leaved for %d seconds\n", t0);
}
if((state == 's') || (t0 >= 10)){
EMBARC_PRINTF("Turn off the stove\n");
motor = 'r';
hm1x_write(&motor, sizeof(motor));
break;
}
}
}

return E_SYS; /* system error */
}

/** @} */