Gil H Arch
Create Your First Project
Start adding your projects to your portfolio. Click on "Manage Projects" to get started
Final assignment
A hygrometer, which will measure the moisture level in the plant for you.
There are 3 modes: dry, humid and wet
When the soil is dry, a sound will be heard, the light will turn red.
When the soil is moist, the light will turn green.
And when the ground is wet, the light will be blue.
In each of the situations, a message will appear on the screen
CODE:
const int Rpin = 11; // הפין אליו יש לחבר את הנורה האדומה
const int Gpin = 10; // הפין אליו יש לחבר את הנורה הירוקה
const int Bpin = 9; // הפין אליו יש לחבר את הנורה הכחולה
const int POWER_PIN = 7; // ּ+ הפין אליו יש לחבר את הסנסור לחות- חיבור המסומן ב
const int SIGNAL_PIN = A2; // S הפין אליו יש לחבר את הסנסור לחות- חיבור המסומן ב
int piezoPin = 8; // הפין אליו יש לחבר את הפיצו- אחראי על הרמקול
int value = 0; // ערך סנסור הלחות
#include <LiquidCrystal_I2C.h> // קריאה לספרייה ובה פקודות של סנסור הלחות
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(POWER_PIN, OUTPUT); // הגדרת סנסור הלחות כפלט
digitalWrite(POWER_PIN, LOW); // כיבוי הסנסור
pinMode(Rpin,OUTPUT); // הגדרת הנורה האדומה כפלט
pinMode(Gpin,OUTPUT); // הגדרת הנורה הירוקה כפלט
pinMode(Bpin,OUTPUT); // הגדרת הנורה הכחולה כפלט
lcd.init(); // אתחול הלד
lcd.backlight();
}
void loop() {
// put your main code here, to run repeatedly:ת
digitalWrite(POWER_PIN, HIGH); // הפעלת הסנסור לחות
delay(10); // חכה 10 מילישניות
value = analogRead(SIGNAL_PIN); // תקרא את הערכים מהסנסור
digitalWrite(POWER_PIN, LOW); // כבה את הסנסור
Serial.print("Sensor value: ");
Serial.println(value); // הצג את ערך הסנסור
delay(1000);
if (value <= 50) { // אם ערך הסנסור קטן או שווה ל50
analogWrite(Rpin, 255); // הדלק את הנורה האדומה בערך 255
analogWrite(Gpin, 0); // השאר את הנורה הירוקה בערך 0 (כבויה)
analogWrite(Bpin, 0); // השאר את הנורה הירוקה בערך 0 (כבויה)
delay(1); // חכה שנייה
lcd.clear(); // נקה מסך
lcd.setCursor(0, 0); // התביית על אזור 0,0 במסך
lcd.print("I'm thirsty"); // כתוב את ההודעה באזור 0,0 במסך
//lcd.setCursor(2, 1); // עבור לאזור 2,1 במסך
//lcd.print("GetStarted.com"); // כתוב את ההודעה באזור 2,1 במסך
delay(1);
tone(piezoPin, 3000, 500); // הפעל את הרמקול בעוצמה מסוימת ובתדר מסוים
delay(500);
tone(piezoPin, 2000, 500);
delay(500);
tone(piezoPin, 3000, 500);
delay(500);
tone(piezoPin, 2000, 500);
delay(500);
}
else if (value < 350){
analogWrite(Rpin, 0);
analogWrite(Gpin, 255);
analogWrite(Bpin, 0);
delay(1);
lcd.clear(); // clear display
lcd.setCursor(0, 0); // move cursor to (0, 0)
lcd.print("Keep an eye"); // print message at (0, 0)
lcd.setCursor(2, 1); // move cursor to (2, 1)
lcd.print("on my"); // print message at (2, 1)
delay(1);
}
else {
analogWrite(Rpin, 0);
analogWrite(Gpin, 0);
analogWrite(Bpin, 255);
delay(1);
lcd.clear(); // clear display
lcd.setCursor(0, 0); // move cursor to (0, 0)
lcd.print("yay I love water"); // print message at (0, 0)
//lcd.setCursor(2, 1); // move cursor to (2, 1)
//lcd.print("GetStarted.com"); // print message at (2, 1)
delay(1);
}
}










