In this tutorial I want to show you how to build a temperature meter with your ATMEGA chip. You can also simply use an Arduino since this tutorial is based on the Arduino IDE. This tutorial requires a ATMEGA 328 that is already equipped with a bootloader as well as a way to program the ATMEGA chip (either a Arduino Uno or a USB to serial converter).
TL;DR: Buy an ATMEGA 328P-PU (or Arduino Uno), a 16 MHz clock crystal, two 22 pF capacitors, an I2C 128x32 OLED LCD Display and a MLX90614 Sensor
To begin with you need an ATMEGA 328P-PU, an I2C 128x32 OLED LCD Display and a MLX90614 infrared temperature sensor. If you are using a standalone ATMEGA chip instead of an Arduino you will also need a 16 MHz clock crystal and two 22 pF capacitors. The display costs ~3€, the temperature sensor ~4€.
Both the display and the temperature sensore use the I2C protocol. This protocol allows for easy communication with your ATMEGA and only uses two digital pins of your chip (SCL and SDA). Another advantage of I2C is that it is theoretically possible to connect up to 128 devices in parallel (since 128 is the limit of unique I2C addresses).
The wiring is pretty straight foreword. If you take a look at the ATMEGA-328 pinout you will see that the pins 28 (SCA) and 27 (SDA) are used for I2C communication. So you have to connect pin 28 to the SCA pin of your display and a second wire from this pin to the SCA pin of your temperature sensor. The same goes for the SDA pins. After that you have to connect VCC and ground as shown in the wiring diagram.
For a power source I used a 4xAA battery case. With normal disposable batteries this would give you an output voltage of around 6V which could damage your chip and other components since the recommended operating voltage at 16MHz is between 4.5V - 5.5V You could use a voltage regulator or a simple diode to reduce the voltage. I however, used four 1.2V rechargeable batteries which in series output around 4.8V.
TL;DR: Install the Adafruit-SSD1306 and Adafruit-MLX90614 libraries
Before we can get started with programming our chip, we need some libraries for the display and sensor. For the display we need the Adafruit-SSD1306 library, for the temperature sensor the Adafruit-MLX90614 library.
Just go to the linked github pages and click Download ZIP. On a mac you now have to open your programs folder and right click the Arduino IDE. Select “show package contents”. Usually the path to the desired folder should look something like this: /Applications/Arduino.app/Contents/Java/libraries.
You have to unzip and copy the libraries to this directory. After that you need to restart the Arduino IDE.
Just open the Arduino IDE, copy the following code into the editor and press upload:
After you made sure that everything works fine on a breadboard you can move on to solder everything permanently on a circuit board.
This is what my final product looks like: