오렌지 보드를 사용하여 온도 측정계를 만들어 보자

 
[컴퓨터월드] 아두이노는 이탈리어로 ‘친한 친구’라는 뜻을 가진 대표적인 오픈소스 하드웨어다. 딱딱하고 접근하기 힘들었던 임베디드 분야를 누구나 쉽게 접근할 수 있도록 만든 미니 기판이라 할 수 있다. 이번 강좌에 사용하는 아두이노 오렌지보드는 한국형 아두이노라 할 수 있다.

아두이노의 보급은 오픈소스 하드웨어의 확산을 불러일으켰고 메이커 문화의 확산에도 큰 기여를 했다. 최근에는 인텔, 마이크로소프트 등 대형 기업들도 이런 오픈소스 하드웨어시장에 뛰어들기 시작했다. 그 만큼 오픈소스 하드웨어 시장의 잠재력이 커졌다는 얘기이다.


1) 프로젝트 개요

이번에 소개할 프로젝트는 TMP36 아날로그 온도 센서와 서보모터를 사용하여 만든 온도계이다. 기본적으로 온도계라 하면 유리관에 수은 온도계를 떠올리겠지만, 이번에 만들 온도계는 바늘을 통해 보드에 적힌 눈금으로 온도를 알려주는 그런 온도계이다.

 

기존의 아두이노 튜토리얼에서는 온도센서와 LCD모듈을 사용하여 단순하게 값을 출력하는 예제가 많은데, 그런 단순한 디스플레이에 출력된 값의 형태가 아니라 시계처럼 바늘로 온도를 눈으로 볼 수 있는 색다른 온도계를 만들어 보자.

이번 프로젝트에 필요한 서보모터와 온도센서 모두 구하기 쉬운 모듈이고, 기존 튜토리얼에서 사용법에 관해 설명했기 때문에 사용하는데는 큰 어려움이 없을것이다. 심지어는 아두이노IDE 예제코드에서도 예제를 지원한다.

 

필요한 부품 목록 

 


하드웨어 연결하기

브레드 보드
※TMP36 온도센서를 연결할 때는 평평한 면과 둥근 면을 잘 확인해야 하며, 서보모터의 연결은 선의 색깔을 확인해야 한다. 보통 서보모터의 선 중 검정색은 GND, 빨간색은 VCC, 흰색이나 노란색은 디지털핀에 연결한다.

 

전자 회로도

 


사진에 보이는 프로젝트는 계기판은 컴퓨터를 사용하여 뽑았고 0℃ ~ 30℃까지의 범위를 설정했다. (직접 제작한다면 이 범위는 변경가능하다. 대신 코드 상에서도 수정이 필요하다.) 

 

뒷 부분은 서보모터를 달고 패널 중앙에 구멍을 뚫어 앞쪽의 바늘과 서보모터를 연결하여 온도에 맞게 바늘이 움직인다.

 

소스코드

#include <Servo.h>
//변수 선언
float voltage = 0;
float sensor = 0;
float celsius = 0;
int angle = 0;

Servo myservo; //서보모터 객체 선언

void setup() {
myservo.attach(4); //서보모터를 디지털 핀4번으로 설정합니다.
Serial.begin(9600); //시리얼 통신을 초기화하고 통신속도를 9600bps로 설정합니다.
}

void loop() {
sensor = analogRead(0); //아날로그 0번핀에 연결된 아날로그 온도센서로 부터 값을 읽어들입니다.
//정해진 과정을 통해 센서에서 읽어들인 값을 섭씨온도로 변환합니다.
voltage = (sensor*5000)/1024;
voltage = voltage-500;
celsius = voltage/10;

//시리얼모니터에 온도값을 출력합니다.
Serial.print(celsius);

//map함수를 통해 측정된 온도값을 서보모터가 움직일 각도로 변환시킵니다.
//celsius값은 0부터 30까지의 값만을 유효값으로 읽습니다.
//유효값으로 읽은 0부터 30사의 값을 180부터 0사이의 값으로 변환시킵니다.
int angle = map(celsius,0,30,180,0);
//서보모터의 각도를 시리얼모니터에 출력합니다.
Serial.print(angle);
Serial.println(" degree");

//서보모터에 주어진 각도값이 0부터 180사이의 유효한 값일 경우 서보모터를 제어합니다.
if(angle >=0 && angle <=180) {
myservo.write(angle);
delay(1000); //1초마다 반복하게 됩니다.
}
}

