define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <SPI.h>
#include <WiFi101.h>
#include <BlynkSimpleMKR1000.h>
#include <Wire.h>
#include <SimpleTimer.h>
#include <FlashAsEEPROM.h>
#include "DHT.h"
#include <BlynkSimpleWiFiShield101.h>
#define DHTPIN 1 // what pin we're connected to, pin1 is 5th pin from end
#define analogPin A5//sensore suolo
#define analogPin A6//sensore temperatura terreno
#define beta 3950 //the beta of the thermistor
#define resistance 10 //the value of the pull-up resistor
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int sm=0;
int pinMoist=A5;
// connessione display (pin)
const int soilTemperature = A6;
const int soilMoisture = A5;
const int tsu = 4;
const int tgiu = 5;
const int hsu = 8;
const int hgiu = 2;
const int ssu = 13;
const int sgiu = 14;
//serpentina riscaldamento
const int vout =6;
const int v2out =3;
const int tout =7;
//umidificatore
const int hout =9;
//irrigazione pompa
const int sout =10;
//dichiarazione pulsanti
int statotsu =0;
int statotgiu =0;
int statohsu =0;
int statohgiu =0;
int tempimpostata =0;
int umidimpostata =0;
int soil = 750;
//umidità terreno
//int umtrimpostata =0;
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int riscaldamento =7;
const int irrigazione = 10;
const int umidificatore =9;
const int ventilazione =6;
//const int stato = irrigazione ;
//#define DHTTYPE DHT21 // DHT 21
#define DHTTYPE DHT22 // DHT 22
//Adafruit_BMP085 bmp;
DHT dht(DHTPIN,DHTTYPE);
SimpleTimer timer;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "23b0f2756b2e4bcc83d91908426df871";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Alice-63479497"; // your network SSID (name)
char pass[] = "a28f1gldje7lmwe88sb0vzzn"; //your network password
int keyIndex = 0; // your network key Index number (needed only for WEP)
//int relayPin = 6;
void sendSensor()
{
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
long a =1023 - analogRead(A6); //read thermistor value
float tempC = beta /(log((1025.0 * 10 / a - 10) / 10) + beta / 298.0) - 273.0;
float t2 =tempC;
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)|| isnan(sm) )
{
Serial.println("Failed to read from DHT sensor!");
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
Blynk.virtualWrite(V2, h);
Blynk.virtualWrite(V3, t);
Blynk.virtualWrite(V5, pinMoist );
//Serial.println(soilMoisture);
Blynk.virtualWrite(V6, t2 );
//Serial.println(soilTemperature);
Blynk.virtualWrite(V7, soil );
Blynk.virtualWrite(V8, tempimpostata );
Blynk.virtualWrite(V9, umidimpostata );
}
// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin 1
//BLYNK_WRITE(V1) {
// int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
// You can also use:
// String i = param.asStr();
// double d = param.asDouble();
//SerialUSB.print("V1 button is: ");
// SerialUSB.println(pinValue);
//if (pinValue == 1) {
//digitalWrite(relayPin, HIGH);
// } else {
// digitalWrite(relayPin, LOW);
// }
//}
void setup()
{
lcd.begin();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("T:");
lcd.setCursor(4,0);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("H:");
lcd.setCursor(4,1);
lcd.print(" ");
lcd.setCursor(8,0);
lcd.print(" Soil:");
//riscaldamento-ventoole
pinMode(tout, OUTPUT);
pinMode(vout, OUTPUT);
//umidificatore-ventole
pinMode(hout, OUTPUT);
//irrigazione
pinMode(sout, OUTPUT);
Serial.begin(9600);
// If the EEPROM is empty then isValid() is false
if (!EEPROM.isValid()) {
Serial.println("EEPROM is empty, writing some example data:");
Serial.print("->");
for (int i=0; i<20; i++) {
EEPROM.write(i, 100+i);
Serial.print(" ");
Serial.print(100+i);
}
Serial.println();
EEPROM.commit();
Serial.println("Done!");
Serial.print("After commit, calling isValid() returns ");
Serial.println(EEPROM.isValid());
} else {
Serial.println("EEPROM has been written.");
Serial.println("Here is the content of the first 20 bytes:");
Serial.print("->");
for (int i=0; i<20; i++) {
Serial.print(" ");
Serial.print(EEPROM.read(i));
}
Serial.println();
}
Blynk.begin(auth, ssid, pass);
// Or specify server using one of those commands:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, ssid, pass, server_ip, port);
dht.begin();
Wire.begin(); // required by BMP180
// bmp.begin();
timer.setInterval(1000L, sendSensor);
pinMode(riscaldamento, OUTPUT);
delay(5000);
}
BLYNK_CONNECTED() {
Blynk.syncVirtual(V20);
}
// This function will be called every time
// when App writes value to Virtual Pin 1
BLYNK_WRITE(V20)
{
if(param.asInt()==1)
{
digitalWrite(riscaldamento, LOW);
}
else
{
digitalWrite(riscaldamento, HIGH);
pinMode(2, OUTPUT);
}
}
void loop()
{
sm = analogRead(pinMoist);
long a =1023 - analogRead(A6); //read thermistor value
Serial.print("Raw reading ");
Serial.println(a);
//the calculating formula of temperature
float tempC = beta /(log((1025.0 * 10 / a - 10) / 10) + beta / 298.0) - 273.0;
statotsu = digitalRead (tsu);
if( statotsu == HIGH)
{tempimpostata++;}
statotgiu = digitalRead (tgiu);
if( statotgiu == HIGH)
{tempimpostata--;}
statohsu = digitalRead (hsu);
if( statohsu == HIGH)
{umidimpostata++;}
statohgiu = digitalRead (hgiu);
if( statohgiu == HIGH)
{umidimpostata--;}
statohsu = digitalRead (ssu);
if( statohsu == HIGH)
{soil++;}
statohgiu = digitalRead (sgiu);
if( statohgiu == HIGH)
{soil--;}
int t = dht.readTemperature();
delay(100);
lcd.setCursor(2, 0);
lcd.print(t);
lcd.setCursor(6, 0);
lcd.print(tempimpostata);
int h = dht.readHumidity();
delay(100);
lcd.setCursor(2, 1);
lcd.print(h);
lcd.setCursor(6, 1);
lcd.print(umidimpostata);
lcd.setCursor(9, 1);
lcd.println( soil);
if (tempimpostata > -1 && tempimpostata < 10)
{ lcd.setCursor (7, 0);
lcd.print (" ");}
if (umidimpostata > -1 && umidimpostata < 10)
{ lcd.setCursor (7, 1);
lcd.print (" ");}
if (soil > -1 && soil < 10)
{ lcd.setCursor (7, 0);
lcd.print (" ");}
delay(100);
if ( t < tempimpostata )
{digitalWrite (tout, HIGH );}
else {digitalWrite (tout, LOW);}
delay(100);
if ( soil > sm )
{digitalWrite ( sout, HIGH );}
else {digitalWrite (sout, LOW);}
delay(100);
if ( umidimpostata < h && t > tempimpostata ) {
digitalWrite ( vout, HIGH );
} else {
digitalWrite (vout, LOW);
delay(100);
if ( h < umidimpostata )
{digitalWrite ( hout, HIGH );}
else {digitalWrite (hout, LOW);
delay(100);
}
}
timer.run(); // Initiates SimpleTimer
Blynk.run();
delay (150);
}
this is the error:
Arduino:1.6.9 (Windows 10), Scheda:"Arduino/MKR1010"
The mkrwifi1010 board (samd platform, arduino package) is unknown
Error during compilation for the Arduino MKR WiFi 1010 card.
Found invalid library in C:\Program Files (x86)\Arduino\libraries\PietteTech_DHT-master: C:\Program Files (x86)\Arduino\libraries\PietteTech_DHT-master
Trovata libreria non valida in C:\Program Files (x86)\Arduino\libraries\u8glib-master: C:\Program Files (x86)\Arduino\libraries\u8glib-master
Found invalid library in C:\Program Files (x86)\Arduino\libraries\PietteTech_DHT-master: C:\Program Files (x86)\Arduino\libraries\PietteTech_DHT-master
Found invalid library in C:\Program Files (x86)\Arduino\libraries\u8glib-master: C:\Program Files (x86)\Arduino\libraries\u8glib-master