The MLX90614 from Melexis is an infrared thermometer for non-contact temperature measurements. Both the IR sensitive thermopile detector chip and the signal conditioning ASIC are integrated in the same TO-39 can.
Integrated into the MLX90614 are a low noise amplifier, 17-bit ADC and powerful DSP unit thus achieving high accuracy and resolution of the thermometer.
Factory calibrated in wide temperature range: -40 to 125°C for sensor temperature and -70 to 380°C for object temperature
SMBus ( I2C based) compatible digital interface for fast temperature readings and building sensor networks.
In this project we shall use the MLX90614 with OLED & ULTRASONIC sensor.Arduino NANO is used as controller.Calibration procedure for correct object temperature reading is also explained.
Before coding , we need to install the required libraries for Arduino.
Open Arduino IDE
Sketch –> Include Library –> Manage Libraries
Search for MLX and select ADAFRUIT MLX90614 Library to install.
Next search for GFX and install ADAFRUIT GFX Library , which is graphic support library for displays.
Finally search for SSD1306 and select ADAFRUIT SSD1306 to install.
Connection details are as shown in image below.
Ultrasonic
TRIG –> D12
ECHO –> D11
OLED
SDA –> A4
SCL –> A5
MLX SENSOR
SDA –> A4
SCL – A5
A mini buzzer is connected to D3.
Vcc of OLED,MLX & Ultrasonic are connected to 5v of NANO
All GND pins are made common.
If you want you can use an external power source 5V 1 AMP at Vin of NANO.
As power consumption of OLED,MLX is very low , we can source power from NANO itself.
OLED & MLX are I2C devices , so they are connected to I2C pins of NANO ( SCL & SDA).
According to I2C address , respective device can be communicated.
CODE Explanation :
Starting with we include the libraries we installed for MLX & OLED.
An object named mlx is created from class Adafruit_MLX90614 from MLX library.
An object display is created from class Adafruit_SSD1306 from OLED library.Here we pass argument –1 , as there is no Reset pin in OLED.
Variables like roomTemp, objectTemp , stemp , threshold are created as Float
Ultrasonic echoPin is defined at D11 , trigPin at D12.
The Maximum & Minimum range of Ultrasonic are initiated as Integer variables.
Ultrasonic will sense the object distance and the Temperature reading from MLX will be initiated only when the Object is in between 15 and 25 cm.
Inside void setup()
Trigger pin of Ultrasonic is declared as OUTPUT pin , Echo as INPUT pin.
OLED display is initiated using begin() function and the I2C address of OLED is passed as argument (0x3C).
setTextColor() function is used to pass argument WHITE which enables black background for OLED.
Inside loop() we generate a trigger pulse for Ultrasonic to generate a 40kHz burst.
The pulse reflected from object is calculated as width using pulseIn() function of Arduino.
Distance of the object is then calculated.
The object temperature in Celcius is read using MLX library function readObjectTempC()
& room temperature using function readAmbientTempC()
Initially the threshold value is set as 0.
After calibration we shall fix the correct threshold value.
Display settings for OLED by using functions setCursor() , display()
At the bottom of OLED we display the distance of target object in cm & then the Room temperature in celcius.
If distance of object is above maximum range ( we’ve set it as 25cm) , GET CLOSER is printed on display.
If distance of object is below minimum (15 cm) , TOO CLOSE is printed.
If the object is between 15 and 25 cm then HOLD ON is printed.
Till readcount is 5 (5 times we take reading and Average it) disptemp() is called.
Finally the object temperature is displayed.
If object temperature is above 37.5 celcius , play_alert() function is called.Here we use the tone()
Finally the compiled code is uploaded to NANO.
OLED display shows GET CLOSER initially and the object distance is displayed at the bottom along with room temperature.
If the object is near to sensor ( below 15 cm) , TOO CLOSE is displayed.
If the object is between 15cm and 25 cm , HOLD ON is displayed and blinks 5 times.
Reading is taken 5 times and averaged.
Forehead or Wrist is shown in front of sensor for taking reading of temperature.
The display shows 31.2 degree celcius.
We use an oral thermometer for calibration purpose.Using this meter under tongue , it shows 98.2 Fahrenheit.
Converting F to Celcius , it is 36.8 C
36.8 LESS 31.2 (shown by OLED initially) = 5.6
So we need to use this value as THRESHOLD.
Update the threshold value and then upload the code.
Now the display shows the correct temperature 36.9 C
CAN – Controller Area Network bus is widely used in Automobile industry and in other industrial applications.
CAN is like Nervous system in Human body facilitating communication between all parts of body.
In CARs , NODEs or ECUs – Electronic Control Units are connected via CAN bus which acts as a control nervous system.
ECUs can be Engine control unit, Airbag control, Audi System , Door position,Brake system, Sensors & others.Each and every function can be assigned a NODE or ECU.
A modern CAR has upto 100 ECUs.
CAN allows ECUs to communicate with each other without complex dedicated wiring in between.
Any ECU can communicate with entire system without causing overload to the controller computer.
CAN is MULTI MASTER setup.Any Node can be a MASTER.
CAN works on a MESSAGING TYPE SYSTEM & no slave address is used to communicate with a node.
Every Node receives the message and the related data will be conceived by the receiver node.
It is like public announcement system in an Airport.Only concerned passengers will take the message.
To balance the CAN BUS and for noise reduction a 120E RESISTOR is used as Terminator.This is must for END NODES. Nodes added in between need not use this Resistor.
In this project we make use of a CAN Board CAN2515.
This board has 2 ICs. One is the CAN Controller MCP2515 , which communicates with Arduino or any MCU by SPI Protocol.
MCP2515 gives SINGLE ENDED DIGITAL signal (High ,Low).
TX-CAN & RX-CAN are at digital levels and are connected to another IC , a TRANSCEIVER.
Here the Transceiver used is TJ1050 . Microchip MCP 2551 is also a transceiver , generally used with Microcontrollers which have inbuilt CAN Controllers.For e.g ESP32 module has in built controller , but it needs TRANSCEIVER like MCP2551 or TJ1050 .Do not confuse with the numbers
2515 IS CONTROLLER , 2551 IS TRANSCEIVER.
TJ1050 receives Digital signal from CAN2515 and converts tp DIFFERENTIAL SIGNAL acceptable on CAN BUS.
Note the connection between TJA1050 and CAN 2515 .
TX-CAN to TXD , RX-CAN to RXD ( not reversed).
The module we use has both ICs on board and we need not care about this connection.
The CAN Message format is as below :
The CAN-ID may be 11 bit or 29 bit.
11 BIT can addresses 2048 nodes ( 2 power 11) hex 0x000 to 0x7FF
Following picture shows the Differential signal level of CAN.
When no information is on BUS , both CAN-H & CAN-L are at half the supply volt (here 2.5 volt on a 5v system).
This is RECESSIVE State or BIT 1.
When CAN-H goes to 5v and CAN-L to 0 v , it is DOMINANT State or BIT 0.
To start with the project , connect a potentiometer ( center pin) to A0 of Arduino.
One end of pot is connected to 5v and other end to Gnd.
The CAN board connections are as shown SPI connections between Arduino and CAN board.
Before starting we need a good Library for CAN to work with.
SEEED Studio has a Library which works fine with their Shield.
Also a modified version on it is available from Cryjfowler.
I prefer to use one from AUTOWP
arduino-mcp2515
which uses STRUCT for message sending.This is very simple and easy to use.
Please note , the Seed studio library and that of coryjfowler both have the same header file name mcp_can.h. If you install both these libraries , then there is clash on object declarations arising errors.Use any one only.
In this demo we use arduino-mcp2515 library.Download it as ZIP file.
DHT11 humidity and temperature sensor is available as a sensor and as a module. The difference between this sensor and module is the pull-up resistor and a power-on LED.
DHT11 is a relative humidity sensor. To measure the surrounding air this sensor uses a thermistor and a capacitive humidity sensor.For measuring temperature this sensor uses a Negative Temperature coefficient thermistor, which causes a decrease in its resistance value with increase in temperature.
The temperature range of DHT11 is from 0 to 50 degree Celsius with a 2-degree accuracy. Humidity range of this sensor is from 20 to 80% with 5% accuracy. The sampling rate of this sensor is 1Hz .i.e. it gives one reading for every second. DHT11 is small in size with operating voltage from 3 to 5 volts. The maximum current used while measuring is 2.5mA.
DHT11 sensor has four pins- VCC, GND, Data Pin and a not connected pin. A pull-up resistor of 5k to 10k ohms is provided for communication between sensor and micro-controller.As amodule it has only 3 pins , pull up resistor provided on board.
Connect DATA pin of DHT11 to D2 of Arduino , Vcc to 5v & Gnd to Gnd.
Open NEXTION EDITOR and start a new project with .HMI file name.
Generate a FONT file and add to the project.
Click on Picture tab at bottom left corner and then + symbol to import a back ground picture.This picture resolution must match that of your NEXTION model
In this demo I’m using 4024T032 ( 400 X 240 pixel 3.2 inch size)
Use IRFANVIEW or INKSCAPE to match the resolution 400 x 240 of the image.
Click on PICTURE tool .It appears p0 on canvas.
At the right side window you can set the attributes for this object.Leave the object name as p0.
Click browse against pic attribute and select the image to be loaded as back ground.
Now the image appears on canvas.
Add 2 TEXT objects .One for Temperature and the other for Humidity.
As Nextion editor cannot handle fraction numbers , we use Text instead of Number object.
Following are the attribute settings for these 2 Text objects.
t0 objname can be changed to Temperature
vscope to global.All objects that is controlled through SERIAL to be set to global.
sta attribute by default is solid color.Change this to crop image.
Also select the browse against picc attribute and select the back ground image.
This creates a Transparent effect to the object.
Text color can be changed by the pco attribute. 65535 means White & 0 means Black.
You can click on Select against pco to select a color.
Same way repeat for the t1 object Humidity.
Next add on 4 more Text objects for display purpose.You need to change the txt attribute to change the display name .
txt – to change display name
pco – to change color of text.
sta -crop image to give transparent effect so that background image is visible through this object.
Click on DEBUG to start the Simulator.
You can test the display by sending STRING Commands.
temperature.txt=”32.0”
changes the Temperature display to 32.0.
Note the usage of double quotes for data to be displayed.While typing the code the interpreter of Nextion editor gives options to select (intellisense).
The commands can be sent as STRING from Arduino and to be followed by 3 bytes of 0xFF.
Upload the following sketch on to Arduino.
Here we use the library for DHT Sensor by including the header file DHT.h
We define the DHT data pin connection as 2 (D2 of Arduino) and type as DHT11.
The variables temperature and humidity are initialized with float literal constants.
Reading of sensor is by calling functions readHumidity() & readTemperature() from the Class dht.
The assigned data is sent to Nextion as a STRING command.
Sending data.
Data to Nextion should be sent in the following format:
String command
=”humidity.txt=\””+String(humidity,1)+”\””;
name of the receiving element humidity
sign “.”
field name of the receiving element txt
sign “=”
data, and if it is String, then in quotation marks, and if it is digital information, then four bytes of data
three bytes 0xff
Notice the use of ESCAPE character backslash \ before double quote “.
This is how to send double quotes from Arduino Serially.
Nextion does not work with float. So all to be sent as – String
To upload the .tft file on to Nextion we use USB-TTL device.Connect Nextion to USB-TTL
Tx to Rx
Rx to Tx
Gnd – Gnd
5v to 5v
Click on UPLOAD button and select the COM port of USB device and a faster baudrate.
Once uploaded , remove USB device and connect Arduino with Nextion with same configuration as above.
The result is displayed on NEXTION DISPLAY.
The DHT sensor requires 1 second refresh rate for each reading.This is provided by 1 sec delay in Arduino code.
This post is on displaying potentiometer reading from Arduino to Nextion display.
Open Nextion Editor and File –> New to create a project file with extension .hmi
Always keep your project files in a separate folder.
In the next screen select your Nextion model display , mine is 4024T032 which is 400 x 240 pixel & 3.2 inch size Basic model.Also select the direction of display as Horizontal.
Using Fonts Generator create a font file by selecting font size and font type.It is saved as .zi file.Click Yes to add font file to project.
The font file appears under font tab.
Next to Fonts tab you see a Picture tab.
Click on that and then click on the + symbol seen on top f this window.
Browse to the location of the background image you want to import.
Remember the image must match the resolution of the display model.Here mine is 400 x 240 , so I’ve converted the image to 400 x 240 pixels using IRFANVIEW Software.
Drag PICTURE tool from toolbox on to canvas or just click on Picture under tool box.
Picture component appears on canvas as p0 object name.
Click on that p0 , to modify attributes for object p0.
Against pic attribute click on browse and select the background picture from the list.
The back ground image appears on workspace canvas.
Click on SLIDER tool and then a NUMBER.
Slider appears as object h0 & number appears as object n0.
You may rename it from attribute section.But we shall leave it to default names.
Following is the attribute window for the object h0.
The mode by default is Horizontal , if required can be changed to Vertical.
Color of the slider by default is Green , by clicking against bc0 attribute and select color , you can change it. pc0 is the color of slider knob, Red by default & can be changed.
Set the maxvalue to 1023 , as Analog read of Arduino ranges from 0-1023.
n0 Number attributes
bc0 , pc0 to change color of number.
vscope can be changed from local to global. If global it is available for all pages and if you control it from Arduino through Serial , make it GLOBAL.
Click on DEBUG to start the Simulator.
Under simulator you can feed in the code to change value of n0 object.
n0.val=524 will change the n0 value to 524.
Close the Simulator.
Now to upload the .tft file (after Compile you get this file) on to Nextion , we use a USB-TTL device.
Connect Tx of Usb device to Rx of Nextion , Rx to Tx , Gnd to Gnd and Vcc to 5v.
Plug in usb device to pc and note the COM port allotted to it.
Click on UPLOAD,
Select COM port and baud rate & click GO.
To Arduino we have to upload the following sketch.
analogRead of A0 pin where pot pin is connected is assigned to a integer variable value.
A string n0.val is sent to serial along with this value .
The string is followed by 3 times 0xff hex value.This is the standard format Nextion will accept on its Serial.
Do not use any other Serial commands here.For e.g if you use Serial.println() , then Nextion will not display the value.
Once sketch is uploaded on to Arduino , connect Arduino to Nextion
Tx to Rx, Rx to Tx , 5v to 5v , Gnd to Gnd
Potentiometer Center pin to A0, one end of pot to +5v and other end to Gnd.
Now turning the potentiometer will vary the number on Display from 0 to 1023.
Now let us modify the Arduino code so that Slider moves according to number value.
Serial.print(“click n0,1);
click n0,1 means activate Press Event of object n0
upload this code on to Arduino.
Now on Nextion Editor click on n0 number object.
Under Touch Press Event feed in
h0.val=n0.val
The touch press event is activated by Arduin code , as if we were physically touching n0.
Now the event code is triggered where we assign value of slider to be same as value of number.
compile and upload the file to Nextion using USB-TTL.
Connect Nextion with Arduino nd see the result.
On varying the potentiometer the number value changes from 0 to 1023 .Accordingly the slider changes position.
Nextion is a Human Machine Interface (HMI) programmable Touch Display.
Nextion includes a hardware part (a series of TFT boards) and a software part , NEXTION EDITOR.
The Nextion TFT board uses only one serial port to communicate. It lets users avoid the hassle of wiring. On board a 32 bit ARM processor is used STM32F030.
Nextion editor has mass components such as button, text, progress bar, slider, instrument panel etc. to enrich the interface design. Furthermore, the drag-and-drop function ensures that users spend less time in programming. With the help of this WYSIWYG editor, designing a GUI is a piece of cake.
T -Series model: T=Basic Model K=Enhanced Model
032 -Display size:”032″ means 3.2 inch
R -Touch screen type:N=non touch; R=resistive touch; C=capacitive touch
All basic models are resistive touch screen display, 4M Flash, 3.5KByte RAM, 65k colors., except 3.5 inch model which has 16M Flash.
Before starting the project ,let us collect the essentials.
Inkscape editor is required , if you need an image in your project. Using INKSCAPPE we can convert the image resolution to match that of Nextion display.
First , download theITEAD LIBRARY file & unzip it. Copy the folder & paste it to C:/Program files/Arduino/Libraries
Rename the folder to Nextion.
Open the Nextion folder & locate NexConfig file.
Right click and select Edit with Notepad++
As the library is designed for ARDUINO MEGA , we need to do the following modifications in Configuration file , so that ARDUINO UNO can be used.
Comment lines 27 & 32.
Change Serial2 to Serial at line 37.
Save the file,
Next , we download an image background for the project and use INKSCAPE to convert image to match our Nextion display which is 400 x 240 resolution.
Huge collection of Both free and paid images are available for download.
Open INKSCAPE
Go to File –> Document Properties
Set the UNITS to PX (Pixel) ,Width as 400 & Height as 240 ( which matches our NEXTION Display Resolution),
Close the Document properties. A new Canvas of size 400 x 240 is created .
Now click File –> Import and browse to the location of the downloaded image file & select it.
The image is loaded on to Inkscape.You can see drag Handles on all sides of the image.
Use the handles to pull so that the image size fits inside the Canvas created,
Click View –> Zoom –> Selection
to Zoom the picture.
Now drag the handles so that the image fits exactly inside the 400 x 240 Canvas
Click on File –> Save as and select the CAIRO PNG type to save the image.
Next proceed with the NEXTION EDITOR Installation.
Open NEXTION Editor.
Click on File –> NEW & within a folder create a new file , say ledonoff.
This will be stored as .HMI File.
On the next window select the model of NEXTION Display you have.
In my case it is 400 X 240 2.3 Inch.
Select the model & then click on DISPLAY
Here select the orientation of display as 90 – HORIZONTAL
You can also select vertical if you have created vertical image and like to have vertical
orientation.
A canvas of size width 400 x height 240 is created inside Display area of Nextion Editor.
Now we have to generate a FONT file.
Go to TOOLS –> FONT GENERATOR
Select Height of Font & type of Font.
Provide a name for the file.
Click Generate Font to see a .ZI font file created.Save that in the project foldet.
Finally click the “Add the Generated Font” message.
You can see the font file added to the FONTS Area.
Next click on PICTURE tab . Then click the + symbol.
Browse to the location of the image file ( 400 x 240) we created earlier using inkscape.
Select the image file , so that it is loaded inside the PICTURES area.
Click on PICTURE under TOOLS area.
Then at the right side ATTRIBUTE Area you can see the id of the image as 1, object name as p0
Below that against pic , empty space iseen
Double click on the empty space against pic to see on a new window the picture selected .
Select the picture seen on new window & click ok.
Now the image fits inside the canvas created.
You can click on DEBUG to see if any error is generated.If any error seen then you have to create again the image exactly of size 400 x 240 using inkscape.
]
Next add 2 Buttons & a Text over the image by clicking on the elements under Tools area.
Click on the first button and go to Attributes area.
Here you can see the id of the component as 2, object name objname as bo.
Write down these attributes , which will be used in coding.
Scroll down to txt and change the name to LED ON.
You can also change the name of objname , but we leave it as b0 as generated.
Same way click on second button and note the attributes id 3 , objname b1
Scroll down and select txt , change name to LED OFF.
For the third element , just change the txt to STATUS.
You can drag the text element to make the text area bigger.
Now click on first button LED ON.
In the EVENT Area click the TOUCH RELEASE EVENT & then put a tick mark
against Send Component ID
Do this for the second button LED OFF , also.
Click the DEBUG button to start the simulator.
Now you can see the display created with buttons and Status text bar.
Click on the LED ON button.While you release the click, a HEX code is generated
inside the simulator return area.
65 00 02 00 FF FF FF
65 is the Touch Detection code
00 is page ID which is page 0 for our project.
02 Component ID which is 2 (LED ON button)
00 Button Release event
FF FF FF End of Message
Similarly click on LED OFF button.
While released you see the following code
65 00 03 00 FF FF FF
Here you can see the 3rd hex code as 03 which is component id of LED OFF button.
This hex code is available at the serial port of display when the event occurs.
So we can easily read this code and decide on which button is operated.
//Button b1 component popcallback function
// When OFF button is released the LED turns OFF and the state text changes
void b1PopCallback(void *ptr){
t0.setText (“State:OFF”);
digitalWrite(led,LOW);
}
void setup(void) {
Serial.begin(9600);
nexInit();
//Register the pop event callback function of the components
#include <Nextion.h>
Then each component used is declared using NexButton function
We have 3 components bo,b1 & t0
bo component is defined as
NexButton b0 = NexButton(0,2,”b0″);
0 is the pageid , 2 is the component id & bo is the object name
Similarly other 2 components b1 & t0 are defined
Next we create a list array using NexTouch function for the Touchable components.
We have only 2 touchable components b0 & b1
The array list is created b0,b1 & NULL isadded finally.
Button b0 component popcallback function
When ON button is Released the LED turns ON and the state text changes
void b0PopCallback(void *ptr)
same way button b1 component popcallback function is declared.
Inside SET UP we attach the function created to corresponding Events.
When you click bo button boPopCallback function is called.
This is done by
b0.attachPop(b0PopCallback,&b0);
Same way for b1 button.
Inside loop we repeatedly watch for the event trigger list.
The code and project files can be downloaded from here :
Arduino ProMini , as the name indicates , is a miniature version of UNO .It runs on 16 MHz crystal ,ATMEGA328 ,but lacks USB connectivity. There are 5V (16MHz) & 3.3V (8MHz) versions. In this demo I use the 5v version.
There is a voltage regulator on board so it can accept voltage up to 12VDC. If you’re supplying unregulated power to the board, be sure toconnect to the RAW pin and not VCC.
Vcc accepts only 5v.
The latest version of this board breaks out the ADC6 and ADC7 pins ,also adds footprints for optional I2C pull-up resistors.
To upload code on to pro mini , a USB-TTL adapter is required.There are many types of USB adapters available.The most reliable one that works up to Windows 10 is the one built on CP2102 IC .
CP2102 adapters are available in 2 variants .One with 6 pins that include the DTR , Data Terminal Ready , which handles the RESET required by the promini board.
The other board is commonly available one with 5 pins.Here RESET must be done manually on promini while code is uploaded.
First let us upload code using the 6 pin version .
The connections are
PROMINI USB-TTL
DTR —–> DTR
TxO —–> Rx
RxI ——> Tx
Vcc ——> 5v
GND ——> GND
In some Promini boards the DTR pin is printed as GRN.
Plug in the USB board to PC & open the Device Manager . If the driver is installed previously , a COM port will be allotted.Otherwise , download the silicon labs cp2102 driver from here & install.
Open the Arduino IDE , feed in the COM port allotted.
Select Board as Arduino Pro or Pro Mini , Programmer as USBasp.
In newer versions of IDE there is option to select type of ProMini board.Under Processor select ATmega328 5v,16MHz
From Examples open the BL;INK sketch
Click on UPLOAD button.
The DTR pin of USB board takes care of the RESET & your code will be uploaded to PROMINI without any manual reset.
Uploading code using a 5 pin version , needs a manual RESET on PROMINI.
The connections are
PROMINI USB-TTL
TxO —–> RxD
RxI ——> TxD
Vcc ——> 5v
GND ——> GND
Plug in the USB to PC & note the COM Port allotted.
Open Arduino IDE .Feed in the COM port , select board as Arduino Pro or Promini & Programmer as USBASP
From Examples , open the BLINK Sketch
Click on UPLOAD button.
Watch out for the message at the bottom of IDE.
“ Compiling Sketch “ message appears first.
Then it changes to “Uploading”
As soon as you see “Uploading” message , gently press the RESET Key on Promini.
This should be done instantly , as soon as you see “UPLOADING” message.
If the KEY Press is at the right time , your code will be uploaded successfully.
You can also use your UNO board to upload code on Promini.
To use the UNO board , you need to by pass the bootloader .For this upload an empty code to UNO or connect the RST pin to GND
Connecting RST pin to GND bypasses the bootloader & only the serial converter IC located near the USB socket is used as USB-TTL.
The connection here is STRAIGHT & not reverse
Tx of Arduino UNO goes to Tx of Promini
Rx of UNO goes to Rx of Promini
Gnd to Gnd
Connect the USB cable to PC & open the IDE.
Select the port where UNO is connected.
Select the board as Arduino Pro or ProMini
Open the BLINK sketch & UPLOAD.
Watch out the message at the bottom of IDE.
Initially “Compiling Sketch “ appears.
Then the message changes to UPLOADING…
Once you see UPLOADING… message , press the RESET key on PROMINI.