Zootropolis Istanbul sketch
// TEMPERATURE
// This Arduino sketch reads DS18B20 “1-Wire” digital
// temperature sensors.
// Copyright (c) 2010 Mark McComb, hacktronics LLC
// License: http://www.opensource.org/licenses/mit-license.php (Go crazy)
// Tutorial:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html
#include
#include
// Data wire is plugged into pin 3 on the Arduino
#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.
DallasTemperature sensors(&oneWire);
// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
//DeviceAddress insideThermometer = { 0x28, 0x90, 0xFB, 0x89, 0x04, 0x00, 0x00, 0xAD };
DeviceAddress outsideThermometer = { 0x28, 0x90, 0xFB, 0x89, 0x04, 0x00, 0x00, 0xAD };
//DeviceAddress dogHouseThermometer = { 0x28, 0x90, 0xFB, 0x89, 0x04, 0x00, 0x00, 0xAD };
// HUMIDITY
//From the bildr article http://bildr.org/2012/11/hih4030-arduino/
int HIH4030_Pin = A1; //analog pin 0
// VIBRATION
const int sensorPin = A0;
int value = 0;
void setup()
{
Serial.begin(9600);
}
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
Serial.print(“Error getting temperature”);
} else {
Serial.print(“C: “);
Serial.print(tempC);
Serial.print(” F: “);
Serial.print(DallasTemperature::toFahrenheit(tempC));
}
}
void loop(void)
{
delay(2000);
//Serial.print(“Getting temperatures…\n\r”);
sensors.requestTemperatures();
//Serial.print(“Inside temperature is: “);
//printTemperature(insideThermometer);
//Serial.print(“\n\r”);
Serial.print(“Outside temperature is: “);
printTemperature(outsideThermometer);
Serial.print(“\n\r”);
//Serial.print(“Dog House temperature is: “);
//printTemperature(dogHouseThermometer);
//Serial.print(“\n\r\n\r”);
//To properly caculate relative humidity, we need the temperature.
float temperature = 25; //replace with a thermometer reading if you have it
float relativeHumidity = getHumidity(temperature);
Serial.println(“Rerelative Humidity is:”);
Serial.println(relativeHumidity);
delay(1000); //just here to slow it down so you can read it
value = analogRead(sensorPin);
//send data to serial port only if higher than threshold of 700
if(value>700)
//we divide the value by 4 because Processing gets data range 0-255, and analog in in arduino reads 0-1023
Serial.print(“vibration: “);
Serial.print(value);
delay(1000);
}
float getHumidity(float degreesCelsius)
{
//caculate relative humidity
float supplyVolt = 5.0;
// read the value from the sensor:
int HIH4030_Value = analogRead(HIH4030_Pin);
float voltage = HIH4030_Value/1023. * supplyVolt; // convert to voltage value
// convert the voltage to a relative humidity
// – the equation is derived from the HIH-4030/31 datasheet
// – it is not calibrated to your individual sensor
// Table 2 of the sheet shows the may deviate from this line
float sensorRH = 161.0 * voltage / supplyVolt – 25.8;
float trueRH = sensorRH / (1.0546 – 0.0026 * degreesCelsius); //temperature adjustment
return trueRH;
}