Remote Object Sensor using Arduino, HCSR04 and MLX90614

Thread Starter

ep.hobbyiest

Joined Aug 26, 2014
201
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

5.Breadboard

6.Few Wires

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

More About MLX90614
FIBD83BJU31T7QY.LARGE.jpg FX56L2GJUMXPF9M.LARGE.jpg

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.
FOB626RJUMXPFB9.LARGE.jpg FXB6XAXJUMXPF9Q.LARGE.jpg

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
FLUITX4JU31T7PJ.LARGE.jpg

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:
F07QTT3JUMXPF84.LARGE.jpg FFBO1A8JUMXPF8U.LARGE.jpg

Code:


Code:
#include <Wire.h>
#include <Adafruit_MLX90614.h>
#include <LiquidCrystal.h>

const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);


Adafruit_MLX90614 mlx = Adafruit_MLX90614();


const int trigPin = 9;
const int echoPin = 10;
// defines variables
long duration;
int distance=0;


void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  mlx.begin(); 
 
  lcd.setCursor(3, 0);
  lcd.print("STechiez");
  delay(2000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Remote Object"); 
  lcd.setCursor(0, 1);
  lcd.print("Distance/Temp. Sensor"); 
  delay(2000);
}

void loop() {
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);  //read the raw timer value
  distance= duration*0.034/2;   //Calculate the distance

 
  lcd.clear();
  lcd.print("Distance:");
  lcd.println(distance);
  lcd.setCursor(0, 1);
  lcd.print("Temp.   :");
  lcd.print(mlx.readObjectTempC());
  lcd.println("*C");
 
  delay(500);
}

Tutorial:



Happy Learning... :)
 
Last edited:
Top