Modul RTC (Real Time Clock) menggunakan IC DS1307 mencatat Tanggal dan waktu (jam). RTC ini dapat digunakan pada Arduino atau ATMEGA 8/16/32 melalui komunikasi I2C
Aplikasi RTC pada arduino severino +LCD 16x2 sebagai calendar:
Diagram Koneksi RTC pada Arduino (Severino):
Agar program berfungsi , harus menggunakan librari RTClib.h yang dapat diunduh di Ladyada (modul kit RTC ini compatible dengan RTC produk Ladyada)
List Program untuk Test :
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
voidsetup () {
Serial.begin(57600);
Wire.begin();
RTC.begin();
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__));
}
}
voidloop () {
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();
Serial.print(" since midnight 1/1/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(3000);
}
Video ini memperlihatkan aplikasi Accelerometer ADXL345 untuk mengatur gerakan 2 buah servo motor (sumbu x dan sumbu y)
Schematic:
List Program
// ADXL345 control 2 Servo Motors// Modified by: Aan Darmawan// valfa.blogspot.com// June 2011//
#include <Wire.h>
#include <Servo.h>
Servo myservox; // servo for x axisServo myservoy; // servo for y axis
#define DEVICE (0x53) //ADXL345 device address
#define TO_READ (6) //num of bytes we are going to read each time (two bytes for each axis)
#define TRIGGER 16 // pin analog2 (16) connect to CS Adxl345, active highbyte buff[TO_READ] ; //6 bytes buffer for saving data read from the deviceint i;
voidsetup()
{
pinMode(TRIGGER,OUTPUT);
digitalWrite(TRIGGER,HIGH);
Wire.begin(); // join i2c bus (address optional for master)
myservox.attach(9); // attaches the servo on pin 9 to the servo object
myservoy.attach(10); // attaches the servo on pin 10 to the servo object
myservox.write(90); // tell servo x to go to position 90 degdelay(25); // makesure servo move
myservoy.write(90); // tell servo y to go to position 90 degdelay(25); // makesure servo move//Turning on the ADXL345
writeTo(DEVICE, 0x2D, 0);
writeTo(DEVICE, 0x2D, 16);
writeTo(DEVICE, 0x2D, 8);
}
voidloop()
{
int regAddress = 0x32; //first axis-acceleration-data register on the ADXL345int x, y, z;
digitalWrite(TRIGGER,LOW);
delay(10);
digitalWrite(TRIGGER,HIGH);
readFrom(DEVICE, regAddress, TO_READ, buff); //read the acceleration data from the ADXL345//each axis reading comes in 10 bit resolution, ie 2 bytes. Least Significat Byte first!!//thus we are converting both bytes in to one int//read 5 times and average them
x=0;
y=0;
z=0;
for(i=1;i<=5;i++){
x += (((int)buff[1]) << 8) | buff[0];
y += (((int)buff[3])<< 8) | buff[2];
z += (((int)buff[5]) << 8) | buff[4];
delay(10);
}
x/=5;
y/=5;
z/=5;
if(x<-255)x= -255; elseif (x>255)x=255;
if(y<-255)y= -255; elseif (y>255)y=255;
x=map(x, -255, 255, 0, 180); // map range y
y=map(y, -255, 255, 0, 180); // map range y
myservox.write(x); // tell servo to go to position in variable xdelay(25);
myservoy.write(180-y); // tell servo to go to position in variable y delay(25);
//It appears that delay is needed in order not to clog the portdelay(200);
}
//---------------- Functions//Writes val to address register on devicevoid writeTo(int device, byte address, byte val) {
Wire.beginTransmission(device); //start transmission to device Wire.send(address); // send register addressWire.send(val); // send value to writeWire.endTransmission(); //end transmission
}
//reads num bytes starting from address register on device in to buff arrayvoid readFrom(int device, byte address, int num, byte buff[]) {
Wire.beginTransmission(device); //start transmission to device Wire.send(address); //sends address to read fromWire.endTransmission(); //end transmissionWire.beginTransmission(device); //start transmission to deviceWire.requestFrom(device, num); // request 6 bytes from deviceint i = 0;
while(Wire.available()) //device may send less than requested (abnormal)
{
buff[i] = Wire.receive(); // receive a byte
i++;
}
Wire.endTransmission(); //end transmission
}
Accelerometer ADXL345 memiliki 3 sumbu, X-Axis, Y-Axis dan Z-Axis, pada video ini menunjukkan respon perangkat ini dari berbagai arah gerakan, selanjutnya diproses pada Arduino Severino dan mengirimkannya ke komputer melalui serial RS232 dan ditampilkan pada monitor dalam bentuk Grafik (pemrograman menggunakan VB6)
Schematic Diagram:
List Program
#include <Wire.h>
#define DEVICE (0x53) //ADXL345 device address
#define TO_READ (6) //num of bytes we are going to read each time (two bytes for each axis)
#define TRIGGER 16 // pin Analog2 connect to CS ADXL345,active HIGHbyte buff[TO_READ] ; //6 bytes buffer for saving data read from the devicechar str[64]; //string buffer to transform data before sending it to the serial portvoidsetup()
{ pinMode(TRIGGER,OUTPUT);
digitalWrite(TRIGGER,HIGH);
Wire.begin(); // join i2c bus (address optional for master)Serial.begin(9600); // start serial for output//Turning on the ADXL345
writeTo(DEVICE, 0x2D, 0);
writeTo(DEVICE, 0x2D, 16);
writeTo(DEVICE, 0x2D, 8);
}
voidloop()
{
int regAddress = 0x32; //first axis-acceleration-data register on the ADXL345int x, y, z;
digitalWrite(TRIGGER,LOW);
delay(15);
digitalWrite(TRIGGER,HIGH);
//
readFrom(DEVICE, regAddress, TO_READ, buff); //read the acceleration data from the ADXL345//each axis reading comes in 10 bit resolution, ie 2 bytes. Least Significat Byte first!!//thus we are converting both bytes in to one int
x = (((int)buff[1]) << 8) | buff[0];
y = (((int)buff[3])<< 8) | buff[2];
z = (((int)buff[5]) << 8) | buff[4];
//we send the x y z values as a string to the serial port
sprintf(str, "x=%4d y=%4d z=%4d", x, y, z);
Serial.print(str);
Serial.print(10, BYTE);
//It appears that delay is needed in order not to clog the portdelay(20);
}
//---------------- Functions//Writes val to address register on devicevoid writeTo(int device, byte address, byte val) {
Wire.beginTransmission(device); //start transmission to device Wire.send(address); // send register addressWire.send(val); // send value to writeWire.endTransmission(); //end transmission
}
//reads num bytes starting from address register on device in to buff arrayvoid readFrom(int device, byte address, int num, byte buff[]) {
Wire.beginTransmission(device); //start transmission to device Wire.send(address); //sends address to read fromWire.endTransmission(); //end transmissionWire.beginTransmission(device); //start transmission to deviceWire.requestFrom(device, num); // request 6 bytes from deviceint i = 0;
while(Wire.available()) //device may send less than requested (abnormal)
{
buff[i] = Wire.receive(); // receive a byte
i++;
}
Wire.endTransmission(); //end transmission
}
Program pada Komputer (VB6)
List Program
Dim Y1, Y2,
Y3, y1old, y2old, y3old, x, sg1, sg2, sg3 As Integer
Piezoelectric adalah komponen yang dapat menghasilkan tegangan listrik sebagai respon dari suatu perubahan tekanan mekanik. Dalam proyek ini Piezoelectric digunakan sebagai sensor tekanan mekanik (yang diperoleh dari getaran) dan hasil keluarannya yang berupa tegangan listrik dibaca melalui input analog arduino dan hasilnya dikirim ke komputer melalui serial RS-232, pada komputer data-data ini ditampilkan dalam bentuk grafik sinyal.
Video Demo
Skema rangkaian
List Program (Arduino)
// Program Deteksi getar dengan Piezoelectric// Oleh : Aan Darmawan// valfa.blogspot.com// maret 2011/* Keterangan skema: * Sambungkan Output Piezo ke pin A0 (Analog input pin 0) Arduino * Pin 8 output ke relay , jika nilai getaran mencapai 800, Relay ON */// deklarasi variabelint mgetar;
int getarPin = 0;
voidsetup() {
pinMode(8,OUTPUT);
// aktifkan serial portSerial.begin(9600);
}
voidloop() {
// baca getaran dari A0
mgetar =analogRead(getarPin);
//kirim ke serialSerial.println(mgetar);
if(mgetar>=800) //jika getaran cukup keras
{
digitalWrite(8,HIGH); // aktifkan relaydelay(2000); // delay 2 detik
}
elsedigitalWrite(8,LOW);
delay(30); // berhenti beberapa milidetik
}
List Program Visual Basic 6
Public x1, y1, x2, y2 As Integer
Private Sub Command1_Click()
If Command1.Caption = "START" Then
MSComm1.PortOpen = True
Timer1.Enabled = True
Command1.Caption = "STOP"
Else
MSComm1.PortOpen = False
Timer1.Enabled = False
Command1.Caption = "START"
End If
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 30
x1 = 2
y1 = 450
x2 = 2
y2 = 450
End Sub
Private Sub Form_Paint()
Form1.DrawWidth = 2
Form1.PSet (x1, y1), RGB(255, 0, 0)
Form1.Line (1, 70)-(1, 452), RGB(255, 0, 0)
Form1.Line (1, 452)-(620, 452), RGB(255, 0, 0)
For i = 6 To 616 Step 10
Form1.Line (i, 450)-(i, 455), RGB(255, 0, 0)
Next i
For i = 452 To 72 Step -10
Form1.Line (0, i)-(5, i), RGB(255, 0, 0)
Next i
Form1.PSet (x1, y1), RGB(0, 0, 255)
End Sub
Private Sub Timer1_Timer()
hasil = MSComm1.Input
If Len(hasil) > 0 Then
n = Val(hasil)
If n > 50 Then n = n / 2.273 Else If n > 5 Then n = n * 2
Text1.Text = n
y2 = 450 - n
If y2 <= 186 Then
y2 = 186
Form1.Line (x1, y1)-(x2, y2), RGB(255, 0, 0)
Else
Form1.Line (x1, y1)-(x2, y2), RGB(0, 0, 255)
End If
x1 = x2
y1 = y2
x2 = x2 + 1
If x2 >= 620 Then
x1 = 2
x2 = 2
Form1.Cls
Form1.PSet (x1, y1), RGB(255, 0, 0)
Form1.Line (1, 70)-(1, 452), RGB(255, 0, 0)
Form1.Line (1, 452)-(620, 452), RGB(255, 0, 0)
For i = 6 To 616 Step 10
Form1.Line (i, 450)-(i, 455), RGB(255, 0, 0)
Next i
For i = 452 To 72 Step -10
Form1.Line (0, i)-(5, i), RGB(255, 0, 0)
Next i
Form1.PSet (x1, y1), RGB(0, 0, 255)
End If
End If
End Sub
LM35 adalah IC sensor suhu yang presisi, keluarannya berupa tegangan yang proposional linier terhadap perubahan suhu dalam derajat Celsius. Dalam video ini memperlihatkan aplikasi sensor suhu IC LM35 untuk mengatur Nyala/Padam Kipas, hasil pengukuran dari sensor suhu ditampilkan pada LCD Display 16x2. Jika suhu lebih besar sama dengan 30 derajat Celsius Kipas akan nyala, sebaliknya apabila suhu lebih kecil dari 30 derajat Celsius kipas akan padam.
Demo Video hasil:
Skema Rangkaian:
List Program:
/* Keterangan skema: * Sambungkan LCD RS pin ke pin 12 Arduino * Sambungkan LCD enable pin ke pin 11 Arduino * Sambungkan LCD pins D4 s.d D7 ke pin 5 s.d 2 Arduino * Sambungkan LCD +5 dan ground ke pin +5V dan ground Arduino * Sambungkan LCD Vo pin ke potensiometer. Guna potensiometer ini adalah untuk mengatur kontras LCD * Sambungkan IC LM35 bagian output (Kaki tengah) ke pin A0 (Analog input pin 0) Arduino * Pin 13 arduino sebagai output, jika temp >=30 derajat Pin 13 logik 1 */// Program demo LCD// Gunakan library LCD
#include "LiquidCrystal.h";
// Inisialisasi LCD dan menentukan pin yang dipakaiLiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// deklarasi variabelfloat tempC;
int tempPin = 0;
voidsetup() {
pinMode(13,OUTPUT);
// Serial.begin(9600);// Set jumlah kolom dan baris LCD
lcd.begin(16, 2);
// Tulis Temperatur di LCD
lcd.print("Temperatur:");
}
voidloop() {
// Set cursor ke kolom 0 dan baris 1// Catatan: Baris dan kolom diawali dengan 0
lcd.setCursor(0, 1);
// baca data dari sensor
tempC = analogRead(tempPin);
// konversi analog ke suhu
tempC = (5.0 * tempC * 100.0)/1024.0;
// tampilkan ke LCD
lcd.print(tempC);
// Serial.println(tempC);if(tempC>=30) //jika temperatur >=30 derajatdigitalWrite(13,HIGH);
elsedigitalWrite(13,LOW);
delay(2000); // berhenti 2 detik untuk menunggu perubahan temperatur
}