코드는 프로젝트치고 간단한 편이다. 일단 먼저 온도센서 값을 읽어오는 작업을 먼저 하게 된다. 아래 코드가 아날로그 0번핀에 연결된 온도센서에서 값을 읽어와서 섭씨로 변환하는 부분이다.


sensor = analogRead(0); //아날로그 0번핀에 연결된 아날로그 온도센서로부터 값을 읽습니다.
//정해진 과정을 통해 센서에서 받은 값을 섭씨온도로 변환합니다.
voltage = (sensor*5000)/1024;
voltage = voltage-500;
celsius = voltage/10;

//시리얼모니터에 온도값을 출력합니다.
Serial.print(celsius);

온도값을 받았으면 이제 이 값을 게이지에 표현하기 위해 서보모터가 움직일 수 있는 각도로 변환시켜야 한다.

위에서 만든 프로젝트 이미지를 보면 알겠지만 게이지에는 0부터 30까지의 온도를 표시할 수 있도록 했고, 서보모터는 0도부터 180도까지 움직인다. 따라서 0~30의 값을 0~180사이의 값으로 변환시키는 작업이 필요하다. 이 작업은 아두이노의 map()이라는 함수를 통해 할 수 있다.

예를 들어 celsius의 값이 20이 들어오면 서보모터의 값은 60도로 움직이고, celsius의 값이 10이면 서보모터의 값은 120도로 움직이게 된다.

//유효값으로 읽은 0부터 30사의 값을 180부터 0사이의 값으로 변환시킵니다.
int angle = map(celsius,0,30,180,0);


변환된 값이 0~180사이의 유효한 값이라면 이제 서보모터를 제어한다.

//서보모터에 주어진 각도값이 0부터 180사이의 유효한 값일 경우 서보모터를 제어합니다.
if(angle >=0 && angle <=180) {
myservo.write(angle);
delay(1000); //1초마다 반복하게 됩니다.
}


마치며

이 프로젝트는 온도센서가 아닌 다른 센서를 사용하여 다른 형태의 프로젝트로 변형시킬 수 있다. 온도센서가 아닌 습도센서를 사용해 볼 수 있고, 더 나아가 WiFi모듈을 사용하여 웹에서 날씨를 받아와 날씨를 알려주는 알림판으로 사용할 수 있고 아니면 압력센서를 사용해서 자리비움을 체크하는 용도로도 만들어 볼 수 있다.

아래 사진은 코코아팹에 올라온 프로젝트로 압력센서를 사용하여 사용자의 자리비움을 체크하는 프로젝트이다.

 

모듈이 간단한 것이라도 아이디어만 좋다면 얼마든지 실생활에서 유용하게 사용할 수 있는 프로젝트를 만들어볼 수 있다. 물론 꼭 유용해야 하는 법은 없다. 재미와 즐거움 또한 아두이노에서 추구하는 방향이기 때문에 엉뚱하더라도 좋다.

위 프로젝트에 대한 글은 http://kocoafab.cc에서도 확인할 수 있다.

 


[Tutorial] Easy-to-follow Orange Board Tutorial (11)
Making a Temperature Measuring Device Using Orange Board

Arduino means a close friend in Italian and is a typical piece of open-source hardware. It is a mini board made for anyone to easily access an Embedded field, which has been hard and difficult to approach. The Arduino Orange Board to be used in this tutorial is a Korean version of Arduino boards.

The distribution of Arduino boards triggered the spread of open-source hardware and significantly contributed to the spread of Maker Culture as well. Recently, conglomerates such as Intel and Microsoft have also started to enter this open-source hardware market. This reflects that the potential of open-source hardware market has grown likewise.

1) Project Outline

The project that we’ll be working on today is a thermometer made using a TMP36 analogue temperature sensor and a servomotor. Generally, when you think of thermometers, the mercury thermometer comes to mind, but the one that we’ll be making now uses a needle to point to a graduation on a board to tell you the temperature.

 

Existing Arduino tutorials often have exercises that have you use the temperature sensor and LCD module to simply print out the value. Instead of simply showing a printed value on a display, we will be making a unique thermometer that indicates the temperature with a needle, just like a clock.

The servomotor and temperature sensor to be used in this project are all easy modules to find, and as existing tutorials have already explained how they are used, operating them should be a snap. Furthermore, even the Arduino IDE sample codes support this exercise.


