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

Low Power Consumption in Arduino Projects

In the world of embedded systems and IoT (Internet of Things), power consumption is a critical factor. Devices often run on batteries, and efficient power management can significantly extend their operational life. This article will explore techniques to reduce power consumption in Arduino projects, ensuring that your devices can run longer on a single charge. We'll focus on practical adjustments and code optimizations tailored for the Arduino environment.

Project: In this example project, we will create a temperature and humidity monitoring system using an Arduino Nano, a DHT22 sensor, and an OLED display. The system will enter a low-power sleep mode when not actively measuring or displaying data, significantly reducing power consumption.

Components List:

  1. Arduino Nano (1x)
  2. DHT22 Temperature and Humidity Sensor (1x)
  3. 0.96" I2C OLED Display (1x)
  4. 10kΩ Resistor (1x)
  5. Breadboard and Jumper Wires

Examples:

#include <DHT.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <avr/sleep.h>

// Define pin for DHT22 sensor
#define DHTPIN 2
#define DHTTYPE DHT22

// Initialize DHT sensor
DHT dht(DHTPIN, DHTTYPE);

// Initialize OLED display
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Initialize DHT sensor
  dht.begin();

  // Initialize OLED display
  if (!display.begin(SSD1306_I2C_ADDRESS, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;);
  }
  display.display();
  delay(2000);  // Pause for 2 seconds

  // Display initial message
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.print("Initializing...");
  display.display();
  delay(1000);
}

void loop() {
  // Measure temperature and humidity
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  // Display the readings on the OLED
  display.clearDisplay();
  display.setCursor(0, 0);
  display.print("Humidity: ");
  display.print(h);
  display.print(" %");
  display.setCursor(0, 10);
  display.print("Temp: ");
  display.print(t);
  display.print(" C");
  display.display();

  // Print the readings to the serial monitor
  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.print(F(" %  Temperature: "));
  Serial.print(t);
  Serial.println(F(" *C "));

  // Enter sleep mode for 10 seconds
  enterSleepMode(10);
}

void enterSleepMode(int sleepTime) {
  // Set sleep mode to Power Down
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();

  // Sleep for the specified time
  for (int i = 0; i < sleepTime; i++) {
    delay(1000);
  }

  // Disable sleep
  sleep_disable();
}

Explanation:

  1. Libraries: We include the necessary libraries for the DHT sensor, OLED display, and sleep functionality.
  2. Setup: Initialize the sensor and display, and show an initial message.
  3. Loop: Measure temperature and humidity, display the values, and enter sleep mode for 10 seconds to save power.
  4. enterSleepMode: A function to put the Arduino into a low-power sleep mode for a specified duration.

Common Challenges:

  • Sensor Read Failures: Ensure proper connections and check sensor specifications.
  • Display Initialization: Verify I2C address and connections.

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.