Wreszcie udało mi się zrobić projekt o którym myślałem od dawna. (!!!Post w trakcie edycji!!!-prototyp skończony).
Mam jakis problem po złożeniu prototypu. Nie wiem czy nie zrobiłem błedu w kodzie, czy nie daje za mało napięcia.
Pomiar wilgotności gleby w paru doniczkach oraz pomiar temperatury i wilgotności powietrza. Koszt projektu około 60zł. 4 pomiary ziemi, 1 pomiar temperatury. Przedział w którym roślina ma sucho lub mokro (H->N->L) (High-Normal-Low) (narazie, niedługo przerobię na %). Przycisk do włączania/wyłączania podświetlenia. Uwielbiam Arduino. Coś takiego w sklepie, to z 600zł. Prototyp zrobiłem na Uno, ale oddziele prąd od sensorów, dam im osobne zasilanie i jak zwykle przerzucę projekt na mój ulubiony sprzęt, podróbka Nano za 8zł sztuka.
Edycja: Zmieniłem kod i dodałem '%', zamiast sygnału z sensora. Muszę jeszcze oczyścić kod z niepotrzebnych loop'ow i smieci.
Wersja 16x2
Wersja 20x4 (kod na dole)
Wersja prototypowa. Parę rzeczy do poprawienia. To jest wersja kompaktowa na wyświetlacz 16x2. Wyświetlacz 20x4 kosztuje o 7zł wiecej. Ja sobie taki będę montował, ale to jest łatwe do przerobienia w kodzie, a wtedy można zamontować więcej sensorów od temperatury powietrza. Dodam również komentarze, ale dopiero dzisiaj skończyłem to pisać. W sumie zacząłęm i skończyłem. Tak się jakoś samo zrobiło. Nie nazwał bym tego "pisać kod", bo to bardziej było kopiuj, wklej. W sumie to jest to gotowe do samopodlewania. Wystarczy tylko określić kiedy jest sucho (na razie przedział jest na oko), jak jest sucho, właczyć pompę. Tam gdzie jest funkcja wyświetlić literę "L" na ekranie, dodać loop'a, żeby też właczyć silnik i podlać. Ja to zrobię trochę inaczej, bo dodam tylko jedną pompę i wstawie 4 zawory, które sa zamkniete jak nie ma prądu. Podajesz sygnał, zawór sie otwiera i pompa zaczyna pracować. Taki miałem pomysł od samego początku, jak wymyśliłem sobie, że chcę roślinki. Po mału składam to wszystko razem. Chcę zrobić auto-box'a.
Linki z których zaczerpnąłem pomysł powyżej:
Blue IIC I2C TWI 1602 16x2 Serial LCD Module Display for Arduino
https://www.ebay.co.uk/itm/New-Blue-IIC-I2C-TWI-1602-16x2-Serial-LCD-Module-Display-for-Arduino-Hot-RASK
LCD I2C 16x2 Display - tutorial - code
https://forum.arduino.cc/index.php?topic=128635.0
I2C Scanner - Bardzo przydatna rzecz, do określania jakie urządzenie się tak naprawdę ma. Jedna rzecz to opis na "Chińskim" eBay'u, a druga, to co tak naprawdę przychodzi w paczce.
http://playground.arduino.cc/Main/I2cScanner
LCD I2C 16x2 Display - Library (uzyte biblioteki do wyswietlacza 16x2 'LiquidCrystal_V1.2.1.zip')
https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/
Soil Moisture Sensor
https://www.ebay.co.uk/itm/5pcs-Soil-Moisture-Hygrometer-Module-for-Moisture-Arduino-Wire-Water-Sensor-S5V1
Soil Moisture Sensor - tutorial - code
https://www.instructables.com/id/Arduino-Soil-Moisture-Sensor/
DHT11 humidity and temperature sensor (Te biblioteki umożliwiają podłaczenie tylko jednego sensora. Wersja bibliotek która umożliwia podłączenie większej liczby sensorów DHT11 na dole post'u.)
https://www.ebay.co.uk/itm/1X-DHT11-Temperature-and-Relative-Humidity-Sensor-Module-for-arduino-XB
DHT11 humidity and temperature sensor - tutorial - code
http://www.circuitbasics.com/how-to-set-up-the-dht11-humidity-sensor-on-an-arduino/
DHT11 - Library
http://www.circuitbasics.com/wp-content/uploads/2015/10/DHTLib.zip
Wersja na wyświetlacz 16x2 i 1 sensor DHT11:
Wersja na wyświetlacz 20x4. Uzyłem innych bibliotek.
LCD I2C 20x4 Display - Library (uzyte biblioteki do wyswietlacza 20x4 'Newliquidcrystal_1.3.5.zip')
https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/
DHT11 - tutorial (Wersja bibliotek dla wiecej niż jednego sensora DHT11.)
https://learn.adafruit.com/dht/overview
DHT11 - Library
https://github.com/adafruit/DHT-sensor-library
Adadruit Sensor - Error przy kompilowaniu programu 'Missing file Adafruit_Sensor.h'. Dodaj do folderu "DHT-sensor-library-master"
https://github.com/adafruit/Adafruit_Sensor
Wersja na wyświetlacz 20x4 i 2 sensory DHT11:
Mam jakis problem po złożeniu prototypu. Nie wiem czy nie zrobiłem błedu w kodzie, czy nie daje za mało napięcia.
Pomiar wilgotności gleby w paru doniczkach oraz pomiar temperatury i wilgotności powietrza. Koszt projektu około 60zł. 4 pomiary ziemi, 1 pomiar temperatury. Przedział w którym roślina ma sucho lub mokro (H->N->L) (High-Normal-Low) (narazie, niedługo przerobię na %). Przycisk do włączania/wyłączania podświetlenia. Uwielbiam Arduino. Coś takiego w sklepie, to z 600zł. Prototyp zrobiłem na Uno, ale oddziele prąd od sensorów, dam im osobne zasilanie i jak zwykle przerzucę projekt na mój ulubiony sprzęt, podróbka Nano za 8zł sztuka.
Edycja: Zmieniłem kod i dodałem '%', zamiast sygnału z sensora. Muszę jeszcze oczyścić kod z niepotrzebnych loop'ow i smieci.
Wersja 16x2
Wersja 20x4 (kod na dole)
Wersja prototypowa. Parę rzeczy do poprawienia. To jest wersja kompaktowa na wyświetlacz 16x2. Wyświetlacz 20x4 kosztuje o 7zł wiecej. Ja sobie taki będę montował, ale to jest łatwe do przerobienia w kodzie, a wtedy można zamontować więcej sensorów od temperatury powietrza. Dodam również komentarze, ale dopiero dzisiaj skończyłem to pisać. W sumie zacząłęm i skończyłem. Tak się jakoś samo zrobiło. Nie nazwał bym tego "pisać kod", bo to bardziej było kopiuj, wklej. W sumie to jest to gotowe do samopodlewania. Wystarczy tylko określić kiedy jest sucho (na razie przedział jest na oko), jak jest sucho, właczyć pompę. Tam gdzie jest funkcja wyświetlić literę "L" na ekranie, dodać loop'a, żeby też właczyć silnik i podlać. Ja to zrobię trochę inaczej, bo dodam tylko jedną pompę i wstawie 4 zawory, które sa zamkniete jak nie ma prądu. Podajesz sygnał, zawór sie otwiera i pompa zaczyna pracować. Taki miałem pomysł od samego początku, jak wymyśliłem sobie, że chcę roślinki. Po mału składam to wszystko razem. Chcę zrobić auto-box'a.
Linki z których zaczerpnąłem pomysł powyżej:
Blue IIC I2C TWI 1602 16x2 Serial LCD Module Display for Arduino
https://www.ebay.co.uk/itm/New-Blue-IIC-I2C-TWI-1602-16x2-Serial-LCD-Module-Display-for-Arduino-Hot-RASK
LCD I2C 16x2 Display - tutorial - code
https://forum.arduino.cc/index.php?topic=128635.0
I2C Scanner - Bardzo przydatna rzecz, do określania jakie urządzenie się tak naprawdę ma. Jedna rzecz to opis na "Chińskim" eBay'u, a druga, to co tak naprawdę przychodzi w paczce.
http://playground.arduino.cc/Main/I2cScanner
LCD I2C 16x2 Display - Library (uzyte biblioteki do wyswietlacza 16x2 'LiquidCrystal_V1.2.1.zip')
https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/
Soil Moisture Sensor
https://www.ebay.co.uk/itm/5pcs-Soil-Moisture-Hygrometer-Module-for-Moisture-Arduino-Wire-Water-Sensor-S5V1
Soil Moisture Sensor - tutorial - code
https://www.instructables.com/id/Arduino-Soil-Moisture-Sensor/
DHT11 humidity and temperature sensor (Te biblioteki umożliwiają podłaczenie tylko jednego sensora. Wersja bibliotek która umożliwia podłączenie większej liczby sensorów DHT11 na dole post'u.)
https://www.ebay.co.uk/itm/1X-DHT11-Temperature-and-Relative-Humidity-Sensor-Module-for-arduino-XB
DHT11 humidity and temperature sensor - tutorial - code
http://www.circuitbasics.com/how-to-set-up-the-dht11-humidity-sensor-on-an-arduino/
DHT11 - Library
http://www.circuitbasics.com/wp-content/uploads/2015/10/DHTLib.zip
Wersja na wyświetlacz 16x2 i 1 sensor DHT11:
Kod:
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <dht.h>
#define I2C_ADDR 0x27 // Define I2C Address using I2C scanner
#define BACKLIGHT_PIN 3 // Do not change these values for I2C Screen
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
dht DHT; // DHT Sensor
#define DHT11_PIN 6 // choose the input pin (for a DHT Sensor)
int n = 1;
int min = 300; // drowned in water
int max = 720; // dry soil
int Btn1Pin = 7; // choose the input pin (for a Button 1)
int Backlight = LOW; // variable for reading the backlight pin status (LED off)
int buttonState = LOW; // the current input for backlight (button not pressed)
int lastButtonState = HIGH; // the previous reading from the input pin (button)
int LED_backlight; // variable for LED_backlight button
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 10; // the debounce time; increase if the output flickers
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
void setup()
{
pinMode(Btn1Pin, INPUT); // declare Button 1 input
lcd.begin (16,2); // Set LCD to 16x2 characters
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); // Switch on the backlight
lcd.home (); // go home
lcd.setCursor ( 0, 0 ); // go to the column 1, line 1
lcd.print("a"); // Display "1"
lcd.setCursor ( 6, 0 ); // go to the column 7, line 1
lcd.print("b"); // Display "2"
lcd.setCursor ( 0, 1 ); // go to the column 1, line 2
lcd.print("c"); // Display "3"
lcd.setCursor ( 6, 1 ); // go to the column 7, line 2
lcd.print("d"); // Display "4"
}
void loop()
{
char percentage1a[80];
char percentage2a[80];
char percentage3a[80];
char percentage4a[80];
int chk = DHT.read11(DHT11_PIN); // declare DHT Sensor input
int sensor1Value = analogRead(A0); // declare Analog Sensor 1 input
int sensor2Value = analogRead(A1); // declare Analog Sensor 2 input
int sensor3Value = analogRead(A2); // declare Analog Sensor 3 input
int sensor4Value = analogRead(A3); // declare Analog Sensor 4 input
int percentage1 = map(sensor1Value, max, min, 0, 100);
sensor1Value = map(sensor1Value, 300, 720, min, max);
sprintf(percentage1a, "%02d", percentage1);
int percentage2 = map(sensor2Value, max, min, 0, 100);
sensor2Value = map(sensor2Value, 300, 720, min, max);
sprintf(percentage2a, "%02d", percentage2);
int percentage3 = map(sensor3Value, max, min, 0, 100);
sensor3Value = map(sensor3Value, 300, 720, min, max);
sprintf(percentage3a, "%02d", percentage3);
int percentage4 = map(sensor4Value, max, min, 0, 100);
sensor4Value = map(sensor4Value, 300, 720, min, max);
sprintf(percentage4a, "%02d", percentage4);
// float percentage = (sensorValue - max)/(min - max);
// double temperature = (double) tempData * (5/10.24);
// float percentage = (float)((sensorValue - min) * 100) / (max - min)
// sensorValue = map(sensorValue, 0, 1023, min, max);
// float percentage = map(sensorValue, max, min, 0, 100);
LED_backlight = digitalRead(Btn1Pin); // if LED On/Off button is pressed perform action
// if (buttonState != lastButtonState) {
// buttonState = lastButtonState;
// if (buttonState == HIGH) {
// Backlight = !Backlight;
// lcd.setBacklight(Backlight);
// }
// }
if (LED_backlight != lastButtonState) {
lastDebounceTime = millis();
lastButtonState = LED_backlight;
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (buttonState != lastButtonState) {
buttonState = lastButtonState;
if (buttonState == HIGH) {
Backlight = !Backlight;
lcd.setBacklight(Backlight);
}
}
}
lcd.setCursor ( 1, 0 ); // go to the column 2, line 1
lcd.print(percentage1a); // Display Sensor 1 Value
if (sensor1Value > 400 && sensor1Value < 550) // Check if the Value is higher than 300 or lower than 400
{
lcd.setCursor ( 3, 0 ); // go to the column 5, line 1
lcd.print("%N"); // Display letter "N" - Neutral moisture
} else if (sensor1Value >= 550) {
lcd.setCursor ( 3, 0 ); // go to the column 5, line 1
lcd.print("%L"); // Display letter "L" - Low moisture
} else if (sensor1Value <= 400) {
lcd.setCursor ( 3, 0 ); // go to the column 5, line 1
lcd.print("%H"); // Display letter "H" - High moisture
}
lcd.setCursor ( 7, 0 );
lcd.print(percentage2a);
if (sensor2Value > 400 && sensor2Value < 550)
{
lcd.setCursor ( 9, 0 );
lcd.print("%N");
} else if (sensor2Value >= 550) {
lcd.setCursor ( 9, 0 );
lcd.print("%L");
} else if (sensor2Value <= 400) {
lcd.setCursor ( 9, 0 );
lcd.print("%H");
}
lcd.setCursor ( 1, 1 );
lcd.print(percentage3a);
if (sensor3Value > 400 && sensor3Value < 550)
{
lcd.setCursor ( 3, 1 );
lcd.print("%N");
} else if (sensor3Value >= 550) {
lcd.setCursor ( 3, 1 );
lcd.print("%L");
} else if (sensor3Value <= 400) {
lcd.setCursor ( 3, 1 );
lcd.print("%H");
}
lcd.setCursor ( 7, 1 );
lcd.print(percentage4a);
if (sensor4Value > 400 && sensor4Value < 550)
{
lcd.setCursor ( 9, 1 );
lcd.print("%N");
} else if (sensor4Value >= 500) {
lcd.setCursor ( 9, 1 );
lcd.print("%L");
} else if (sensor4Value <= 500) {
lcd.setCursor ( 9, 1 );
lcd.print("%H");
}
lcd.setCursor ( 13, 0 ); // go to the column 14, line 1
lcd.print(DHT.temperature); // Display DHT Sensor Temperature
lcd.setCursor ( 15, 0 ); // go to the column 16, line 1
lcd.print("C"); // Display letter "C"
lcd.setCursor ( 13, 1 ); // go to the column 14, line 2
lcd.print(DHT.humidity); // Display DHT Sensor Humidity
lcd.setCursor ( 15, 1 ); // go to the column 16, line 2
lcd.print("%"); // Display symbol "%"
delay(1000);
}
Wersja na wyświetlacz 20x4. Uzyłem innych bibliotek.
LCD I2C 20x4 Display - Library (uzyte biblioteki do wyswietlacza 20x4 'Newliquidcrystal_1.3.5.zip')
https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/
DHT11 - tutorial (Wersja bibliotek dla wiecej niż jednego sensora DHT11.)
https://learn.adafruit.com/dht/overview
DHT11 - Library
https://github.com/adafruit/DHT-sensor-library
Adadruit Sensor - Error przy kompilowaniu programu 'Missing file Adafruit_Sensor.h'. Dodaj do folderu "DHT-sensor-library-master"
https://github.com/adafruit/Adafruit_Sensor
Wersja na wyświetlacz 20x4 i 2 sensory DHT11:
Kod:
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#define I2C_ADDR 0x27 // Define I2C Address using I2C scanner
#define BACKLIGHT_PIN 3 // Do not change these values for I2C Screen
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
#define DHTPIN1 6 // what digital pin we're connected to
#define DHTPIN2 7 // what digital pin we're connected to
#define DHTTYPE DHT11 // DHT 11
DHT dht1(DHTPIN1, DHTTYPE); // DHT Sensor 1
DHT dht2(DHTPIN2, DHTTYPE); // DHT Sensor 2
char buff_h1[2];
char buff_t1[2];
char buff_h2[2];
char buff_t2[2];
String h1_string;
String t1_string;
String h2_string;
String t2_string;
String dht_string;
int n = 1;
int min = 280; // drowned in water
int max = 720; // dry soil
int Btn1Pin = 7; // choose the input pin (for a Button 1)
int Backlight = LOW; // variable for reading the backlight pin status (LED off)
int buttonState = LOW; // the current input for backlight (button not pressed)
int lastButtonState = HIGH; // the previous reading from the input pin (button)
int LED_backlight; // variable for LED_backlight button
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 10; // the debounce time; increase if the output flickers
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
void setup()
{
Serial.begin(9600);
pinMode(Btn1Pin, INPUT); // declare Button 1 input
lcd.begin (20,4); // Set LCD to 16x2 characters
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); // Switch on the backlight
lcd.home (); // go home
lcd.setCursor ( 0, 0 ); // go to the column 1, line 1
lcd.print("WW:"); // Display "1"
lcd.setCursor ( 0, 1 ); // go to the column 1, line 2
lcd.print("SS:"); // Display "2"
lcd.setCursor ( 0, 2 ); // go to the column 1, line 3
lcd.print("CB:"); // Display "3"
lcd.setCursor ( 0, 3 ); // go to the column 1, line 4
lcd.print("SQ:"); // Display "4"
}
void loop()
{
char percentage1a[80];
char percentage2a[80];
char percentage3a[80];
char percentage4a[80];
int sensor1Value = analogRead(A0); // declare Analog Sensor 1 input
int sensor2Value = analogRead(A1); // declare Analog Sensor 2 input
int sensor3Value = analogRead(A2); // declare Analog Sensor 3 input
int sensor4Value = analogRead(A3); // declare Analog Sensor 4 input
int percentage1 = map(sensor1Value, max, min, 0, 100);
sprintf(percentage1a, "%02d", percentage1);
int percentage2 = map(sensor2Value, max, min, 0, 100);
sprintf(percentage2a, "%02d", percentage2);
int percentage3 = map(sensor3Value, max, min, 0, 100);
sprintf(percentage3a, "%02d", percentage3);
int percentage4 = constrain(percentage4, max, min);
percentage4 = map(sensor4Value, max, min, 0, 100);
sprintf(percentage4a, "%02d", percentage4);
LED_backlight = digitalRead(Btn1Pin); // if LED On/Off button is pressed perform action
if (LED_backlight != lastButtonState) {
lastDebounceTime = millis();
lastButtonState = LED_backlight;
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (buttonState != lastButtonState) {
buttonState = lastButtonState;
if (buttonState == HIGH) {
Backlight = !Backlight;
lcd.setBacklight(Backlight);
}
}
}
lcd.setCursor ( 4, 0 ); // go to the column 2, line 1
lcd.print(percentage1a); // Display Sensor 1 Value
if (sensor1Value > 400 && sensor1Value < 550) // Check if the Value is higher than 300 or lower than 400
{
lcd.setCursor ( 6, 0 ); // go to the column 5, line 1
lcd.print("% Normal"); // Display letter "N" - Neutral moisture
} else if (sensor1Value >= 550) {
lcd.setCursor ( 6, 0 ); // go to the column 5, line 1
lcd.print("% Low "); // Display letter "L" - Low moisture
} else if (sensor1Value <= 400) {
lcd.setCursor ( 6, 0 ); // go to the column 5, line 1
lcd.print("% High "); // Display letter "H" - High moisture
}
lcd.setCursor ( 4, 1 );
lcd.print(percentage2a);
if (sensor2Value > 400 && sensor2Value < 550)
{
lcd.setCursor ( 6, 1 );
lcd.print("% Normal");
} else if (sensor2Value >= 550) {
lcd.setCursor ( 6, 1 );
lcd.print("% Low ");
} else if (sensor2Value <= 400) {
lcd.setCursor ( 6, 1 );
lcd.print("% High ");
}
lcd.setCursor ( 4, 2 );
lcd.print(percentage3a);
if (sensor3Value > 400 && sensor3Value < 550)
{
lcd.setCursor ( 6, 2 );
lcd.print("% Normal");
} else if (sensor3Value >= 550) {
lcd.setCursor ( 6, 2 );
lcd.print("% Low ");
} else if (sensor3Value <= 400) {
lcd.setCursor ( 6, 2 );
lcd.print("% High ");
}
lcd.setCursor ( 4, 3 );
lcd.print(percentage4a);
if (sensor4Value > 400 && sensor4Value < 550)
{
lcd.setCursor ( 6, 3 );
lcd.print("% Normal");
} else if (sensor4Value >= 550) {
lcd.setCursor ( 6, 3 );
lcd.print("% Low ");
} else if (sensor4Value <= 400) {
lcd.setCursor ( 6, 3 );
lcd.print("% High ");
}
int t1 = dht1.readTemperature();
int h1 = dht1.readHumidity();
lcd.setCursor ( 15, 0 ); // go to the column 16, line 1
lcd.print("T:");
lcd.setCursor ( 17, 0 ); // go to the column 14, line 1
lcd.print(round(t1)); // Display DHT Sensor Temperature
lcd.setCursor ( 19, 0 ); // go to the column 16, line 1
lcd.print("C"); // Display letter "C"
lcd.setCursor ( 15, 1 ); // go to the column 16, line 1
lcd.print("H:");
lcd.setCursor ( 17, 1 ); // go to the column 14, line 2
lcd.print(round(h1)); // Display DHT Sensor Humidity
lcd.setCursor ( 19, 1 ); // go to the column 16, line 2
lcd.print("%"); // Display symbol "%"
int t2 = dht2.readTemperature();
int h2 = dht2.readHumidity();
lcd.setCursor ( 15, 2 ); // go to the column 16, line 1
lcd.print("T:");
lcd.setCursor ( 17, 2 ); // go to the column 14, line 1
lcd.print(round(t2)); // Display DHT Sensor Temperature
lcd.setCursor ( 19, 2 ); // go to the column 16, line 1
lcd.print("C"); // Display letter "C"
lcd.setCursor ( 15, 3 ); // go to the column 16, line 1
lcd.print("H:");
lcd.setCursor ( 17, 3 ); // go to the column 14, line 2
lcd.print(round(h2)); // Display DHT Sensor Humidity
lcd.setCursor ( 19, 3 ); // go to the column 16, line 2
lcd.print("%"); // Display symbol "%"
delay(1000);
}
Ostatnia edycja: