Professional Documents
Culture Documents
Digital Thermometerusing Arduinoand MCP9808 Digital Temperature Sensor
Digital Thermometerusing Arduinoand MCP9808 Digital Temperature Sensor
net/publication/322530363
CITATION READS
1 7,013
2 authors:
All content following this page was uploaded by J. Martinos on 16 January 2018.
Digital Thermometer
Using Arduino and MCP9808 Digital Temperature Sensor
John Martinos
Introduction ioannismartinos@gmail.com
The purpose of this project was to learn how to program a http://www.researchgate.net/profile/J_Martinos
microcontroller and build pc software which communicates with LinkedIn: John Martinos
the microcontroller. Send commands to the microcontroller and Themis Martinos
receive data from a sensor. As a platform for the microcontroller themismartinos@gmail.com
we used the Arduino UNO R3 development board which is the http://www.researchgate.net/profile/Themis_Martinos
most popular and documented product of the whole Arduino LinkedIn: Themis Martinos
family. The Arduino UNO is a microcontroller board based on the
ATmega328P. It has 14 digital input/output pins, 6 analog inputs,
a USB connection, a power jack and everything needed to
support the microcontroller. For the scope of this project we
used the Arduino UNO to control the MCP9808 digital
temperature sensor, with a typical/maximum accuracy of
±0.25°C/±0.5°C over the sensor's -40°C to +125°C range. The
MCP9808 comes from Adafruit as a breakout board PCB with a
library for the Arduino, which makes it very easy to connect and
get readings from the sensor. We used the Arduino IDE software
to write the code for the microcontroller and uploaded it to the
board. For the PC software we used the Visual Studio
Community edition and wrote a windows form application in C#
which communicates with the Arduino UNO via the COM port.
Figure 1 shows the GUI for the PC software. We also, made an
extension board "module" (see Figure 2) which connects to the
Arduino Uno via pin headers. The circuit for the "module" was Figure 1. Graphical User Interface "GUI" for the PC software.
made on a PCB universal prototyping board 70X90mm. On the
board we placed a 16X2 LCD character display which connects to
the board via pin headers, the temperature sensor which is also
connects to the board via pin headers, a Potentiometer to
control the contrast of the LCD, a buzzer, 5 DIP switches, a LED
and 7 resistors.
[1]
Martinos TEAM Schematic and Connections Diagrams for the "Module"
16/01/2018 Published on Research Gate
8 11
9 1: Arduino Uno R3
2: LCD 16X2 Characters
3: MCP9808 Temp. Sensor
4: Buzzer 5V, 12mm
5: 220Ω Resistor
6: 220Ω Resistor
1 7: 4kΩ Potentiometer
0 8: LED
10 9: 10kΩ Resistor
00 10: 1kΩ Resistor
00 11: DIP Switch 5 Position
Figure 4. Connections diagram for the "module". Figure 5. Arduino UNO R3.
If the UNO cannot find the MCP9808 for some reason, then it prints
the message "Connection to MCP9808 Failed" to the LCD.
Switch 1 Switch 5
Switch 4
Switch 3
Switch 2
The readings from the temperature sensor are printed on the graph
as it shows the figure above. The vertical line of the graph represents
the value of the temperature on Celsius or Fahrenheit. The
horizontal line represents the number of the loops. The horizontal
lcd.setCursor(0,0); if (Serial.available()> 2)
lcd.print(" Digital "); {
lcd.setCursor(0,1); inputByte_0 = Serial.read();
lcd.print(" Thermometer "); delay(10);
delay(1000); inputByte_1 = Serial.read();
lcd.clear(); delay(10);
inputByte_2 = Serial.read();
if (!tempsensor.begin()) { delay(10);
Serial.println("Couldn't find MCP9808!");
We used the Visual Studio Community edition and wrote a windows form application in C# which communicates with the Arduino UNO via
the COM port. This program consists of three main tabs. In the tab "Form1.cs" we have the main code (and main class) for the program. In the
tab "Form1.cs [Design]" we have designed the graphical user interface "GUI" for the program. The part of the code which reads the COM
ports and establishes the connection with the device, it is written in a second class. This part of the code it is written in the tab
"Connector.cs". First step for the code is to get all the available COM port names. Then to each COM port name it sends a buffer and wait for
a specific response. If the response is the message " I'M ARDUINO " then it saves the name of this port in a variable. On the next step it opens
this port and sends a buffer. As a response it gets back the data from the sensor.
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
chart2.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
Celsius.Checked = true;
Fahrenheit.Checked = false;
trackBar.Value = 1500;
TimerPlot.Text = trackBar.Value + "";
}
try
{
Status.Text = "Connection Successful - Connected to " + comport.port;
if (Celsius.Checked==true)
{
if (TF == true)
{
chart2.Series[0].Points.Clear();
TF = false;
Units.Text = "C";
}
String TempMessage = comport.message(4, 8, 32);
DataOut.Text = "";
DataOut.Text = TempMessage;
chart2.Series[0].Points.AddY(TempMessage.Substring(0, 5));
}
else
{
if (TF == false)
{
chart2.Series[0].Points.Clear();
TF = true;
Units.Text = "F";
}
String TempMessage = comport.message(4, 8, 64);
DataOut.Text = "";
DataOut.Text = TempMessage;
chart2.Series[0].Points.AddY(TempMessage.Substring(0, 5));
}
}
catch
{
Status.Text = ("Connection was lost - Searching . . .");
}
}
private void chart2_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void DataOut_TextChanged(object sender, EventArgs e)
{
}
private void Status_TextChanged(object sender, EventArgs e)
{
}
private void Celsius_CheckedChanged(object sender, EventArgs e)
{
Units.Text = "C";
}
private void Fahrenheit_CheckedChanged(object sender, EventArgs e)
{
Units.Text = "F";
}
private void Units_Click(object sender, EventArgs e)
{
}
namespace WindowsFormsApp1
{
class Connector
{
public string port = "";
static SerialPort currentPort;
public Boolean connect(int baud, string recognizeText, byte paramone, byte paramtwo, byte paramthree)
{
try
{
byte[] buffer = new byte[3];
buffer[0] = Convert.ToByte(paramone);
buffer[1] = Convert.ToByte(paramtwo);
buffer[2] = Convert.ToByte(paramthree);
int intReturnASCII = 0;
char charReturnValue = (Char)intReturnASCII;
string[] ports = SerialPort.GetPortNames();
foreach (string newport in ports)
{
currentPort = new SerialPort(newport, baud);
currentPort.Open();
currentPort.Write(buffer, 0, 3);
Thread.Sleep(200);
int count = currentPort.BytesToRead;
string returnMessage = "";
while (count > 0)
{
intReturnASCII = currentPort.ReadByte();
returnMessage = returnMessage + Convert.ToChar(intReturnASCII);
count--;
}
currentPort.Close();
port = newport;
if (returnMessage.Contains(recognizeText))
{
return true;
}
}
return false;
}
catch (Exception e)
{
return false;
}
}
public string message(byte paramone, byte paramtwo, byte paramthree)
{
try
{
byte[] buffer = new byte[3];
buffer[0] = Convert.ToByte(paramone);
buffer[1] = Convert.ToByte(paramtwo);
buffer[2] = Convert.ToByte(paramthree);
currentPort.Open();
currentPort.Write(buffer, 0, 3);
int intReturnASCII = 0;
char charReturnValue = (Char)intReturnASCII;
Thread.Sleep(200);
int count = currentPort.BytesToRead;
string returnMessage = "";
while (count > 0)
{
intReturnASCII = currentPort.ReadByte();
returnMessage = returnMessage + Convert.ToChar(intReturnASCII);
count--;
}
currentPort.Close();
return returnMessage;
}
catch (Exception e)
{
return "";
}
}
}
}