0% found this document useful (0 votes)
51 views6 pages

Code of The Project With Servo and Ultrasonic Sensor

This document contains code for a library that interfaces with the MLX90614 non-contact temperature sensor over I2C. It reads the ambient and object temperatures from the sensor and displays them on an LCD. If the object temperature is above 40 degrees Celsius and an ultrasonic sensor detects an object between 1-6 inches away, a servo motor will activate.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views6 pages

Code of The Project With Servo and Ultrasonic Sensor

This document contains code for a library that interfaces with the MLX90614 non-contact temperature sensor over I2C. It reads the ambient and object temperatures from the sensor and displays them on an LCD. If the object temperature is above 40 degrees Celsius and an ultrasonic sensor detects an object between 1-6 inches away, a servo motor will activate.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

/***************************************************

To buy the kit :- +91-8571964488

This is a library example for the MLX90614 Temp Sensor

Designed specifically to work with the MLX90614 sensors in the

adafruit shop

----> https://www.adafruit.com/products/1747 3V version

----> https://www.adafruit.com/products/1748 5V version

These sensors use I2C to communicate, 2 pins are required to

interface

Adafruit invests time and resources providing this open source code,

please support Adafruit and open-source hardware by purchasing

products from Adafruit!

Written by Limor Fried/Ladyada for Adafruit Industries.

BSD license, all text above must be included in any redistribution

****************************************************/

#include <Wire.h>

#include <LiquidCrystal.h>

#include <Servo.h>

#include <Wire.h>

#include <Adafruit_MLX90614.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 10);

Servo myservo;

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

long microsecondsToInches(long microseconds);

long microsecondsToCentimeters(long microseconds);

const int trigPin = 7;

const int echoPin = 8;

void setup() {

myservo.attach(9);

myservo.write(0);

//delay(2000);

lcd.begin(16, 2);

// Print a message to the LCD.

lcd.setCursor(0, 0);

lcd.print("Wireless Temp.");

lcd.setCursor(0, 1);

lcd.print(" Measurement");

Serial.begin(9600);

pinMode(LED_BUILTIN, OUTPUT);

Serial.println("Adafruit MLX90614 test");


mlx.begin();

void loop() {

Serial.print(mlx.readAmbientTempC());

Serial.print("|");

Serial.print(mlx.readObjectTempC());

Serial.print("|");

lcd.clear();

lcd.setCursor(0, 0);

lcd.print("Temp. Reading:- ");

lcd.setCursor(0, 1);

lcd.print(mlx.readObjectTempC());

lcd.setCursor(4, 1);

lcd.print(" Degree Celcius");

/*

if( mlx.readObjectTempC() >=40 )

digitalWrite(LED_BUILTIN, HIGH);

}
else

digitalWrite(LED_BUILTIN, LOW);

*/

long duration, inches, cm;

// The sensor is triggered by a HIGH pulse of 10 or more microseconds.

// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:

pinMode(trigPin, OUTPUT);

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

// Read the signal from the sensor: a HIGH pulse whose

// duration is the time (in microseconds) from the sending

// of the ping to the reception of its echo off of an object.

pinMode(echoPin, INPUT);

duration = pulseIn(echoPin, HIGH);

// convert the time into a distance

inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);

if( (inches<=6 && inches >= 1) && mlx.readObjectTempC() <=40 )

digitalWrite(LED_BUILTIN, HIGH);

myservo.write(95); // write the position to servo

delay(2500);

else

digitalWrite(LED_BUILTIN, LOW);

myservo.write(0); // write the position to servo

delay(800);

long microsecondsToInches(long microseconds)

// According to Parallax's datasheet for the PING))), there are

// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per

// second). This gives the distance travelled by the ping, outbound

// and return, so we divide by 2 to get the distance of the obstacle.


// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf

return microseconds / 74 / 2;

long microsecondsToCentimeters(long microseconds)

// The speed of sound is 340 m/s or 29 microseconds per centimeter.

// The ping travels out and back, so to find the distance of the

// object we take half of the distance travelled.

return microseconds / 29 / 2;

You might also like