Jasleen
Published

Temperature Sensor To control Servo Motor

In this arduino project, We use a temperature sensor LM35, to control the speed of the Servo motor.

IntermediateProtip1 hour46,847
Temperature Sensor To control Servo Motor

Things used in this project

Hardware components

Resistor 1k ohm
Resistor 1k ohm
×1
Arduino UNO
Arduino UNO
×1
Temperature Sensor
Temperature Sensor
×1
DC motor (generic)
×1
1N4007 – High Voltage, High Current Rated Diode
1N4007 – High Voltage, High Current Rated Diode
×1
General Purpose Transistor NPN
General Purpose Transistor NPN
×1
9V 1A Switching Wall Power Supply
9V 1A Switching Wall Power Supply
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Story

Read more

Schematics

Schematic Diagram

Code

temperature controlled servo motor

Arduino
float temp;

int tempPin = A0; //arduino pin used for temperature sensor

int tempMin = 25; // the temperature to start the buzzer

int tempMax = 70;

int fan = 6; // the pin where fan is connected

int fanSpeed = 0;

void setup() {

pinMode(fan, OUTPUT);

pinMode(tempPin, INPUT);

Serial.begin(9600);

}

void loop() {

temp = analogRead(tempPin);

temp = (temp *5.0*100.0)/1024.0; //calculate the temperature in Celsius

Serial.println(temp);

delay(1000); // delay in between reads for stability

if(temp < tempMin) { // if temp is lower than minimum temp

fanSpeed = 0; // fan is not spinning

digitalWrite(fan, LOW);

}

if((temp >= tempMin) && (temp <= tempMax)) //if temperature is higher than the minimum range

{

fanSpeed = map(temp, tempMin, tempMax, 32, 255); // the actual speed of fan

analogWrite(fan, fanSpeed); // spin the fan at the fanSpeed speed

}

}

Credits

Jasleen

Jasleen

1 project • 8 followers

Comments