List of Items Required

 

Connecting to Hardware

Breadboard
※ When connecting the TMP36 temperature sensor, make sure to confirm the flat side and the round side, and make sure to verify the colors of the lines when connecting the servomotor. In most cases, the black line connects to the GND, red line to VCC, and white or yellow line to the digital pin.

 

Electronic Circuit Diagram

 

The project that you can see in the figure is using a dashboard taken from a computer with a range set between 0℃ ~ 30℃. (If you are making one yourself, then this range can be adjusted. However, this requires modifications to the code as well.)

 

Attach the servomotor to the back and poke a hole in the middle of the panel to connect the servomotor to the needle, allowing the needle to move in tandem with the temperature.

 

Source Code


#include <Servo.h>
//Declare a variable.
float voltage = 0;
float sensor = 0;
float celsius = 0;
int angle = 0;

Servo myservo; //Declare servomotor object.

void setup() {
myservo.attach(4); //Set the servomotor as digital pin 4.
Serial.begin(9600); //Initialize the serial communication and set the communication speed at 9600bps.
}

void loop() {
sensor = analogRead(0); //Read the value from the analogue temperature sensor connected to analogue pin 0.
//The value read from the sensor through the chosen process will be converted into Celsius (℃).
voltage = (sensor*5000)/1024;
voltage = voltage-500;
celsius = voltage/10;
//Print the temperature value on the serial monitor.
Serial.print(celsius);

//Change the measured temperature value into the angle that the servomotor will move by through the map variable.
//The Celsius value only recognizes values between 0 and 30 as valid values.
//Change the values from 0 to 30 read as valid values to values from 180 to 0.
int angle = map(celsius,0,30,180,0);
//Print the angle of the servomotor on the serial monitor.
Serial.print(angle);
Serial.println(" degree");
//If the angle value given to the servomotor is a valid value from 0 to 180, the servomotor will be controlled.
if(angle >=0 && angle <=180) {
myservo.write(angle);
delay(1000); //This is repeated every 1 second.
}
}

The code is fairly simple for a project. First, make sure that the temperature sensor value is read as the initial step. The code below is the part that reads the value from the temperature sensor connected to the analogue pin 0 and then converts the value into Celsius.

sensor = analogRead(0); //Read the value from the analogue temperature sensor connected to analogue pin 0.
//The value read from the sensor through the chosen process will be converted into Celsius (℃).
voltage = (sensor*5000)/1024;
voltage = voltage-500;
celsius = voltage/10;

//Print the temperature value on the serial monitor.

Serial.print(celsius);
 

Once you have received the temperature value, you must then change the value into the angle that the servomotor can move by in order to display the value on the gauge.

As you can tell from the image of the project created above, the gauge has been set to display temperature between 0 and 30, while the servomotor moves from 0 degrees to 180 degrees. Therefore, the values from 0 to 30 must be changed to values from 0 to 180. This process can be done through Arduino’s map() function.

For example, if the Celsius value is 20, the servomotor’s value will move by 60 degrees, and if the Celsius value is 10, the servomotor will move by 120 degrees.

//Change the values from 0 to 30 read as valid values to values from 180 to 0.
int angle = map(celsius,0,30,180,0);
 

 
If the changed value is a valid value between 0~180, the servomotor will now be controlled.

//If the angle value given to the servomotor is a valid value from 0 to 180, the servomotor will be controlled.
if(angle >=0 && angle <=180) {
myservo.write(angle);
delay(1000); //This is repeated every 1 second.
}


Conclusion

You can use a sensor other than the temperature sensor used in this project to change it into a different type of project. You can experiment with a humidity sensor, go even further beyond and use a WiFi module to use it as a notice board that retrieves the weather from the internet and informs you, or use it as a pressure sensor to check for absences.

The picture below shows a project uploaded onto kocoafab that uses a pressure sensor to see if the user is away from the keyboard.

 

Even if the module is simple, as long as the idea is good, you can create programs that are practical in real life. Of course, there’s no rule that states that the projects have to be practical. Arudino strives for fun and enjoyment as well, so it’s perfectly fine to make something bizarre or whimsical as well.

More on the project above can be found at http://kocoafab.cc as well.

 

관련기사

저작권자 © 아이티데일리 무단전재 및 재배포 금지