39
LAMPIRAN
SOURCE CODE PROGRAM
Program Keseluruhan
#include <SPI.h> #include <Ethernet.h>// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// if you don't want to use DNS (and reduce your sketch size) // use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
char server[] = "www.donijadisatu.96.lt"; // name address for Google (using DNS)
// Set the static IP address to use if the DHCP fails to assign IPAddress ip(192, 168, 0, 177);
// Initialize the Ethernet client library // with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP): EthernetClient client;
int val;
int tempPin = 1; float mv;
float cel;
void setup() { pinMode(6,OUTPUT);
pinMode(3,INPUT_PULLUP); pinMode(A1,INPUT);
// Open serial communications and wait for port to open: Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// start the Ethernet connection: if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP"); // try to congifure using IP address instead of DHCP: Ethernet.begin(mac, ip);
}
// give the Ethernet shield a second to initialize: delay(1000);
Serial.println("connecting..."); }
void sensor(){
val = analogRead(tempPin); mv = ( val/1024.0)*5000;
A-1
40
cel = mv/10; }
void loop() { sensor();
// Pemadaman api bila suhu melebihi 33 derajat selsius if(cel>33){
digitalWrite(6,HIGH); delay(3000);
}
else if(cel<32){ digitalWrite(6,LOW); delay(100);
}
//Pengiriman data pembacaan suhu ke Internet String cari,http,gabung1,gabung2;
cari="POST /update.php/?value="; http=" HTTP/1.1";
gabung1=cari+cel; gabung2=gabung1+http; Serial.println(gabung2);
if (client.connect(server, 80)) { Serial.println("connected"); // Make a HTTP request:
// client.println("POST /update.php/?value=cantik HTTP/1.1"); client.println(gabung2);
client.println("Host: www.donijadisatu.96.lt"); client.println("Connection: close");
client.println(); } else {
// if you didn't get a connection to the server: Serial.println("connection failed");
}
client.stop(); }
Uji Sensor LM35
void setup() {
// put your setup code here, to run once:
pinMode(A0, INPUT);
Serial.begin(9600);
}
float mv, cel, nilai;
A-2
41
int tempPin = 0;
void loop() {
nilai = analogRead(tempPin);
mv = ( nilai/1024.0)*5000;
cel = mv / 10;
Serial.print("Celsius: ");
Serial.print(cel);
Serial.print(" || ADC: ");
Serial.println(nilai);
delay(3000);
A-3