CE351 Lab 2023 Spring
Lab 6 - Build an IoT temperature monitor
Name: Simon Gorman
Email: sbgorman@fortlewis.edu

1. Build an IoT temperature monitor

2. Introduction

Using the Arduino Nano, DS18B20 temperature sensor, and SSD1306 OLED module to prototype a commercial product.

3. Materials and Methods
!Need Arduino IDE installed!
Materials Quantity
Arduino Uno 2
Arduino Nano 2
ESP8266 module 1
DS18B20 temperature sensor 1
SSD1306 OLED module 1
Elegoo Power Supply Module 1
Breadboard 1
1k resistor 1
2k resistor 1
Jumper wires 20

Task 1.1 - Remove redundant functions and only display text



Video 01: Display animations and text on the SSD1306 OLED module


Video 02: Display only the text on the SSD1306 OLED module

Task 1.2 - Read the temperature from DS18B20 from Arduino Nano

Wired an Arduino Uno instead of an Arduino Nano to the DS18B20 sensor using the following connection (see Fig. 01):
wiring from Nano to DS18B20 sensor
Figure 01: Wiring from the Arduino Nano to DS18B20 sensor

Nano to Uno connections:
I also used a 4.7k resistor as the pull-up.

Used the following code to print the temperature to the serial plotter:
// example 1, Temperature to serial plotter
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup()
{
Serial.begin(9600);
sensors.begin();
}
void loop()
{
sensors.requestTemperatures(); // Send the command to get temperature readings
Serial.println(sensors.getTempCByIndex(0));
delay(10);
}
Figure 02: Arduino Code for printing the temperature to the serial plotter

arduino code to read temperature from DS18B20
Figure 03: Serial plotter results

Task 1.3 - Display the temperature on the OLED module (ssd1306)
read temperature to ssd1306 oled module
Figure 04: SSD1306 OLED module displaying the temperature from DS18B20 sensor

Task 2 - Use an ISR while displaying on ssd1306
Ran the following Arduino code (see Fig.05):
// example 3, ssd1306 and Timer1, conflict test. 
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
String myString;
#include <OneWire.h> #include <DallasTemperature.h>
#define ONE_WIRE_BUS 2 OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire);
bool states;
void setup() {  
 noInterrupts();
 TCCR1A=0;
 TCCR1B=0;
 TCNT1=0;
 OCR1A=62500;
 TCCR1B|=(1<<WGM12);
 TCCR1B|=(1<<CS12);
 TCCR1B|=(1<<CS10);
 TIMSK1|=(1<<OCIE1A);
 interrupts();
 pinMode(11,OUTPUT);
 sensors.begin();  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);// Address 0x3C for 128x64
 display.clearDisplay();
 display.display();
} void loop() {  sensors.requestTemperatures();
 myString=String(sensors.getTempCByIndex(0));
 drawChar(myString+" oC"); } void drawChar(String str) {
 display.clearDisplay();
 display.setTextSize(2);      // Normal 1:1 pixel scale
 display.setTextColor(SSD1306_WHITE); // Draw white text
 display.setCursor(0, 0);     // Start at top-left corner
 display.cp437(true);         // Use full 256 char 'Code Page 437' font
 display.print(str);
 display.display();
}
ISR(TIMER1_COMPA_vect){
 states=!states;
 digitalWrite(11,states);
}
Figure 05: Arduino code for using an ISR while displaying to an ssd1306 OLED module

Made the following connections on the breadboard (see Fig.06):

Wiring of using an ISR while displaying on ssd1306
Figure 06: Wiring for Arduino Uno, ESP8266, Elegoo Power Supply Module, SSD1306 OLED module, an LED, and DS18B20 temperature sensor on the breadboard


Video 03: Flashing LED every 4 seconds while using an ISR to display on the SSD1306 OLED module

Task 3 - Build the IoT based temperature monitor
Used the following wiring diagram (see Fig. 00) for the hardware connections:

wiring diagram for master-slave Nanos
Figure 07: Wiring diagram for master-slave Nanos

wiring to breadboard with two Arduino Unos
Figure 08: Breadboard connections using two Arduino Unos

Thingspeak widgets
Figure 09: Thingspeak widgets from ESP8266-01 sensor

4. Results
[]

5. Discussion
My biggest problem was that I couldn't find any bootloaded Arduino Nanos so I resorted to using Arduino Unos instead. I also had to learn how to use Thingspeak for the first time so that was a lot of work. I managed to muddle through it and gained knowledge on new sensors/programs so it was a worthwhile project.