#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h> //Temp sensor
#include <Wire.h>
#include <LiquidCrystal_I2C.h> //LCD display
#include <Adafruit_GFX.h> //Nokia Display
#include <Adafruit_PCD8544.h> //Nokia display
// Nokia dispay:
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
//Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);
Adafruit_PCD8544 display = Adafruit_PCD8544(16,0, 13, 15, 3);
//Adafruit_PCD8544 display = Adafruit_PCD8544(16=D0, 0= D3, 13=D7, 15=D8, 3=RX);
// Configuration for the display i2c op lolin pin D1=SCL D2=SDA
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
// Define Trig and Echo pin for ultrasonic sensor
#define trigPin 14 //(d05 op lolin)
#define echoPin 12 //(do06 op lolin)
// Define variables:
long duration;
int distance;
int inhoud;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxX"; //Enter the Auth code which was send by Blink
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxxxxe"; //Enter your WIFI Name
char pass[] = "xxxxxxxe22"; //Enter your WIFI Password
#define DHTPIN 2 // Digital pin D4 op lolin voor temp sensor
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21 // DHT 21, AM2301
DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
//ultrasone sensor
digitalWrite(trigPin, LOW);
delayMicroseconds(1000);
// Trigger the sensor by setting the trigPin high for 10 microseconds:
digitalWrite(trigPin, HIGH);
delayMicroseconds(2000);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
// Calculate the distance:
distance = duration*0.034/2;
inhoud= map(distance,200,30, 0,5000);
//Blink settings
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, h); //V5 is for Humidity
Blynk.virtualWrite(V6, t); //V6 is for Temperature
Blynk.virtualWrite(V7, distance); //V6 is for Temperature
Blynk.virtualWrite(V8, inhoud); //V6 is for Temperature
// some serial info
Serial.println(t);
Serial.println(h);
Serial.println(distance);
Serial.println(inhoud);
//tekst on display lcd
lcd.setCursor ( 0, 0 );
lcd.print("Afstand : "); //distance
lcd.print(distance);
lcd.print (" cm ");
lcd.setCursor ( 0, 1 );
lcd.print("Inhoud : ");
lcd.setCursor ( 8, 1 );
lcd.print (inhoud);
lcd.setCursor ( 13, 1 );
lcd.print ("L");
//Nokia display
display.clearDisplay();
display.setTextSize(1);
// display.setTextColor(WHITE, BLACK); // 'inverted' text
display.setCursor(0,0);
display.print("Temp = ");
display.print(t);
display.setCursor(0,10);
display.print("Vocht = ");
display.println(h);
display.setTextColor(BLACK);
display.setCursor(0,22);
display.print(distance);
display.print(" cm");
display.setCursor(0,35);
display.print("Inh ");
display.setCursor(20,30);
display.setTextSize(2);
display.print(inhoud);
display.print("L");
display.display();
}
void setup()
{
Serial.begin(115200); // See the connection status in Serial Monitor
// Define inputs and outputs
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
//*Just some text for testing the display
lcd.begin(16,2); // initialize the lcd
lcd.home (); // go home
lcd.setCursor ( 0, 0 ); // go to the next line
lcd.print("Tank inhoud ");
lcd.setCursor ( 0, 1 ); // go to the next line
lcd.print (" Ultra sonic ");
delay(2000);
lcd.clear();
//
Blynk.begin(auth, ssid, pass);
dht.begin();
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
display.begin();
// init done
// you can change the contrast around to adapt the display
// for the best viewing!
display.setContrast(60);
display.display(); // show splashscreen
delay(500);
display.clearDisplay(); // clears the screen and buffer
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE, BLACK); // 'inverted' text
display.setCursor(0,5);
display.println(" Spike ");
display.setTextSize(1);
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(10,25);
display.println("Arduino");
display.setCursor(30,35);
display.println("projects");
display.display();
delay(500);
}
void loop()
{
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates SimpleTimer
}
Geen opmerkingen:
Een reactie posten