Arduino Two Channel Thermometer with Display (Full Code)

Pictured below is a two-channel thermometer we recently built for a customer. This device takes inputs from two ds18b20 temperature sensors and displays their measured temperatures on a 1602 LCD display module. The thermometer is built around an Arduino Pro Mini.

Arduino double thermometer with lcd display - full code provided

Below is the full Arduino sketch (code) for our device.

See this guide to Connecting an I2C Display to Arduino for the LCD connections. We have added the necessary 3k3 pull up resistors between pin A4 and 5V, and pin A5 and 5V – click here to read about I2C Pull Up Resistors. We have also used an external 5V regulator rather than relying on the 5V regulator built into the Arduino Pro Mini, and added reverse polarity protection on the input with a 1N4001 diode.

// © reuk.co.uk - 2018
// Double Thermometer with Display.

// For the DS18B20 temperature sensors.
#include <OneWire.h> // (https://github.com/PaulStoffregen/OneWire)
#include <DallasTemperature.h> // (https://github.com/milesburton/Arduino-Temperature-Control-Library)

// Data wires are plugged into pins 2 and 3 on the arduino.
#define ONE_WIRE_BUS 2
#define SECOND_BUS 3

// For the 1602 LCD module.
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27 // Note that some modules have address 0x3F

#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

// Setup a oneWire instances to communicate with OneWire devices.
OneWire oneWire(ONE_WIRE_BUS);
OneWire secondWire(SECOND_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensor1(&oneWire);
DallasTemperature sensor2(&secondWire);

float sensorOneTemperature = 0.0;
float sensorTwoTemperature = 0.0;

void setup(void)
{
 // Start up the temperature sensor library.
 sensor1.begin();
 sensor2.begin();
 
 // Set the temperature sensor resolutions to 11 bit
 // ADC (12 bit is much slower but higher resolution).
 sensor1.setResolution(11);
 sensor2.setResolution(11);
 
 // Initialise the LCD.
 lcd.begin (16,2); // For a 16x2 character LCD
 // Switch on the LCD backlight.
 lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
 lcd.setBacklight(HIGH);
 // Clear the LCD screen.
 lcd.clear();
}

void loop(void)
{ 
 // Read in the temperatures of the two sensors.
 sensor1.requestTemperatures(); // Read temperature of sensor1
 sensorOneTemperature = sensor1.getTempCByIndex(0);
 sensor2.requestTemperatures(); // Read temperature of sensor2
 sensorTwoTemperature = sensor2.getTempCByIndex(0);

 // Display the temperatures of the sensors on the LCD.
 displayTemperatures();
}

void displayTemperatures(){
 // Display sensor1's temperature.
 lcd.setCursor(0,0);
 lcd.print(" T1: ");
 lcd.print(sensorOneTemperature,2);
 lcd.print((char)223);
 lcd.print("C ");
 
 // Display sensor2's temperature.
 lcd.setCursor(0,1);
 lcd.print(" T2: ");
 lcd.print(sensorTwoTemperature,2);
 lcd.print((char)223);
 lcd.print("C ");
}

If you need any kind of bespoke thermometer or thermostat, please email neil@reuk.co.uk with details of your specific requirements.

Formula 1 Race Starting Lighting Timer

formula 1 racing timerPictured above is a timer we recently built for a customer which will be used in a Formula 1 style race start lighting gantry. This gantry will be fitted at the top of a slope with toy cars held by a small gate latched up by a small solenoid with a spring loaded core. When the race is to start, the solenoid is energised which drops the gate allowing the cars to roll down the slope in their race.

In the photograph, five red LEDs are temporarily attached to the timer board for testing, but these will be mounted into the gantry across the track when it is finished.

When the user presses the button, the LEDs follow the standard F1 race start sequence – each red LED turns on in sequence with a one second interval. As each LED turns on, an on board piezo buzzer briefly pips. Then, when all five LEDs are illuminated, there is a random time interval of between 1 and 3 seconds before all the LEDs are turned off.

formula 1 race starting gantryThe lights turning off indicates that the race is to start. The buzzer sounds for 1 second, while the on board relay energises for 1 second to energise the solenoid and start the race.

If you need any kind of bespoke timer or controller, please email neil@reuk.co.uk with details of your requirements.

Mini Temperature Data Logger Design Plans

mini temperature data logger

Pictured above is a high accuracy (within 0.1°C) low power temperature data logger designed originally for scientific research in sea turtle egg incubation, but which could be put to use in a great many other applications.

This logger measures and logs the temperature once every 10 minutes exactly with sufficient memory space to hold 180 days of data (26,000 records). The logger is powered by a CR2032 coin cell battery which can keep it running unattended for the full 180 days.

When the measurement period is over, the logger can be extracted from its waterproof case and the logged data transmitted over a UART connection via a cable to a PC for subsequent analysis.

The goal of this project was to achieve all of the above at a cost per unit (of a batch of 50 units) of under €5, including the case.

mini temperature logger pcbThe temperature sensor used is a 16-bit resolution digital MAX30205MTA+. This gives a temperature resolution of 0.00390625°C and 0.1°C accuracy in the range 0-50°C. The microcontroller chosen is the ATMEGA328PB – a slightly more feature rich version of the MCU found on many Arduino boards. The serial flash memory chip used is a 512kbit AT25DN512C from Adesto which has sufficient space to hold the 410-420kbit of data to be logged in six months.

For full details, plans, and discussion of this project, click here: Low Power Cost and Size Temperature Data Logger.

Multi-sensor datalogger and timer relay

Pictured below is a device we were recently commissioned to design and build.

multi-sensor 3 channel datalogger with relay timerThis device, built around an Arduino Pro Mini, is one of the most complex projects we have completed recently. It is primarily a timer (utilising a ds3231 real time clock (RTC)) to energise a relay for a user programmed number of minutes once every day, week, fortnight, or month. However it must also monitor and process data from three sensors and log these readings to a micro SD card for later analysis at intervals which depend on the status of the system at any one time.

display for three channel datalogger

This device has a display to show the user the status of the system with readings from a pressure and a flow rate sensor as well as a valve and a relay which the device controls.

Detailed datalogging is only required when the valve is open (with logs appended at a rate of once per second), but the pressure sensor status must be logged every hour and changes to the status of the valve and other significant system changes must also be logged as and when they occur.

When logging data every second, it does not take long to generate a file which is unwieldy to process in Excel or other programmes. Therefore, our device creates a new file each time the valve opens, and logs to it until the valve closes again. In this way, there is one reasonably sized datalog file for each valve opening event together with one master log file which is appended hourly and also when there is a significant change detected in the system.

setting the time and date for a real time clock datalogger

Having mulitple datalog files not always recording data at regular intervals, it was essential that the timestamp for each line record in the logs showed the actual time and date rather than just an index value.

datalogger file from 3 channel arduino dataloggerThis will make future analysis of the collected data much easier.

The user is able to set the number of minutes that the relay is ‘on’ and also the precise time of day at which they would like the relay to turn ‘on’. The interval between relay ‘on’ events for this particular device was set to daily, weekly (7 days), fortnightly (14 days), or monthly (28 days).

setting up the arduino 3 channel dataloggerAn added feature is that the user can manually change the number of days until the relay will next turn ‘on’ which is particularly useful for testing the system or forcing the relay to turn ‘on’ at a previously unscheduled time and date if required.

The last piece of complexity was the flow rate sensor. This sensor outputs high pulses at a per second rate which when multiplied by 0.2 gives the litres per minute rate of flow through the sensor. The results generated then had to be converted into the desired cubic metres of flow per hour to be displayed and logged. As we did not have access to this flow rate sensor, we had to use a second Arduino to simulate the square wave the sensor generates to fully test the device we built. With a maximum of 1000 pulses per second to detect (for the maximum expected 12m3 per hour flow rate), the 16MHz clock of the Arduino Pro Mini was more than up to the job of simulating the sensor.

If you need any kind of timer or multi-channel datalogger, please email neil@reuk.co.uk with details of your requirements.

Poultry Egg Incubator with On Board Display and Humidity Maintenance

We have made many poultry egg incubators and timers over the last few years – devices which monitor and maintain temperature and humidity and also turn the eggs at regular intervals. Below is an image of one such incubator controller which we were recently commissioned to build which is a bit different from those.

poultry egg incubator controller

The motor is set to turn for three seconds five times per day to rotate the eggs. This is standard.

The heating element used for this incubator is a bit oversized, so we have to be careful not to overheat the eggs when it is used. When the temperature is measured to be 0.5C or more below a user set target temperature, the heater is turned on. Then, when the target temperature is reached, the heater is turned off. Because the element remains hot after being turned off, the incubator will continue to heat up to a little above target temperature while the element cools down. Therefore, there is also a fan which turns on just in case the temperature exceeds the target by 1.5C or more to cool things down long before the eggs overheat.

display for poultry egg incubation controller

Humidity management is also achieved rather differently than usual. In all previous incubators we have made which have included humidity sensing, a commercial humidifier has been switched on/off to maintain appropriate humidity levels. For this controller, when humidity is measured to be below a user set target minimum level, a pump is turned on for five second which adds water to a container in the incubator. The rapid evaporation of this water in the warmth of the incubator increases the humidity level back above the minimum rapidly. In order to prevent flooding or raising the humidity level excessively, the controller will run the pump at most once every ten minutes.

This entire system is powered by a solar charged 12V battery bank.

If you need any type of incubator (or humidor), please email neil@reuk.co.uk with details of your requirements.

Water Tank Thermostat Controller

We were recently commissioned to design and build a thermostatic controller for a large tank of water (5m3) which has to be maintained within a narrow temperature window for the testing of ultra-sonic scanning equipment.

thermostat controller for large water tankPictured above is the device we came up with. The user can set a target temperature threshold of 15 and 30 °C in 0.5°C steps using the UP and DOWN buttons. If the temperature of the water falls to 0.25°C or more below the threshold, then a relay closes which turns on a heater. When the temperature of the water has reached 0.25°C or more above the threshold, the relay opens again and the heater turns off. This keeps the water within +/- 0.25°C of the target temperature.

Since the temperature of such a large volume of water is slow to change, the update time of the thermometer in this device does not need to be very fast. We could therefore set the resolution of the DS18B20 temperature sensor to 12-bit (0.0625°C) by accepting an almost 0.75 seconds temperature reading update time.

thermostatic controller display

The display shows the current measured temperature (top left), heater status (top right), and the temperature threshold which has been set by the user.

If you need any kind of thermostatic controller, please email neil@reuk.co.uk with details of your requirements.

Testing 128×32 OLED IIC Display with Arduino

Many of the products we sell make use of 16×2 character LCD displays. These displays coupled with an Hitachi HD44780 LCD control module enable an Arduino or Raspberry Pi to operate the display very simply with just two data connections and two power connections required.

16x2 LCD display with module for use with Arduino and Raspberry Pi

However, these displays are physically quite large being 80 x 36mm, and while they are well suited to panel mounting, they cannot really be attached to the circuit board that is driving it without creating a device with large dimensions.

We have recently being looking at alternatives to these displays looking for something physically smaller, easily circuit board mountable, lower power consumption, and improved contrast. After much testing, we have chosen the OLED display pictured below.128x32 i2c arduino displayThese displays are far smaller having an active screen area of just 22.38 x 5.58mm. They require no backlight as each of the 128×32 pixels self-illuminates thanks to OLED technology. The maximum power consumption of one of these displays is 0.08W with every pixel illuminated – therefore less when showing text or when nothing is being displayed. In all ways these displays are an improvement on the 16×2 character LCDs.

OLED display used with arduinoThese OLED displays have much better contrast than LCDs, there is more space available to display information since more characters can be displayed, and there are much better graphics capabilities with the OLED displays. The image above shows the new OLED version of the LCD display from our REUK Low Voltage Disconnect with Display pictured below.

LCD display on REUK low voltage disconnect (LVD)

The biggest advantage however is the ease with which these OLED displays can be mounted to the circuit boards of our controllers so that we can produce more convenient small form factor integrated units with no increase in our pricing for customers.

arduino pro mini controlled 128 x 32 oled display

If you are interested in trying out one of these displays for your own projects, click here: buy 128×32 OLED Display for under £3 including delivery. If you intend to use one with an Arduino project, you will need to add the following libraries to your Arduino IDE: SSD1306 Library and Adafruit GFX Library, so that you can communicate with the display.

Controller for Multi-Pump Irrigation System Water Distribution

Pictured below is a diagram of an irrigation system comprising three water tanks located on three terraces. The lowest tank contains a bilge pump which will pump water up to the next terrace, and the tank on that terrace has a pump to send water up to the top tank.
Irrigation system diagram - multi tank, multi pump, multi terrace

The bilge pump has its own float switches and will, when powered, start pumping when its upper float switch detects water (full tank) and will stop when its lower float switch does not detect water (empty tank).

The two higher tanks have float switches so that their water level status can be monitored. Pictured below is the controller we built to manage the two pumps in order to best distribute the stored water across the three tanks while minimising overflow wastage. Ideally no tank should ever be completely empty, and no tank should be full and overflowing if the next higher tank is not full.

irrigation system pump controllerThis controller, built around an Arduino Pro Mini monitors the status of the float switches of the two upper tanks to decide when power should be supplied to a pump or pumps. If for example the middle tank is full, and the top tank is not, the Tank 2 pump will be run until either the middle tank is empty or the top tank is full. If the bottom tank is full, and Tank 2 is not, then the bilge pump will fill up Tank 2.

In order to prevent multi-switching (a pump being turned on and off rapidly and repeatedly) timers are built into this controller so that a pump will always overrun by 10 seconds when it is to be turned off. This will ensure that the state of the float switch which called for the pump to be turned off will be stable and unaffected by turbulence in tank.

If you need any type of pump controller, please email neil@reuk.co.uk with details of your requirements.

Controller for Heater used to Prevent Condensation on Telescope Mirror

A common problem for amateur astronomers is condensation forming on the mirror in their telescopes. During the night the mirror cools down, and then in the morning as the air warms up, condensation forms on the mirror which is colder than the surrounding air. The same thing happens to the surface of a bottle when you take it out of a fridge, but for a telescope it is problematic as condensation deteriorates the reflective coating on the mirror, and of course a foggy coating reduces the quality of the star images obtained by the telescope.

One solution to this problem is to warm up the mirror so that it remains 2 to 5 degrees Celcius above the ambient air temperature – something which can be achieved using a heating element and a thermostatic controller. If the mirror gets too cold, it will be covered in condensation. If the mirror gets too hot, it could warp. Therefore accurate control of the heating element is essential.

telescope condensation prevention controller with heater

Pictured above is one such thermostatic controller we recently prepared for a customer loosely based around our 2013 Solar Water Heating Pump Controller.

This device has two ds18b20 digital temperature sensors – one which attaches behind the mirror of the telescope and the other which measures the ambient air temperature. When the temperature at the mirror falls to within 2°C (or any other user programmable value) warmer than ambient, the heating element is switched on (via the onboard relay). The heating element stays on until the mirror has heated up to be at least 5°C (or any other user programmable value) warmer than ambient.

We used a non-waterproof sensor at the back of the mirror as this area remains dry and that sensor needs to respond to quick temperature changes. (The protection on waterproof temperature sensors slows down their response to temperature change.) We did however use a waterproof sensor to measure ambient air temperatures because that sensor is exposed and ambient air temperatures change relatively slowly.

The heating cycle continues automatically ensuring condensation does not form on the mirror, and the mirror is not over heated. This is a 12VDC powered controller managing a 12VDC heating element so that it can be battery powered when used at remote locations.

If you need a user programmable thermostatic controller for your telescope heating element, please email neil@reuk.co.uk with details of your requirements.

Target Shooting Lights Controlling Timer

Pictured below is a timer for use in competitive target shooting. Usually we make turning target controllers which turn the target to face and away from the shooter at the required times. This controller instead is for use with a fixed target, using a red and a green light to tell the shooter when to shoot.

shooting target lighting controllerThe red light starts off on. The start/stop button is pressed and the range master gives a vocal command for shooters to load. After 30 seconds, the red light turns off and the green light turns on – shooting commences. After a user programmable timer period has elapsed, the red light turns on again, the green light turns off, and shooting stops.

With this particular controller, the available timing options are fixed as 4, 6, 8, 10, 20, or 150 seconds. The timer option button is used to cycle through those options with red indicator LEDs used to show which option is currently selected. (We also make timers like these with a physical display and the ability for the user to change the values of the timing options instead of having a fixed selection – see here for details of some of our other shooting timers.)

The type of bulb to be used with controller is pictured below: a low current 12VDC powered 22ds LED bulb from Onpow.22ds 12vdc LED bulbIf you need any type of shooting range timer, please email neil@reuk.co.uk with details of your requirements.