ความรู้แน่น ฟรีสำหรับชุมชน ArduinoAll ที่นี่เท่านั้น

ฟรีและดีที่สุด คอร์สอบรม Arduino + NodeMCU
ทำเพื่อแบ่งปัน ห้ามนำไปจำหน่าย หรือเก็บเงินค่าเรียน
  !!!


  


AllNewStep รับประกันคุณภาพทุกชิ้น วันจันทร์-ศุกร์แจ้งชำระสินค้าก่อน 14.00 จัดส่งทันทีวันนี้ค่ะ

กรุงเทพ /ภาคกลาง ได้พรุ่งนี้


*** สินค้าทุกชิ้น ถ้าสามารถทำรายการสั่งซื้อได้ แสดงว่ามีครบทุกรายการค่ะ *** 

พิมพ์ค้นหาบทความ หัวข้อกระทู้ และสินค้าในเว็บ AllNewStep ได้ที่นี่
QUOTE 

RTC DS1307 !!

net

คือผมจะตั้งเวลา โดยใช้สวิตต่อออกมาครับ นี้คือโค้ดที่ได้เขียนทั้งหมด

 

#include "DHT.h"

#include <Wire.h> 

#include "RTClib.h"

 

 

 

#include <LiquidCrystal_I2C.h> //ประกาศ Library ของจอ I2C

// Set the LCD address to 0x27 for a 16 chars and 2 line display

LiquidCrystal_I2C lcd(0x3F, 20, 4);

#define DHTPIN 2 // what pin we're connected to

 

// Uncomment whatever type you're using!

#define DHTTYPE DHT11 // DHT 11 

//#define DHTTYPE DHT22 // DHT 22 (AM2302)

//#define DHTTYPE DHT21 // DHT 21 (AM2301)

 

// Connect pin 1 (on the left) of the sensor to +5V

// Connect pin 2 of the sensor to whatever your DHTPIN is

// Connect pin 4 (on the right) of the sensor to GROUND

// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

 

DHT dht(DHTPIN, DHTTYPE);

 

RTC_DS1307 RTC;

 

#define speed1 4   

#define speed2 5  

#define speed3 6

#define motor  7

void setup() {

  pinMode(speed1, OUTPUT);

  pinMode(speed2, OUTPUT);

  pinMode(speed3, OUTPUT);

  pinMode(motor, OUTPUT);

  lcd.begin();

// Print a message to the LCD.

//lcd.print("%"); //ฟังก์ชั่นในการกำหนดข้อความที่ต้องการแสดงผล

lcd.setCursor(0, 1); //ฟังก์ชั่นในการกำหนดตำแหน่ง Cursor

//lcd.print("c");

Serial.begin(9600); 

Serial.println("DHTxx test!");

 

dht.begin();

 Serial.begin(9600);

    Wire.begin();

   

    RTC.begin();

    //RTC.adjust(DateTime(__DATE__, __TIME__));

 

  if (! RTC.isrunning()) {

    Serial.println("RTC is NOT running!");

    // following line sets the RTC to the date & time this sketch was compiled

    //RTC.adjust(DateTime(__DATE__, __TIME__));

}

}

 

