Remote Object Sensor using Arduino, HCSR04 and MLX90614

Discussion in 'The Completed Projects Collection' started by ep.hobbyiest, Jul 17, 2019.

  1. ep.hobbyiest

    Thread Starter Member

    Aug 26, 2014
    Nowadays, Makers, Developers are preferring Arduino for rapid development of the prototyping of projects. Arduino is an open-source electronics platform based on easy-to-use hardware and software. Arduino has very good user community. In this project we will see how to sense object’s temperature and distance. The object can be of any type like hot jar or real cold ice cube wall outside. So, with this system we can be save our-self. And more importantly this can be helpful for disabled person (blind people).

    For this project we will need following components,

    1.Arduino Nano

    2.MLX90614 (IR Temperature sensor)

    3.HCSR04 (Ultrasonic sensor)

    4.16x2 LCD


    6.Few Wires

    We can use any Arduino board instead of Arduino nano considering pin mapping.

    More About MLX90614

    MLX90614 is i2c based IR temperature sensor works on thermal radiation detection.

    Internally, the MLX90614 is a pairing of two devices: an infrared thermopile detector and a signal-conditioning application processor. Per the Stefan-Boltzman law, any object that isn't below absolute zero (0°K) emits (non-human-eye-visible) light in the infrared spectrum that is directly proportional to its temperature. The special infrared thermopile inside the MLX90614 senses how much infrared energy is being emitted by materials in its field of view, and produces an electrical signal proportional to that. That voltage produced by the thermopile is picked up by the application processor's 17-bit ADC, then conditioned before being passed over to a microcontroller.

    More About Ultrasonic Sensor.

    In ultrasonic module HCSR04, we have to give trigger pulse on trigger pin, so that it will generate ultrasound of frequency 40 kHz. After generating ultrasound i.e. 8 pulses of 40 kHz, it makes echo pin high. Echo pin remains high until it does not get the echo sound back.

    So the width of echo pin will be the time for sound to travel to the object and return back. Once we get the time we can calculate distance, as we know the speed of sound. HC-SR04 can measure up to range from 2 cm - 400 cm. Ultrasonic Module will generate the ultrasonic waves which are above the human-detectable frequency range, usually above 20,000 Hz. In our case we will be transmitting the frequency of 40Khz.

    More About 16x2 LCD

    16x2 LCD is 16 character and 2 row lcd which has 16 pins of connection. This LCD requires data or text in ASCII format to display.
    First row Starts with 0x80 and 2nd row starts with 0xC0 address. LCD can work in 4-bit or 8-bit mode. In 4 bit mode, Data/Command is Sent in Nibble Format First Higher nibble and then lower Nibble.

    For Example, to send 0x45 First 4 will be sent Then 5 will be sent.

    There are 3 controlling pins that is RS, RW, E.

    How to Use RS:

    When Command is sent, then RS = 0

    When Data is sent, then RS = 1

    How to use RW:

    RW pin is Read/Write.

    where, RW=0 means Write Data on LCD

    RW=1 means Read Data from LCD

    When we are writing to LCD command/Data, we are setting pin as LOW.

    When we are reading from LCD, we are setting pin as HIGH.

    In our case, we have hardwired it to LOW level, because we will be writing to LCD always.

    How to use E (Enable):

    When we send data to LCD, we are giving pulse to lcd with the help of E pin.

    This is high level flow we have to follow while sending COMMAND/DATA to LCD.

    Following is the Sequence to Follow.

    Higher Nibble

    Enable Pulse,

    Proper RS value, Based on COMMAND/DATA

    Lower Nibble

    Enable Pulse,

    Proper RS value, Based on COMMAND/DATA

    More Images:


    Code (Text):
    1. #include <Wire.h>
    2. #include <Adafruit_MLX90614.h>
    3. #include <LiquidCrystal.h>
    5. const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
    6. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
    9. Adafruit_MLX90614 mlx = Adafruit_MLX90614();
    12. const int trigPin = 9;
    13. const int echoPin = 10;
    14. // defines variables
    15. long duration;
    16. int distance=0;
    19. void setup() {
    20.   Serial.begin(9600);
    21.   lcd.begin(16, 2);
    22.   pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
    23.   pinMode(echoPin, INPUT); // Sets the echoPin as an Input
    24.   mlx.begin();
    26.   lcd.setCursor(3, 0);
    27.   lcd.print("STechiez");
    28.   delay(2000);
    29.   lcd.clear();
    30.   lcd.setCursor(0, 0);
    31.   lcd.print("Remote Object");
    32.   lcd.setCursor(0, 1);
    33.   lcd.print("Distance/Temp. Sensor");
    34.   delay(2000);
    35. }
    37. void loop() {
    38.   digitalWrite(trigPin, HIGH);
    39.   delayMicroseconds(10);
    40.   digitalWrite(trigPin, LOW);
    41.   duration = pulseIn(echoPin, HIGH);  //read the raw timer value
    42.   distance= duration*0.034/2;   //Calculate the distance
    45.   lcd.clear();
    46.   lcd.print("Distance:");
    47.   lcd.println(distance);
    48.   lcd.setCursor(0, 1);
    49.   lcd.print("Temp.   :");
    50.   lcd.print(mlx.readObjectTempC());
    51.   lcd.println("*C");
    53.   delay(500);
    54. }


    Happy Learning... :)
    Last edited: Jul 18, 2019