first commit
This commit is contained in:
147
NANO_SERRE/NANO_SERRE.ino
Normal file
147
NANO_SERRE/NANO_SERRE.ino
Normal file
@@ -0,0 +1,147 @@
|
||||
#include <OneWire.h>
|
||||
#include <DallasTemperature.h>
|
||||
|
||||
|
||||
//////////////////////////////////////////
|
||||
// DALLAS
|
||||
/////////////////////////////////////////
|
||||
#define onewirepin 4 // DATA pin of DS18B20 wired to pin 10 of Arduino
|
||||
#define moistPin A1
|
||||
OneWire oneWire(onewirepin);
|
||||
DallasTemperature sensors(&oneWire);
|
||||
|
||||
// find the DeviceAddress of your DS18B20 with the sketch DS18B20_address_reporter
|
||||
// then replace the 8-byte ID below with the reported one
|
||||
|
||||
DeviceAddress Probe = { 0x28, 0xFF, 0x61, 0x1D, 0x76, 0x04, 0x00, 0x34 };
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
// DHT
|
||||
////////////////////////////////////////
|
||||
#include "DHT.h"
|
||||
|
||||
#define DHTPIN 5
|
||||
#define DHTTYPE DHT11
|
||||
DHT dht(DHTPIN, DHTTYPE);
|
||||
|
||||
#include <avr/sleep.h>
|
||||
|
||||
void setup() {
|
||||
|
||||
|
||||
// initialize digital pin LED_BUILTIN as an output.
|
||||
Serial.begin(9600);
|
||||
pinMode(2, OUTPUT);
|
||||
pinMode(3, OUTPUT);
|
||||
pinMode(A0, INPUT);
|
||||
pinMode(moistPin, INPUT);
|
||||
//pinMode(10, INPUT);
|
||||
|
||||
sensors.begin (); // Initialize the sensor and set resolution level
|
||||
sensors.setResolution(Probe, 10);
|
||||
|
||||
delay(1000);
|
||||
Serial.println();
|
||||
Serial.print ("Number of Devices found on bus = ");
|
||||
Serial.println (sensors.getDeviceCount());
|
||||
Serial.print ("Getting temperatures... ");
|
||||
Serial.println ();
|
||||
|
||||
/** DHT **/
|
||||
dht.begin();
|
||||
|
||||
// For sleep
|
||||
// CLKPR = 0x80;
|
||||
// CLKPR = 0x01;
|
||||
stop();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Reads the information from the CI
|
||||
|
||||
/**
|
||||
* DHT11 : Temperature
|
||||
*/
|
||||
|
||||
float temperature = dht.readTemperature();
|
||||
float humidity_air = dht.readHumidity();
|
||||
|
||||
int lum = analogRead(A0);
|
||||
// int tmp = digitalRead(10);
|
||||
int moistVal = analogRead(moistPin);
|
||||
int percent = 2.718282 * 2.718282 * (.008985 * moistVal + 0.207762); //calculate percent for probes about 1 - 1.5 inches apart
|
||||
Serial.println(percent);
|
||||
|
||||
if (lum > 1000) {
|
||||
avance();
|
||||
delay(1000);
|
||||
//stop();
|
||||
}
|
||||
else {
|
||||
stop();
|
||||
}
|
||||
|
||||
digitalWrite(3, HIGH);
|
||||
Serial.print("Humidite ");
|
||||
Serial.print(humidity_air);
|
||||
Serial.print(" température ");
|
||||
Serial.print(temperature,2);
|
||||
Serial.print(" luminosite ");
|
||||
Serial.print(lum);
|
||||
Serial.print(" hum_sol ");
|
||||
Serial.print(moistVal);
|
||||
Serial.print(" %sol ");
|
||||
Serial.println(percent);
|
||||
|
||||
// sensors.requestTemperatures(); // Command all devices on bus to read temperature
|
||||
//
|
||||
// Serial.print("Temperature is: ");
|
||||
// printTemperature(Probe);
|
||||
// Serial.println();
|
||||
|
||||
delay(1000);
|
||||
digitalWrite(3, LOW);
|
||||
|
||||
//Serial.println("Goto sleep");
|
||||
// set_sleep_mode(SLEEP_MODE_PWR_DOWN);
|
||||
// sleep_enable();
|
||||
// sleep_cpu();
|
||||
//Serial.println("Wake up");
|
||||
}
|
||||
|
||||
|
||||
void stop()
|
||||
{
|
||||
Serial.println("stop");
|
||||
digitalWrite(2, LOW); // turn the LED on (HIGH is the voltage level)
|
||||
delay(200);
|
||||
|
||||
Serial.println("stop fin");
|
||||
}
|
||||
|
||||
void avance() {
|
||||
Serial.println("avance");
|
||||
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
|
||||
delay(200);
|
||||
|
||||
Serial.println("avance fin");
|
||||
}
|
||||
|
||||
void printTemperature(DeviceAddress deviceAddress)
|
||||
{
|
||||
|
||||
float tempC = sensors.getTempC(deviceAddress);
|
||||
|
||||
if (tempC == -127.00)
|
||||
{
|
||||
Serial.print ("Error getting temperature ");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print ("C: ");
|
||||
Serial.println (tempC);
|
||||
// Serial.print (" F: ");
|
||||
// Serial.print(DallasTemperature::toFahrenheit(tempC));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user