void loop() {

 

// Reading temperature or humidity takes about 250 milliseconds!

// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)

   float h = dht.readHumidity();

   float t = dht.readTemperature();

   

// check if returns are valid, if they are NaN (not a number) then something went wrong!

if (isnan(t) || isnan(h)) {

    Serial.println("Failed to read from DHT");

  } else {

    Serial.print("Humidity: "); 

    Serial.print(h);

    Serial.print(" %\t");

    Serial.print("Temperature: "); 

    Serial.print(t);

    Serial.println(" *C");

  lcd.setCursor(0, 0); //ฟังก์ชั่นในการกำหนดตำแหน่ง Cursor

lcd.print((float)h);lcd.print("\%");

  lcd.setCursor(0, 1); //ฟังก์ชั่นในการกำหนดตำแหน่ง Cursor

lcd.print((float)t);lcd.print("\c");

lcd.setCursor(1, 0); //ฟังก์ชั่นในการกำหนดตำแหน่ง Cursor

 

 DateTime now = RTC.now();

 int Y = now.year();

  int M =now.month();

   int d =now.day();

    int H =now.hour();

      int m =now.minute();

      int s =now.second();

 

    Serial.print(now.year(), DEC);

    Serial.print('/');

    Serial.print(now.month(), DEC);

    Serial.print('/');

    Serial.print(now.day(), DEC);

    Serial.print(' ');

    Serial.print(now.hour(), DEC);

    Serial.print(':');

    Serial.print(now.minute(), DEC);

    Serial.print(':');

    Serial.print(now.second(), DEC);

    Serial.println();

 

    Serial.print(" since 1970 = ");

    Serial.print(now.unixtime());

    Serial.print("s = ");

    Serial.print(now.unixtime() / 86400L);

    Serial.println("d");

 

    // calculate a date which is 7 days and 30 seconds into the future

    DateTime future (now.unixtime() + 7 * 86400L + 30);

 

    Serial.print(" now + 7d + 30s: ");

    Serial.print(future.year(), DEC);

    Serial.print('/');

    Serial.print(future.month(), DEC);

    Serial.print('/');

    Serial.print(future.day(), DEC);

    Serial.print(' ');

    Serial.print(future.hour(), DEC);

    Serial.print(':');

    Serial.print(future.minute(), DEC);

    Serial.print(':');

    Serial.print(future.second(), DEC);

    Serial.println();

 

    Serial.println();

    delay(100);

 lcd.setCursor(6,2); //ฟังก์ชั่นในการกำหนดตำแหน่ง Cursor

lcd.print(Y);lcd.print(" "); //แสดงปีออกทางหน้าจอ

 lcd.setCursor(4,2); //ฟังก์ชั่นในการกำหนดตำแหน่ง Cursor

lcd.print(M);lcd.print("/"); //แสดงเดือนออกทางหน้าจอ

lcd.setCursor(1,2); //ฟังก์ชั่นในการกำหนดตำแหน่ง Cursor

lcd.print(d);lcd.print("/"); //แสดงวันออกทางหน้าจอ

lcd.setCursor(0,3); //ฟังก์ชั่นในการกำหนดตำแหน่ง Cursor

lcd.print(H);lcd.print(":"); //แสดงชั่วโมงออกทางหน้าจอ

lcd.setCursor(3,3); //ฟังก์ชั่นในการกำหนดตำแหน่ง Cursor

lcd.print(m);lcd.print(":"); //แสดงนาทีออกทางหน้าจอ

lcd.setCursor(6,3); //ฟังก์ชั่นในการกำหนดตำแหน่ง Cursor

lcd.print(s);lcd.print(" "); //แสดงวินาที

//ส่วนด้านล่างจะทำหน้าที่ขับพัดลมให้ออกแต่ละเกียร์

 digitalWrite(speed1, 0); 

 digitalWrite(speed2, 0);

 digitalWrite(speed3, 0);

 digitalWrite(motor,  0);

 

 if(t > 33)

{ digitalWrite(speed1, 0); 

  digitalWrite(speed2, 0);

  digitalWrite(speed3, 1);

  digitalWrite(motor,  1);

   lcd.setCursor(8,1); //ฟังก์ชั่นในการกำหนดตำแหน่ง Cursor

lcd.print("speed3&Water");

  }

else if(t > 32)

{ digitalWrite(speed1, 0); 

  digitalWrite(speed2, 0);

  digitalWrite(speed3, 1);

  digitalWrite(motor,  0);

   lcd.setCursor(8,1); //ฟังก์ชั่นในการกำหนดตำแหน่ง Cursor

lcd.print("speed3");

  }

else if(t > 23)

{ digitalWrite(speed1, 0); 

  digitalWrite(speed2, 1);

  digitalWrite(speed3, 0);

  digitalWrite(motor,  0);

   lcd.setCursor(8,1); //ฟังก์ชั่นในการกำหนดตำแหน่ง Cursor

lcd.print("speed2");

}

 

else if(t > 22)

{ digitalWrite(speed1, 1); 

  digitalWrite(speed2, 0);

  digitalWrite(speed3, 0);

  digitalWrite(motor,  0);

  lcd.setCursor(8,1); //ฟังก์ชั่นในการกำหนดตำแหน่ง Cursor

lcd.print("speed1");

}

 

//อยากจะมีสวิตตั้งเวลาเปิด-ปิด จะได้ไม่ต้องมาพิมโปรแกรมแล้วเบิร์นตลอดเวลาต้องทำไงครับ

 

  

  }

}

QUOTE 
ความคิดเห็นที่ #1
เจ้าของร้าน

ทำได้ครับ เขียนโปรแกรมรับค่าจากสวิตช์ แล้วเซฟการตั้งค่าไว้ที่ eeprom ของ Arduino

ตามตัวอย่างนี้ครับ https://www.arduino.cc/en/Reference/EEPROM

 

แสดงความคิดเห็นที่ 1-1 จากทั้งหมด 1 ความคิดเห็น
ขาย ARDUINO
คุณภาพ อันดับ 1

ได้รับรางวัลร้านยอดเยี่ยม
ตั้งแต่ปี 2558
ขาย Arduino
วีดีโอสอน Arduino

สอน esp8266

สอน Arduino IoT
สอน Arduino แบบเร็ว

สอน NodeMCU

อุปกรณ์ Arduino

MEMBER ZONE

พูดคุย-สอบถาม