LEDS, PIR Sensor, Temperature Sensor - Server Room Project

Created a Server Room Project I though I would share.

Project tests temperature (*F) and will flash addressable LED Strip according to different alarms. Project will also turn on all LEDs to White if someone enters server room for more light.

I borrowed from a lot of different projects, so thank you all for your help.

JP


/*
 * Project: Server Room Temperature and Person Detection
 * Created by Jared Pruett
 * 
 * Board: Ardunio Uno
 * PIR Sensor: HC-SR501
 * Thermostat: DS17B20
 * LEDS: 5M / 16.4Ft LED Strip - WS2812B  - 300 Pixels on LED Strip and 5V 15amp Power supply
 * 
 * Description: 
 * PIR sensor checks if people enter room and turns on White Lights to see better
 * Temperature is checked constantly and will alarm the LEDs (Red and White for Hot, Blue and White for Cold)  
 * 
 * 
 * 
 * Pin Out: 
 * D2: PIR Sensor
 * D3: Thermostat
 * D4: Buzzer
 * D7: LED Signal Line
  */
 


#include <FastLED.h>
#include <OneWire.h>
#include <DallasTemperature.h>


//ONE WIRE and Temperature Sensor
// Data wire is conntec to the Arduino digital pin 3
#define ONE_WIRE_BUS 3

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature sensor 
DallasTemperature sensors(&oneWire);



//LED Stuff
#define LED_PIN     7
#define NUM_LEDS    300
CRGB leds[NUM_LEDS];



//Pins Number Setup
int motionSensorPin = 2;
int thermostatPin = 3;
int buzzerPin = 4;

//Intial Variables
int curTemp = 72;
int alarmTimeDelay = 500;
int OnOffDelay = 60000;  //Motion Delay









void setup() {

  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  Serial.begin(9600); // setup Serial Monitor to display information
  pinMode(motionSensorPin, INPUT); // Input from motion sensor
  pinMode(thermostatPin, INPUT); // Input from thermostat
  pinMode(buzzerPin, OUTPUT); // Output from buzzer
  sensors.begin(); //Start Checking Temp
  digitalWrite(4,LOW); //Cut of Buzzer
}




// Function to Turn on White Light
void lightsOn()
{
  for(int LED=0;LED<NUM_LEDS;LED++)
  {  
    leds[LED]=CRGB(255,255,255);
  }
  FastLED.show();
  delay(OnOffDelay);
}

// Function to Turn off All Light
void lightsOff()
{
for(int LED=0;LED<NUM_LEDS;LED++)
  {  
    leds[LED]=CRGB(0,0,0);
  }
  FastLED.show();
}

//Function to Flash RGB Color Specified, alternating Colr and White 
void alarmLED (int red, int green, int blue)
{
  for(int LED=0;LED<NUM_LEDS;LED++)
  {
    if (LED % 2 == 0)
    {
      leds[LED]=CRGB(red,green,blue);
    }
    else
    {
      leds[LED]=CRGB(255,255,255);
    }
  }  
  FastLED.show();
  delay(alarmTimeDelay);

  for(int LED=0;LED<NUM_LEDS;LED++)
  {
    if (LED % 2 == 0)
    {
      leds[LED]=CRGB(255,255,255);
    }
    else
    {
      leds[LED]=CRGB(red,green,blue);   
    }
  }
  FastLED.show();
  delay(alarmTimeDelay);
}





// Function to check temperature and determine what to do when temperature reaches hiTemp and loTemp Settings. 
void tempCheck(int temp)
{

  int hiTemp = 90;
  int loTemp = 55;
 if (temp < loTemp) 
      {
        alarmLED(0,0,255); //Flash LEDS Blue 
        buzzer (1);
      }
      else if (temp > hiTemp)
      {
        alarmLED(255,0,0); //Flash LEDs Red
        buzzer (1);
      }
      else
      {
        //Turn off Buzzer and Serial Print the Current Temperature
        buzzer (0);
        Serial.print("Current Temperature: ");
        Serial.print(temp );
        Serial.print(" *F");
        Serial.println();
      } 
}


//Turn on Buzzer (1 for On, 0 for Off)
void buzzer(int buzz)
{
  if (buzz == 1)
   {
    digitalWrite(4,HIGH);
   }
   else 
   {
     digitalWrite(4,LOW);
   }
}


void loop() {

 
 int motion = digitalRead(motionSensorPin);
  if(motion)
  {
    Serial.println("Motion detected - Turning on Lights");
    lightsOn();
  }
  else
  {
     lightsOff();
  }


  // Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
  sensors.requestTemperatures(); 
  curTemp = sensors.getTempFByIndex(0);
  tempCheck (curTemp);
  delay(1000); 
}




very poor programming skill

Thanks for the project, I like the comments in the code expanding a little on the functions would make it easier to follow. Posting an annotated schematic would help present your project better. Be sure to show all of the connections, power, ground, and power sources possibly with some pictures. LInks to technical information on the sensors helps a lot as there are many with the same name but different.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.