diff --git a/src/_7-segment/_7-segment.ino b/src/_7-segment/_7-segment.ino new file mode 100644 index 0000000000000000000000000000000000000000..38022bddf395f331046e4a8205c4e47e02cc3aa4 --- /dev/null +++ b/src/_7-segment/_7-segment.ino @@ -0,0 +1,64 @@ +// pin 11 of 74HC595 (SHCP) +const int bit_clock_pin = 13; +// pin 12 of 74HC595 (STCP) +const int digit_clock_pin = 12; +// pin 14 of 74HC595 (DS) +const int data_pin = 11; + +// digit pattern for a 7-segment display +const byte digit_pattern[10] = +{ + B00111111, // 0 + B00000110, // 1 + B01011011, // 2 + B01001111, // 3 + B01100110, // 4 + B01101101, // 5 + B01111101, // 6 + B00000111, // 7 + B01111111, // 8 + B01101111, // 9 +}; + +unsigned int counter = 0; + +void setup() +{ + pinMode(data_pin, OUTPUT); + pinMode(bit_clock_pin, OUTPUT); + pinMode(digit_clock_pin, OUTPUT); +} + +void update_one_digit(int data) +{ + int i; + byte pattern; + + // get the digit pattern to be updated + pattern = digit_pattern[data]; + + // turn off the output of 74HC595 + digitalWrite(digit_clock_pin, LOW); + + // update data pattern to be outputed from 74HC595 + // because it's a common anode LED, the pattern needs to be inverted + shiftOut(data_pin, bit_clock_pin, MSBFIRST, ~pattern); + + // turn on the output of 74HC595 + digitalWrite(digit_clock_pin, HIGH); +} + +void loop() +{ + int i; + unsigned int digit_base; + + counter++; + + digit_base = 10; + + // get the value to be displayed and update one digit + update_one_digit(counter % digit_base); + + delay(500); +} diff --git a/src/coba/coba.ino b/src/coba/coba.ino new file mode 100644 index 0000000000000000000000000000000000000000..649113b00d45504a09654b95d9937f03849b6a3e --- /dev/null +++ b/src/coba/coba.ino @@ -0,0 +1,65 @@ + + +const int ledPin = 2; +const int buttonPin = 4; +int buttonState = 0; +int val = 0; +int soilPin = A0; +int soilPower = 7; +int statusLED = 0; +int buzzer = 9; +int buzzerHigh = false; +int sensorLDR = A1; +int valueLDR = 0; +int res0 = 10.0; + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + + pinMode(buttonPin, INPUT); + + pinMode(ledPin, OUTPUT); + pinMode(soilPower, OUTPUT); + pinMode(buzzer, OUTPUT); + digitalWrite(soilPower, LOW); +} + +void loop() { + // put your main code here, to run repeatedly: + buttonState = digitalRead(buttonPin); + + if(buttonState == HIGH) { + digitalWrite(buzzer, LOW); + Serial.println("botton clicked"); + } + + Serial.print("Soil Moisture = "); + Serial.println(readSoil()); + if (readSoil() > 50) { + Serial.println("wet soil"); + digitalWrite(ledPin, LOW); + } else { + Serial.println("dry soil"); + digitalWrite(ledPin, HIGH); + digitalWrite(buzzer, HIGH); + Serial.println("alarm on"); + } + + valueLDR = analogRead(sensorLDR); // read the value from the sensor + Serial.print("cahaya: "); //prints the values coming from the sensor on the screen + float vout0 = valueLDR*0.0048828125; // calculate the voltage + int lux0 = 500/(res0*((5-vout0)/vout0)); // calculate the Lux + Serial.println(lux0); +// delay(1000); //​take a reading every second +} + +int readSoil() { +// digitalWrite(soilPower, HIGH);​ //turn D7 "On" + digitalWrite(soilPower, HIGH); + delay(10); + val = analogRead(soilPin); + digitalWrite(soilPower, LOW); + return 1023-val; //send current moisture value +} + diff --git a/src/json_parser.cpp/json_parser.cpp.ino b/src/json_parser.cpp/json_parser.cpp.ino index 41fcb257686d8a58e0e8aeec73a027cd830d15ff..7a0e32cc230b395952d0aab3d5b97d22f8fcffe9 100644 --- a/src/json_parser.cpp/json_parser.cpp.ino +++ b/src/json_parser.cpp/json_parser.cpp.ino @@ -48,12 +48,13 @@ void ReadJson() { char* GenerateJSONString() { char buff[12]; char* totalString, ageText, humidityText, lightText, yearString, humidityString, lightString; - yearString = itoa(year,buff,10); - humidityString = itoa(humidity,buff,10); - lightString = itoa(light,buff,10); - ageText = "age : "; + //yearString = itoa(year,buff,10); + //humidityString = itoa(humidity,buff,10); + //lightString = "12"; + //lightString = itoa(light,buff,10); + //ageText = "age : "; - totalString = "|age : ", yearString, " humidity : ", humidityString, " light : ", lightString, "|"; + totalString = "|age : ";//, yearString, " humidity : ", humidityString, " light : ";//, lightString, "|"; return (totalString); } diff --git a/src/lcd/lcd.ino b/src/lcd/lcd.ino index ea5a7a062fea3149181b09437101b01e5dfd93a6..189e4dd804968970e2921262f3fb2dee25cac5d1 100644 --- a/src/lcd/lcd.ino +++ b/src/lcd/lcd.ino @@ -2,19 +2,19 @@ #include <LiquidCrystal_I2C.h> // Set the LCD address to 0x27 for a 16 chars and 2 line display -LiquidCrystal_I2C lcd(0x3F,16,2); +LiquidCrystal_I2C lcd(0x3F, 16, 2); void setup() { - // initialize the LCD - lcd.init(); + // initialize the LCD + lcd.init(); - // Turn on the blacklight and print a message. - lcd.backlight(); - lcd.print("Hello, world!"); + // Turn on the blacklight and print a message. + lcd.backlight(); + lcd.print("Hello, world!"); } void loop() { - // Do nothing here... -} + // Do nothing here... +} \ No newline at end of file diff --git a/src/lib/ArduinoJson-v5.13.1.zip b/src/lib/ArduinoJson-v5.13.1.zip new file mode 100644 index 0000000000000000000000000000000000000000..8c9425014653b5b93d8a96b0efea8ac28fb36068 Binary files /dev/null and b/src/lib/ArduinoJson-v5.13.1.zip differ diff --git a/src/main/main.ino b/src/main/main.ino index 249adb081a4dd6b74537d635c057ce2d7f3c307a..5182dc2452b6b8efd78158821ab8ad4e8a73cc66 100644 --- a/src/main/main.ino +++ b/src/main/main.ino @@ -1,3 +1,5 @@ +#include <HttpClient.h> + const int ledPin = 2; const int buttonPin = 4; int buttonState = 0; @@ -7,7 +9,10 @@ int soilPower = 7; int statusLED = 0; int buzzer = 9; int buzzerHigh = false; - +int sensorLDR = A1; +int valueLDR = 0; +int res0 = 10.0; + void setup() { // put your setup code here, to run once: Serial.begin(9600); @@ -40,7 +45,12 @@ void loop() { Serial.println("alarm on"); } -// delay(1000); //​take a reading every second + valueLDR = analogRead(sensorLDR); // read the value from the sensor + Serial.print("cahaya: "); //prints the values coming from the sensor on the screen + float vout0 = valueLDR*0.0048828125; // calculate the voltage + int lux0 = 500/(res0*((5-vout0)/vout0)); // calculate the Lux + Serial.println(lux0); + delay(1000); //​take a reading every second } int readSoil() { diff --git a/src/main_2/main_2.ino b/src/main_2/main_2.ino new file mode 100644 index 0000000000000000000000000000000000000000..2007a74de8c9ccc1154b28b90bf815e040e327d4 --- /dev/null +++ b/src/main_2/main_2.ino @@ -0,0 +1,151 @@ +#include <HttpClient.h> +#include <Wire.h> +#include <LiquidCrystal_I2C.h> + +const int ledPin = 2; +const int buttonPin = 4; +int buttonState = 0; +int val = 0; +int soilPin = A0; +int soilPower = 7; +int statusLED = 0; +int buzzer = 9; +int buzzerHigh = false; +int sensorLDR = A1; +int valueLDR = 0; +int res0 = 10.0; + +// Set the LCD address to 0x27 for a 16 chars and 2 line display +LiquidCrystal_I2C lcd(0x3F, 16, 2); + +// pin 11 of 74HC595 (SHCP) +const int bit_clock_pin = 13; +// pin 12 of 74HC595 (STCP) +const int digit_clock_pin = 12; +// pin 14 of 74HC595 (DS) +const int data_pin = 11; + +// digit pattern for a 7-segment display +const byte digit_pattern[10] = +{ + B00111111, // 0 + B00000110, // 1 + B01011011, // 2 + B01001111, // 3 + B01100110, // 4 + B01101101, // 5 + B01111101, // 6 + B00000111, // 7 + B01111111, // 8 + B01101111, // 9 +}; + +unsigned int counter = 0; + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + + pinMode(buttonPin, INPUT); + + pinMode(ledPin, OUTPUT); + pinMode(soilPower, OUTPUT); + pinMode(buzzer, OUTPUT); + digitalWrite(soilPower, LOW); + + pinMode(data_pin, OUTPUT); + pinMode(bit_clock_pin, OUTPUT); + pinMode(digit_clock_pin, OUTPUT); + + // initialize the LCD + lcd.init(); + + // Turn on the blacklight and print a message. + lcd.backlight(); +} + +void loop() { + + int i; + unsigned int digit_base; + + counter++; + + digit_base = 10; + + // get the value to be displayed and update one digit + update_one_digit(counter % digit_base); + + lcd.setCursor(0,0); + lcd.autoscroll(); + lcd.print("Hello! Welcome to GreenTyNo :)"); + delay(1000); + + + + // put your main code here, to run repeatedly: + buttonState = digitalRead(buttonPin); + + if(buttonState == HIGH) { + buzzerHigh = false; + } + + Serial.print("Soil Moisture = "); + Serial.println(readSoil()); + if (readSoil() > 60) { + Serial.println("wet soil"); + digitalWrite(ledPin, LOW); + } else { + Serial.println("dry soil"); + digitalWrite(ledPin, HIGH); +// digitalWrite(buzzer, HIGH); +// delay(200); +// digitalWrite(buzzer, LOW); +// delay(1000); + buzzerHigh = true; + Serial.println("alarm on"); + } + + if(buzzerHigh) { + digitalWrite(buzzer, HIGH); + delay(200); + digitalWrite(buzzer, LOW); + delay(1000); + } + + valueLDR = analogRead(sensorLDR); // read the value from the sensor + Serial.print("cahaya: "); //prints the values coming from the sensor on the screen + float vout0 = valueLDR*0.0048828125; // calculate the voltage + int lux0 = 500/(res0*((5-vout0)/vout0)); // calculate the Lux + Serial.println(lux0); +// delay(1000); //​take a reading every second +} + +int readSoil() { +// digitalWrite(soilPower, HIGH);​ //turn D7 "On" + digitalWrite(soilPower, HIGH); + delay(10); + val = analogRead(soilPin); + digitalWrite(soilPower, LOW); + return 1023-val; //send current moisture value +} + +void update_one_digit(int data) +{ + int i; + byte pattern; + + // get the digit pattern to be updated + pattern = digit_pattern[data]; + + // turn off the output of 74HC595 + digitalWrite(digit_clock_pin, LOW); + + // update data pattern to be outputed from 74HC595 + // because it's a common anode LED, the pattern needs to be inverted + shiftOut(data_pin, bit_clock_pin, MSBFIRST, ~pattern); + + // turn on the output of 74HC595 + digitalWrite(digit_clock_pin, HIGH); +} +