|
O‘rnatilgan tizimlari fanidan 5-topshiriq bajardi
|
Sana | 20.05.2024 | Hajmi | 278,23 Kb. | | #245777 |
Bog'liq 5 6 O\'T ELBEK
O‘ZBEKISTON RESPUBLIKASI
RAQAMLI TEXNOLOGIYALAR VAZIRLIGI
MUHAMMAD AL-XORAZMIY NOMIDAGI
TOSHKENT AXBOROT TEXNOLOGIYALARI UNIVERSITETI
Kompyuter injiniringi fakulteti
Sun’iy intellekt kafedrasi
O‘rnatilgan tizimlari fanidan
5-TOPSHIRIQ
Bajardi: Xolmatov Elbek guruh talabasi
424-21
Tekshirdi: Xoldorov Sh.I.
TOSHKENT – 2024
Automated Servo Motor Control
Using TMP36 Temperature Sensor and Potentiometer
Introduction
In this project, we aim to create a system that uses a TMP36 temperature sensor, a potentiometer, and a servo motor to automate movements based on temperature readings. The objective is to control the servo motor such that it moves right and left when the temperature exceeds 40°C and moves forward and backward when the temperature drops below 0°C. This setup can be useful for various applications, including automated ventilation systems, cooling mechanisms, and other temperature-dependent mechanical operations.
Body
Components Required:
1. Arduino UNO
2. TMP36 temperature sensor
3. Potentiometer
4. Servo motor
5. Breadboard and jumper wires
Circuit Diagram:
To build the circuit, connect the components as follows:
1. TMP36 sensor:
- VCC to 5V
- GND to GND
- Analog output to A0
2. Potentiometer:
- One terminal to 5V
- Second terminal to GND
- Wiper (middle terminal) to A1
3. Servo motor:
- VCC to 5V
- GND to GND
- Control signal to digital pin 9
Code Implementation:
The following Arduino code reads the temperature from the TMP36 sensor and the position from the potentiometer. It then controls the servo motor based on the temperature readings.
cpp
#include
const int tempPin = A0; // TMP36 temperature sensor pin
const int potPin = A1; // Potentiometer pin
const int servoPin = A2; // Servo motor pin
Servo myServo;
void setup() {
Serial.begin(9600);
myServo.attach(servoPin);
}
void loop() {
// Read temperature from TMP36
int tempReading = analogRead(tempPin);
float voltage = tempReading * (5.0 / 1024.0);
float temperatureC = (voltage - 0.5) * 100.0;
// Read potentiometer value
int potReading = analogRead(potPin);
int servoAngle = map(potReading, 0, 1023, 0, 180);
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.print(" C, Potentiometer: ");
Serial.print(potReading);
Serial.print(", Servo Angle: ");
Serial.println(servoAngle);
if (temperatureC > 40) {
// If temperature is above 40°C, move the servo to the angle specified by the potentiometer
myServo.write(servoAngle);
} else if (temperatureC < 0) {
// If temperature is below 0°C, move the servo forward and backward
myServo.write(0);
delay(1000);
myServo.write(180);
delay(1000);
} else {
// If temperature is between 0°C and 40°C, keep the servo at a neutral position
myServo.write(90);
}
delay(500);
}
Explanation:
1. Temperature Reading: The TMP36 sensor's analog output is converted to a temperature value in Celsius.
2. Potentiometer Reading: The potentiometer's analog output is mapped to an angle between 0 and 180 degrees.
3. Servo Control: Based on the temperature readings, the servo motor is controlled:
- If the temperature exceeds 40°C, the servo angle is set according to the potentiometer's position.
- If the temperature drops below 0°C, the servo alternates between 0° and 180°.
- If the temperature is between 0°C and 40°C, the servo remains at a neutral position (90°).
Figure 1.1 Main view
Figure 1.2 Schema of the project
Figure 1.3 Used elements
Url: https://www.tinkercad.com/things/ik71wJ71njC-super-waasa-amur/editel?sharecode=csLOGh2lVV0eg87bRXMAFOIgJoUIgkh4UZu5olfZe9E
Conclusion
This project demonstrates a simple yet effective way to control a servo motor based on temperature readings using a TMP36 sensor and a potentiometer. By automating the servo movements based on temperature thresholds, we can achieve responsive mechanical actions suitable for various practical applications.
The implementation showcases how Arduino can be used to integrate different sensors and actuators to create an automated system. This approach can be further expanded and modified for more complex automation tasks in environmental control systems and other temperature-sensitive operations.
|
| |