kalymnos_stem
Κυριακή 30 Μαρτίου 2025
Κυριακή 23 Μαρτίου 2025
servo and led
// C++ code
//
#include <Servo.h>
int angle = 0;
int i = 0;
Servo servo_9;
void setup()
{
pinMode(5, OUTPUT);
servo_9.attach(9, 500, 2500);
pinMode(4, OUTPUT);
angle = 0;
}
void loop()
{
while (angle < 180) {
angle += 1;
digitalWrite(5, HIGH);
servo_9.write(angle);
}
delay(2000); // Wait for 2000 millisecond(s)
if (angle == 180) {
digitalWrite(5, LOW);
}
while (angle > 0) {
angle += -1;
digitalWrite(4, HIGH);
servo_9.write(angle);
}
delay(2000); // Wait for 2000 millisecond(s)
digitalWrite(4, LOW);
}
Σάββατο 15 Μαρτίου 2025
ldr and lcd
Δευτέρα 3 Μαρτίου 2025
Κυριακή 16 Φεβρουαρίου 2025
LCD οθόνη και arduino
// C++ code
//
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd_2(39, 16, 2);
void setup()
{
lcd_2.init();
lcd_2.clear();
}
void loop()
{
lcd_2.setCursor(0, 0);
lcd_2.print("hello world");
delay(1000); // Wait for 1000 millisecond(s)
lcd_2.setCursor(0, 1);
lcd_2.print("Are you Ok ?");
}
χρήσιμες εντολές για την οθόνη:
include <LiquidCrystal.h> καλούμε τη βιβλιοθήκη για την οθόνη που θα πρέπει να έχουμε κατεβάσει-εγκαταστήσει
lcd.scrollDisplayRight();
lcd.scrollDisplayLeft();
Με τις εντολές αυτές μπορούμε να έχουμε κινούμενο κείμενο προς την κατεύθυνση της εντολής
Σάββατο 8 Φεβρουαρίου 2025
watering plants and screen
κώδικας για ρύθμιση
/* Change these values based on your calibration values */
#define soilWet 500 // Define max value we consider soil 'wet'
#define soilDry 750 // Define min value we consider soil 'dry'
// Sensor pins
#define sensorPower 7
#define sensorPin A0
void setup() {
pinMode(sensorPower, OUTPUT);
// Initially keep the sensor OFF
digitalWrite(sensorPower, LOW);
Serial.begin(9600);
}
void loop() {
//get the reading from the function below and print it
int moisture = readSensor();
Serial.print("Analog Output: ");
Serial.println(moisture);
// Determine status of our soil
if (moisture < soilWet) {
Serial.println("Status: Soil is too wet");
} else if (moisture >= soilWet && moisture < soilDry) {
Serial.println("Status: Soil moisture is perfect");
} else {
Serial.println("Status: Soil is too dry - time to water!");
}
delay(1000); // Take a reading every second for testing
// Normally you should take reading perhaps once or twice a day
Serial.println();
}
// This function returns the analog soil moisture measurement
int readSensor() {
digitalWrite(sensorPower, HIGH); // Turn the sensor ON
delay(10); // Allow power to settle
int val = analogRead(sensorPin); // Read the analog value form sensor
digitalWrite(sensorPower, LOW); // Turn the sensor OFF
return val; // Return analog moisture value
}
κώδικας με LCD οθόνη:
#include <Wire.h>#include <LiquidCrystal_I2C.h>LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display/* Change these values based on your calibration values */#define soilWet 500 // Define max value we consider soil 'wet'#define soilDry 750 // Define min value we consider soil 'dry'// Sensor pins#define sensorPower 7#define sensorPin A0void setup() {pinMode(sensorPower, OUTPUT);lcd.init(); // initialize the lcd// Print a message to the LCD.lcd.backlight();// Initially keep the sensor OFFdigitalWrite(sensorPower, LOW);Serial.begin(9600);}void loop() {int moisture = readSensor(); //get the reading from the function below and print itSerial.print("Analog Output: ");Serial.println(moisture);lcd.setCursor(3,0);lcd.print(moisture);delay(1000);// Determine status of our soilif (moisture < soilWet) {Serial.println("Status: Soil is too wet");lcd.setCursor(1,0);lcd.print("Soil is too wet");} else if (moisture >= soilWet && moisture < soilDry) {Serial.println("Status: Soil moisture is perfect");lcd.setCursor(1,0);lcd.print("Soil moisture is perfect");} else {Serial.println("Status: Soil is too dry - time to water!");lcd.setCursor(1,0);lcd.print("Soil is too dry");lcd.setCursor(1,1);lcd.print("time to water!");}delay(1000); // Take a reading every second for testing// Normally you should take reading perhaps once or twice a daySerial.println();lcd.clear();}// This function returns the analog soil moisture measurementint readSensor() {digitalWrite(sensorPower, HIGH); // Turn the sensor ONdelay(10); // Allow power to settleint val = analogRead(sensorPin); // Read the analog value form sensordigitalWrite(sensorPower, LOW); // Turn the sensor OFFreturn val; // Return analog moisture value}