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

Arduino-Controlled Temperature-Activated DC Motor

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Temperature-Activated DC Motor

Circuit Documentation

Summary

This circuit is designed to read temperature data from an LM35 temperature sensor and control a DC motor using an L298N motor driver module. The motor's operation is dependent on the temperature reading; it turns on when the temperature reaches or exceeds 27 degrees Celsius, and its speed increases with rising temperature. The Arduino UNO microcontroller serves as the central processing unit, reading the sensor data, calculating the temperature, and controlling the motor speed accordingly.

Component List

Arduino UNO

L298N 2A Dual Motor Driver Module with PWM Control

DC Motor

Temperature Sensor (LM35)

9V Battery

Wiring Details

Arduino UNO

L298N 2A Dual Motor Driver Module with PWM Control

DC Motor

Temperature Sensor (LM35)

9V Battery

Documented Code

/*
 * This Arduino sketch reads the temperature from an LM35 sensor and controls
 * a DC motor via an L298N motor driver. The motor turns on if the temperature
 * reaches 27 degrees Celsius and its speed increases as the temperature rises.
 */

const int tempPin = A0; // Pin connected to LM35 Vout
const int motorEnablePin = 9; // Pin connected to L298N ENA
const int motorIn1Pin = 8; // Pin connected to L298N IN1
const int motorIn2Pin = 7; // Pin connected to L298N IN2

void setup() {
  pinMode(motorEnablePin, OUTPUT);
  pinMode(motorIn1Pin, OUTPUT);
  pinMode(motorIn2Pin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int tempReading = analogRead(tempPin);
  float voltage = tempReading * (5.0 / 1023.0);
  float temperatureC = voltage * 100.0;
  Serial.print("Temperature: ");
  Serial.print(temperatureC);
  Serial.println(" C");

  if (temperatureC >= 27.0) {
    int motorSpeed = map(temperatureC, 27, 50, 0, 255);
    motorSpeed = constrain(motorSpeed, 0, 255);
    analogWrite(motorEnablePin, motorSpeed);
    digitalWrite(motorIn1Pin, HIGH);
    digitalWrite(motorIn2Pin, LOW);
  } else {
    analogWrite(motorEnablePin, 0);
    digitalWrite(motorIn1Pin, LOW);
    digitalWrite(motorIn2Pin, LOW);
  }

  delay(1000); // Wait for 1 second before next reading
}

This code is written for the Arduino UNO and is responsible for reading the temperature from the LM35 sensor, calculating the temperature in Celsius, and controlling the DC motor through the L298N motor driver based on the temperature reading. The motor speed is controlled using PWM on pin D9, and the motor direction is controlled by setting pins D8 and D7 to high or low.