Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Create a Temperature Sensor System Using Arduino

Temperature sensors are essential components in various applications, from weather stations to home automation systems. In the Arduino environment, using a temperature sensor is straightforward and can be achieved with minimal components. This article will guide you through setting up a temperature sensor system using an Arduino board and a common temperature sensor, the LM35.

Components Required:

  • Arduino Uno (or any compatible Arduino board)
  • LM35 temperature sensor
  • Jumper wires
  • Breadboard
  • USB cable to connect Arduino to a computer

Understanding the LM35 Sensor:

The LM35 is a precision integrated-circuit temperature sensor with an output voltage linearly proportional to the Centigrade temperature. It provides a simple way to measure temperature with an accuracy of ±0.5°C at room temperature.

Wiring the LM35 to Arduino:

  1. Connect the LM35:
    • The LM35 has three pins: VCC, GND, and VOUT.
    • Connect the VCC pin to the 5V pin on the Arduino.
    • Connect the GND pin to one of the GND pins on the Arduino.
    • Connect the VOUT pin to one of the analog input pins on the Arduino, for example, A0.

Writing the Arduino Code:

Below is a sample code to read the temperature from the LM35 sensor and print it to the Serial Monitor.

const int sensorPin = A0;  // Pin connected to VOUT of LM35

void setup() {
  Serial.begin(9600);  // Start the serial communication
}

void loop() {
  int sensorValue = analogRead(sensorPin);  // Read the analog value from the sensor
  float voltage = sensorValue * (5.0 / 1023.0);  // Convert the analog reading to voltage
  float temperatureC = voltage * 100;  // Convert the voltage to temperature in Celsius

  Serial.print("Temperature: ");
  Serial.print(temperatureC);
  Serial.println(" °C");

  delay(1000);  // Wait for a second before reading again
}

How the Code Works:

  • analogRead(sensorPin): Reads the voltage from the sensor pin.
  • Voltage Calculation: Converts the analog reading (0 to 1023) to a voltage (0 to 5V).
  • Temperature Calculation: Converts the voltage to temperature in Celsius using the LM35's scale factor (10mV per °C).

Uploading the Code:

  1. Connect your Arduino to your computer using the USB cable.
  2. Open the Arduino IDE.
  3. Copy the above code into a new sketch.
  4. Select the correct board and port from the 'Tools' menu.
  5. Click on the 'Upload' button to upload the code to the Arduino.

Testing:

  • Open the Serial Monitor from the Arduino IDE (Ctrl+Shift+M).
  • You should see the temperature readings in Celsius displayed every second.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.