졸업작품/Multi Analog Sensor Based Project

Multi Analog Sensor Based Project

ElectricShock 2016. 3. 26. 20:16

졸작은 크게 4개의 큰 범주로 나뉜다.

Analog 입력        Analog 출력

Analog 입력        Digital 출력

Digital 입력        Analog 출력

Digital 입력        Digital 출력


이중에서 가장 기본이 되는건 Analog입력  Digital출력 이다.

한개의 입력에 한개의 출력은 가장 하급 이므로 사실상 학생들의 의뢰가 없다고 보면된다.

그래서 최소한 2개 이상의 Multiple inputs는 되야만 졸작으로서의 기본 요건이 된다.


두개의 입력이 들어올때 어떻게 다뤄야할지 갈팡질팡하는 사람이 있는데

알고리즘상에서 두입력중 어떤게 우선순위를 갖는지 보면된다.

그리고 추가로 LCD를 띄워야한다면 아래 내용을 생각해봐야한다.

1. LCD에 아날로그 값이 뜨는지 디지털 값이 뜨는지 혹은 둘다 뜨는지

2.. 단위(Ω,℃,m 등등)을 띄울때 LCD의 좌표는 어떻게 되는지


▼아래는 참고 사이트이다.

http://www.instructables.com/id/Arduino-analog-input-display/?ALLSTEPS




/* hey, this is a simple code to make your arduino read
the value of a potentiometer and display it in percentage form on
a 16 X 2 LCD screen. I am pretty new at this so sorry if this code
is terrible or if i have no idea what i'm talking about in the
comments.

the circuit(pasted from examples):

* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
* Potentiometer attached to analog input 0

* center pin of the potentiometer to the analog pin
* one side pin (either one) to ground
* the other side pin to +5V

*/
#include <LiquidCrystal.h>         //  LCD 사용시 필요한 필수 라이브러리
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);        //Arduino 연결핀

int potPin = A0;                     //센서의 Signal핀.....A0핀에서 뽑는다.
int potValue1 = 0;                    //센서의 초기값
int potValue2 = 0;                 // final display variable  ☆
void setup() 

{
    lcd.begin(16, 2);                     //LCD의 가로세로 사이즈
    lcd.print("Potentiometer");         //표기할 문자열
}

void loop() 

{
// read then divide the input(max 1020 in this case) by 10
    potValue1 = analogRead(potPin) / 10;   

//A0값을 담고있는 potPin을 analogRead로 읽어들여서 10으로 나눈후 변수 potValue1에 담는다.

// divide by 1.02 to get percentage
    potValue2 = potValue1 / 1.02;            //1020/10/1.02 = 100
// set cursor to second row, first column
    lcd.setCursor(0, 1);            //값을 표시하기전에 Cursor좌표
//display final percentage
    lcd.print(potValue2);          //값을 (0,1)에 표시한다.
//print the percent symbol at the end
    lcd.print("%");
//wait 0.1 seconds
    delay(100);
//wipe the extra characters
    lcd.print(" ");
    delay(1);

위의 코드가 LCD표시의 기본 코드가 된다.


신발장 project를 만들기 위해선

먼저 신발이 위치해야하고 (바닥에 버튼눌림 = Digital High Value)

그 다름에 습도센서가 값을 감지해야한다. (습도센서 변수 x > 100 혹은 x < 100)

(여기서 100은 그냥 임의의 변수값이다.)

고민할 필요없이 if 문의 중첩으로 하면된다.





if (버튼 조건)    //눌렸을때

{

if (센서조건)    //기준치 이상인가?...이상일경우 {}안으로 들어간다.

{

Fan동작

}

else        //버튼은 눌렸는데 센서기준이 부합되지않을때

}

else            //눌리지 않았을때





이 개념이 잡혀있다면

처음에 언금한 LCD코드와 if문 중첩코드를 섞어서 컴파일 하면 된다.



Multi_Inputs.txt