// This #include statement was automatically added by the Particle IDE.
//#include "lib1.h"
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
#include "Adafruit_DHT.h"
#define DHTPIN 0 // what pin we're connected to
void callback(char* topic, byte* payload, unsigned int length);
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
const int ledPin1 = D1 ;
const int ledPin2 = D2 ;
const int ledPin3 = D7 ;
const int analogInPin1 = A0;
const int analogInPin2 = A1;
char* message;
#define ThermisterPin 2
int main ()
{
char buffer [100];
int n, a=5, b=3;
n=sprintf (buffer, "%d plus %d is %d", a, b, a+b);
printf ("[%s] is a string %d chars long\n",buffer,n);
return 0;
}
//*******************//
int sensorValue = 0;
int outputValue = 0;
int sensorValue2 = 0;
int outputValue2 = 0;
int sensorValue3 = 0;
int sensorValue4 = 0;
int ledState = LOW;
int ledState2 = LOW;
int ledState3 = HIGH;
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println("DHT22 test!");
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
char message[56];
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a
// very slow sensor)
float h = dht.getHumidity();
// Read temperature as Celsius
float t = dht.getTempCelcius();
// Read temperature as Farenheit
float f = dht.getTempFarenheit();
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Compute heat index
// Must send in temp in Fahrenheit!
float hi = dht.getHeatIndex();
float dp = dht.getDewPoint();
float k = dht.getTempKelvin();
Serial.print("Humid: ");
Serial.print(h);
Serial.print("% - ");
Serial.print("Temp: ");
Serial.print(t);
Serial.print("*C ");
Serial.print(f);
Serial.print("*F ");
Serial.print(k);
Serial.print("*K - ");
Serial.print("DewP: ");
Serial.print(dp);
Serial.print("*C - ");
Serial.print("HeatI: ");
Serial.print(hi);
Serial.println("*C");
sensorValue3 = (t);
sprintf(message, " %d ", sensorValue3);
Particle.publish("Temperature", message, PRIVATE);
sensorValue4 = (h);
sprintf(message, " %d ", sensorValue4);
Particle.publish("Humididty" , message ,PRIVATE);
sensorValue2 = analogRead(analogInPin2);
outputValue2 = map(sensorValue, 0, 5000, 0, 255);
Serial.println(sensorValue2);
sprintf(message, " %d ", sensorValue2);
Particle.publish("mymosquitto/Particle2", message);
//******************//
sensorValue = analogRead(analogInPin1);
outputValue = map(sensorValue, 0, 5000, 0, 255);
Serial.println(sensorValue);
sprintf(message, " %d " , sensorValue );
Particle.publish("mymosquitto/Particle1", message);
//******************//
if (sensorValue < 1400) {
digitalWrite (ledPin2, HIGH);
digitalWrite (ledPin1, LOW);
Particle.publish("mymosquitto/Particle", "Larry Happy");
delay(1000);
}
else if (sensorValue > 1400) {
digitalWrite (ledPin1, HIGH);
digitalWrite (ledPin2, LOW);
Particle.publish("mymosquitto/Particle", "Larry needs Water");
delay(1000);
}
Serial.println(Time.timeStr());
}