Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Controlled Servo with Ultrasonic and Thermal Scanning

View and Edit Project In Cirkit DesignerImage of Arduino UNO Controlled Servo with Ultrasonic and Thermal Scanning

Circuit Documentation

Summary

This circuit is designed to control a servo motor that rotates an ultrasonic sensor (HC-SR04) and a thermal sensor (MLX90614) to scan the environment. The ultrasonic sensor is used to measure distances, while the thermal sensor measures temperatures. The data collected from these sensors can be used to identify a person in a critical situation. The Arduino UNO serves as the central processing unit, controlling the servo and reading data from the sensors. The circuit is powered by a 9V battery, and communication with the thermal sensor is facilitated through an I2C module.

Component List

Arduino UNO

Servo

HC-SR04 Ultrasonic Sensor

mlx90614

I2C module

9V Battery

GPS NEO 6M

Wiring Details

Arduino UNO

Servo

HC-SR04 Ultrasonic Sensor

mlx90614

I2C module

9V Battery

GPS NEO 6M

Documented Code

// This Arduino sketch controls a servo motor to rotate an ultrasonic sensor
// and a thermal sensor (MLX90614) to scan the environment. The ultrasonic
// sensor measures distances, and the thermal sensor measures temperatures.
// The data is used to identify a person in a critical situation.

#include <Servo.h>
#include <Wire.h>
#include <Adafruit_MLX90614.h>

// Defines pins for the Ultrasonic Sensor
const int trigPin = 9;
const int echoPin = 10;

// Variables for the duration and the distance
long duration;
int distance;

Servo myServo; // Creates a servo object for controlling the servo motor
Adafruit_MLX90614 mlx = Adafruit_MLX90614(); // Creates an object for the MLX90614

void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  Serial.begin(9600);
  myServo.attach(11); // Defines on which pin is the servo motor attached
  mlx.begin(); // Initializes the MLX90614 sensor
}

void loop() {
  // Rotates the servo motor from 15 to 165 degrees
  for(int i = 15; i <= 165; i++) {
    myServo.write(i);
    delay(30);
    distance = calculateDistance(); // Calculates distance
    float temp = mlx.readObjectTempC(); // Reads temperature
    Serial.print(i); // Sends the current degree to the Serial Port
    Serial.print(",");
    Serial.print(distance); // Sends the distance value to the Serial Port
    Serial.print(",");
    Serial.print(temp); // Sends the temperature value to the Serial Port
    Serial.print(".");
  }
  // Repeats the previous lines from 165 to 15 degrees
  for(int i = 165; i > 15; i--) {
    myServo.write(i);
    delay(30);
    distance = calculateDistance();
    float temp = mlx.readObjectTempC();
    Serial.print(i);
    Serial.print(",");
    Serial.print(distance);
    Serial.print(",");
    Serial.print(temp);
    Serial.print(".");
  }
}

// Function for calculating the distance measured by the Ultrasonic sensor
int calculateDistance() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH); // Sets the trigPin on HIGH state for 10 micro seconds
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH); // Reads the echoPin
  distance = duration * 0.034 / 2; // Calculating the distance
  return distance;
}

This code is designed to be uploaded to the Arduino UNO microcontroller. It initializes the servo and sensors in the setup() function and then enters a loop where it rotates the servo, reads the distance from the ultrasonic sensor, and the temperature from the MLX90614 sensor. The data is then printed to the serial port for monitoring. The calculateDistance() function is used to trigger the ultrasonic sensor and calculate the distance based on the time it takes for the echo to return.