Sketch Arduino (Sketch_feb21a.ino)
1. Sketch Arduino (Sketch_feb21a.ino)
char c; //Part DHT11 #include <dht.h> const int PIN_SENSOR = 7; dht DHT; //Part Relay #define R1 A0 // Connect PIN Analog 0 #define R2 A1 // Connect PIN Analog 1 //Part Ethernet Shield #include <SPI.h> #include <Ethernet.h> EthernetClient client; byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192, 168, 1, 177); char server[] = "192.168.1.178"; //Part Servo #include <Servo.h> Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards int pos = 0; // variable to store the servo position int k= 0 ; //Part RTC #include <Wire.h> #include "RTClib.h" RTC_Millis rtc;
void setup() { Serial.begin(9600); Serial.println("### GARAGELAB ###");
//Setup Eth Ethernet.begin(mac,ip); //Setup Servo myservo.attach(9); // attaches the servo on pin 9 to the servo object myservo.write(0); //Setup RTC rtc.begin(DateTime(F(__DATE__), F(__TIME__))); // This line sets the RTC with an explicit date & time, for example to set rtc.adjust(DateTime(2017, 2, 20, 13, 00, 30)); // January 21, 2014 at 3am you would call: //Setup Relay pinMode(R1, OUTPUT); pinMode(R2, OUTPUT);
void loop() { // DHT11 Send Data DHT.read11(PIN_SENSOR);
Serial.print("Temperature = ");
Serial.print(DHT.temperature); Serial.println(" *C");
if (client.connect(server, 80)) { client.print("GET /ardhengki/insert.php?"); //client.print( "GET /diplomna/Arduino/add_data.php?"); client.print("suhu="); client.println(DHT.temperature);
client.println( "HTTP/1.1"); client.println( "Connection: close" ); client.stop(); Serial.println("SEND"); delay (1000);
} else {
// you didn’t get a connection to the server: Serial.println(" –> SEND failed/n"); }
//Serial C Variable if (Serial.available() > 0) {
c = Serial.read(); Serial.println(c); }else {
delay(100); }
// SetPoint Puyuh if (c=='n'){ Serial.println("SetPoint Puyuh"); if (DHT.temperature <=38)
{digitalWrite(R2, HIGH); digitalWrite(R1, LOW); } else {digitalWrite(R2, LOW); }
if (DHT.temperature >=39) {digitalWrite(R2, LOW); digitalWrite(R1, HIGH); } else {digitalWrite(R1, LOW); }
// SetPoint Ayam if (c=='f'){ Serial.println("SetPoint Ayam");
if (DHT.temperature <=38) {digitalWrite(R2, HIGH); digitalWrite(R1, LOW); } else {digitalWrite(R2, LOW); } if (DHT.temperature <=38) {digitalWrite(R2, HIGH); digitalWrite(R1, LOW); } else {digitalWrite(R2, LOW); }
//RTC Combine Servo DateTime now = rtc.now();
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();
if (now.day() >= 20) { if(now.minute()==1){ for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees { // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } }
if(now.minute()==3){ for(pos = 180; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees { myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } } if(now.minute()==5){ for(pos = 0; pos <= 180; pos += 1) // goes from 180 degrees to 0 degrees { myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } } if(now.minute()>5){
(now.minute()==k); } } c='0'; }