Temperature Control Neo Pixels with Arduino Nano

Auteur avatarCETECH11 | Dernière modification 18/11/2023 par CETECH11

Will guide you to build a DHT11 controlled Neo pixel lighting system with Arduino Nano

Introduction

A NeoPixel ring controlled by a DHT11 sensor and an Arduino Nano can be a fascinating project that combines temperature sensing with visual feedback. This article will guide you through the process of building such a system.

Materials Needed

  • Arduino Nano
  • DHT11 Temperature and Humidity Sensor
  • Neo Pixel Ring
  • Jumper Wires

Matériaux

Outils

Étape 1 - Get PCBs For Your Projects Manufactured

You must check out PCBWAY for ordering PCBs online for cheap!

You get 10 good-quality PCBs manufactured and shipped to your doorstep for cheap. You will also get a discount on shipping on your first order. Upload your Gerber files onto PCBWAY to get them manufactured with good quality and quick turnaround time. PCBWay now could provide a complete product solution, from design to enclosure production. Check out their online Gerber viewer function. With reward points, you can get free stuff from their gift shop. Also, check out this useful blog on PCBWay Plugin for KiCad from here. Using this plugin, you can directly order PCBs in just one click after completing your design in KiCad.




Étape 2 - Connecting the Hardware

First, connect the DHT11 sensor and the Neo Pixel ring to the Arduino Nano. The DHT11 sensor can be connected to any digital pin on the Arduino Nano. The Neo Pixel ring should be connected to the D2 pin of the Arduino Nano.




Étape 3 - Installing the Libraries

You will need to install the DHT library and the Adafruit Neo Pixel library in your Arduino IDE. These libraries contain the necessary functions to interact with the DHT11 sensor and the Neo Pixel ring.

First Navigate to Sketch > Include Library > Manage Libraries...

In the Library Manager, there is a search box. Type “DHT sensor library” into the search box.

In the search results, find the library named “DHT sensor library” by Adafruit. Click on it, then click the “Install” button.

And that’s it! You’ve successfully installed the DHT11 sensor library in Arduino IDE. This library should now be available for inclusion in your sketches.



Étape 4 - Programming the Arduino

The next step is to program the Arduino Nano. The program should read the temperature from the DHT11 sensor and change the color of the Neo Pixel ring based on the temperature.

For example, you could program the Neo Pixel ring to display a blue color when the temperature is below a certain threshold.

A green color when the temperature is within a comfortable range,

and a red color when the temperature is above a certain threshold.


Étape 5 - Testing the System

After programming the Arduino Nano, it’s time to test the system. Power up the Arduino and observe the color of the Neo Pixel ring. Try changing the temperature around the DHT11 sensor (for example, by blowing hot or cold air onto the sensor) and see if the color of the Neo Pixel ring changes accordingly.
#include <Adafruit_NeoPixel.h>
#include <Adafruit_Sensor.h>

#include <DHT.h>
#include <DHT_U.h>

#define DHTTYPE    DHT11     // DHT 11
#define DHTPIN 3
DHT_Unified dht(DHTPIN, DHTTYPE);
#define PIN 2 // Neo

Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);

void setup() {

  Serial.begin(115200);
  dht.begin();
  sensor_t sensor;
  strip.begin();
  strip.setBrightness(100);
  strip.show();
}

void loop() {

  sensors_event_t event;
  dht.temperature().getEvent(&event);
  Serial.print(F("Temperature: "));
  float temp1 = event.temperature;
  Serial.print(temp1);
  Serial.println(F("°C"));
  
  dht.humidity().getEvent(&event);
  Serial.print(F("Humidity: "));
  float hum1 = event.relative_humidity;
  Serial.print(hum1);
  Serial.println(F("%"));

  if (temp1 >= 28 && temp1 < 31) {
    strip.clear(); // Set all pixel colors to 'off'
    for (int i = 0; i < 12; i++) { // For each pixel...
      strip.setPixelColor(i, strip.Color(0, 150, 0));
      strip.show();
    }
  }

  else if (temp1 < 28) {
    strip.clear();
    for (int i = 0; i < 12; i++) { // For each pixel...
      strip.setPixelColor(i, strip.Color(0, 0, 150));
      strip.show();
    }
  }

  else {
    strip.clear();
    for (int i = 0; i < 12; i++) { // For each pixel...
      strip.setPixelColor(i, strip.Color(150, 0, 0));
      strip.show();
    }
  }

}



Étape 6 - Conclusion

Building a DHT11-controlled Neo Pixel ring with an Arduino Nano is a fun and educational project combining temperature sensing and visual feedback. With this system, you can visually monitor the temperature in a room and get a sense of whether the temperature is within a comfortable range.

Commentaires

Published