30 Smart Project Microcontroller Arduino
30 Smart Project Microcontroller Arduino
net/publication/324745091
CITATIONS READS
0 4,801
1 author:
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
SISTEM PENDETEKSI GEMPA LAUT DAN TSUNAMI DINI JARAK JAUH MENGGUNAKAN TEKNOLOGI MIKROKONTROLLER ATMEGA 328P DAN VIBRATION SENSOR DENGAN
SISTEM PENGIRIMAN DATA BERBASIS GSM SIM900A View project
Temperature And Humidity Control System In The Broiler Chicken Coop Using ATmega 328P Microcontroller And Fuzzy Logic Mamdani Method With MATLAB View project
All content following this page was uploaded by Puput Dani Prasetyo Adi on 25 April 2018.
Puput Dani
2016
30 Tutorials Project
Smart Arduino
1 |B u k u A p p r o v e
Daftar Isi
Daftar Produk
…………………………………………………………………………………………………….3
Project 09. Arduino dan Sensor Arus Yhdc SCT-013-000 ( CT – Sensor ) …..…….26
Project 10. Sensor Sentuh ( Touch Sensor ) dengan Arduino ………………...……. 31
2 |B u k u A p p r o v e
Project 30. Komunikasi Arduino Ke Android Via Bluetooth ………………….…….93
Project 31. Voice Recognition Module dan Arduino
3 |B u k u A p p r o v e
Perkenalan Dengan Arduino
4 |B u k u A p p r o v e
proses yang ribet yang akan mematahkan semangat belajar
mengenai mikrokontroler sejak awal.
Dengan board Arduino, anda dimanjakan untuk dapat dengan
mudah dan sederhana mempelajari mikrokontroler berbasis Arduino.
Contoh pada board Arduino UNO R3, pada board tersebut telah
terdapat chip mikrokontroler ATmega328 (yang dapat dicabut
pasang), terdapat chip ATmega16U untuk komunikasi USB, IC regulator
untuk memudahkan kita memberi tegangan (baik USB, baterai 9V
atau AC adaptor 9-12V), dan banyak pin I/O yang sudah disediakan
lubang kabelnya. Perhatian anda tidak lagi tersita hanya untuk koneksi
chip ATmega328, tapi bisa berkonsentrasi pada kreasi yang sedang
anda tuju. Seperti pada contoh led diatas, anda hanya tinggal
sambungkan led ke arduino, koneksikan Arduino via kabel USB, load
program "blink" via software Arduino IDE, dan selesai. Led akan
berkedip dan anda bisa tersenyum.
5 |B u k u A p p r o v e
Contoh Project Arduino
6 |B u k u A p p r o v e
Software Arduino
7 |B u k u A p p r o v e
PROJECT 01
MEMBUAT PROJECT PENGENDALI LAMPU LED
Contoh Implementasi
Mengendalikan Lampu LED, bisa berkedip atau On – Off saat di tekan Button
8 |B u k u A p p r o v e
Coding yang digunakan
void setup()
{
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare pushbutton as input
}
void loop()
{
val=digitalRead(inputPin);
if(val==LOW)
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(80); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(80); // waits for a second
}
else
{
digitalWrite(ledPin, LOW);
}
}
void setup()
{
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare pushbutton as input
}
void loop()
{
val=digitalRead(inputPin);
if(val==LOW)
{
digitalWrite(ledPin, LOW);
9 |B u k u A p p r o v e
}
else
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(150); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(150); // waits for a second
}
}
Project 02
Sensor Cahaya LDR dan Arduino
• 1x Arduino
• 1x Breadboard
• 1x Sensor cahaya LDR
• 1x Resistor 10k
• 7x Kabel jumper
Contoh Implementasi
Suatu kandang ayam memerlukan panas dari lampu pijar dengan panas yang
pas. Lampu pijar akan menyala jika penerangan sekitar kandang kurang
terkena cahaya matahari, dan lampu akan mati dengan sendirinya jika
penerangan dari cahaya matahari tercukupi.
10 |B u k u A p p r o v e
Skematik dan Penyusunan / Pengkabelan
11 |B u k u A p p r o v e
Project 03
• Buzzer 5v
• Arduino Board
Contoh Implementasi
int melody[] = { C, b, g, C, b, e, R, C, c, g, a, C };
int beats[] = { 16, 16, 16, 8, 8, 16, 32, 16, 16, 16, 8, 8 };
int MAX_COUNT = sizeof(melody) / 2; // Melody length, for looping.
digitalWrite(speakerOut,HIGH);
delayMicroseconds(tone_ / 2);
// DOWN
12 |B u k u A p p r o v e
digitalWrite(speakerOut, LOW);
delayMicroseconds(tone_ / 2);
playTone();
// A pause between notes...
delayMicroseconds(pause);
13 |B u k u A p p r o v e
Project 04.
• Arduino Board
• Potensiometer
Contoh Implementasi
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
}
void loop() {
val = analogRead(potPin); // read the value from the sensor
digitalWrite(ledPin, HIGH); // turn the ledPin on
delay(val); // stop the program for some time
digitalWrite(ledPin, LOW); // turn the ledPin off
delay(val); // stop the program for some time
}
14 |B u k u A p p r o v e
Project 05.
LED dengan Arduino
Arduino Board
LCD 16x2
Contoh Implementasi
Menampilkan teks 2 baris
#include <LiquidCrystal.h>
15 |B u k u A p p r o v e
const int PIN_RS = 12;
const int PIN_E = 11;
const int PIN_DB_4 = 7;
const int PIN_DB_5 = 6;
const int PIN_DB_6 = 5;
const int PIN_DB_7 = 4;
// Buat objek
LiquidCrystal lcd(PIN_RS, PIN_E, PIN_DB_4, PIN_DB_5, PIN_DB_6, PIN_DB_7);
void setup()
{
// Tentukan ukuran LCD
lcd.begin(16, 2);
}
void loop()
{
lcd.clear();
lcd.print("Balonku ada lima");
lcd.setCursor(0, 1);
lcd.print("Beraneka warna");
delay(5000);
lcd.clear();
lcd.print("Meletus satu");
lcd.setCursor(0, 1);
lcd.print("Tinggal 4-lah");
delay(5000);
}
16 |B u k u A p p r o v e
Project 06.
Arduino dengan Motor DC
Fungsi Motor DC ini salah satunya digunakan untuk menggerakkan roda mobil
mainan.
• 1 x L298 bridge IC
• 1 x DC motor
• 1 x Arduino Mega2560 / Arduino UNO
• 1 x breadboard
• 10 x jumper wires
Contoh Implementasi
Anda bisa membuat percobaan untuk mengatur Putaran Motor DC
void setup()
17 |B u k u A p p r o v e
{
pinMode(pwm,OUTPUT) ; //we have to set PWM pin as output
pinMode(in_1,OUTPUT) ; //Logic pins are also set as output
pinMode(in_2,OUTPUT) ;
}
void loop()
{
//For Clock wise motion , in_1 = High , in_2 = Low
digitalWrite(in_1,HIGH) ;
digitalWrite(in_2,LOW) ;
analogWrite(pwm,255) ;
//For brake
digitalWrite(in_1,HIGH) ;
digitalWrite(in_2,HIGH) ;
delay(1000) ;
//For brake
digitalWrite(in_1,HIGH) ;
digitalWrite(in_2,HIGH) ;
delay(1000) ;
}
// --------------------------------------
// Contoh untuk mengatur putaran motor DC
18 |B u k u A p p r o v e
// --------------------------------------
void setup()
{
pinMode(PIN_PWM, OUTPUT);
}
void loop()
{
// Kecepatan penuh
analogWrite(PIN_PWM, 255);
delay(5000);
// Kecepatan sedang
analogWrite(PIN_PWM, 128);
delay(5000);
// Motor dimatikan
analogWrite(PIN_PWM, 0);
delay(5000);
}
19 |B u k u A p p r o v e
Project 07
Motor Servo dan Arduino
• Arduino Board
• Motor Servo
• Wire
Contoh Implementasi
20 |B u k u A p p r o v e
Source Code yang digunakan
// ------------------------------------
// Contoh untuk mengontrol motor servo
// ------------------------------------
#include <Servo.h>
// Buat objek
Servo motorServo;
void setup()
{
// Motor servo dihubungkan ke pin servo
motorServo.attach(PIN_SERVO);
}
void loop()
{
motorServo.write(0);
delay(2000);
motorServo.write(90);
delay(2000);
motorServo.write(135);
delay(2000);
}
21 |B u k u A p p r o v e
PROJECT 08
ARDUINO AND FIBRATION SENSOR
Fibration Sensor
Contoh Implementasi
Melakukan Percobaan dengan membuat suatu getaran disekitar Sensor
dan lihat pada Serial Monitor.
22 |B u k u A p p r o v e
void setup() {
Serial.begin(9600);
pinMode(vibrationSensorPin, INPUT); // Jadikan Vibration
sensor sebagai input
pinMode(indikatorHijau, OUTPUT); // Jadikan indikatorHijau
sebagai Output
pinMode(indikatorMerah, OUTPUT); // Jadiikan indikatorMerah
sebagai Output
pinMode(indikatorBuzzer, OUTPUT); // Jadikan indikatorBuzzer
sebagai Output
}
void loop() {
vibrationSensorState = digitalRead(vibrationSensorPin);
if (vibrationSensorState == HIGH) { // Jika ada getaran di
sensor = HIGH
digitalWrite(indikatorHijau, HIGH); // Aktifkan indikator
Hijau
digitalWrite(indikatorMerah, LOW); // Matikan indikator
Merah
digitalWrite(indikatorBuzzer, HIGH); // // Aktifkan
indikator Buzzer
Serial.println("Ada Pergetaran gan!");
delay(8000); // Tunda 8 detik
digitalWrite(indikatorHijau, LOW); // Matikan indikator
Hijau
digitalWrite(indikatorMerah, HIGH); // Aktifkan indikator
Merah
delay(100); // Delay untuk menunggu getaran selanjutnya
}
else {
digitalWrite(indikatorHijau, LOW); // Matikan indikator
Hijau
digitalWrite(indikatorMerah, HIGH); // Aktifkan indikator
Merah
digitalWrite(indikatorBuzzer, LOW); // Matikan indikator
Buzzer
Serial.println("Menunggu getaran...");
delay(1000);
}
}
23 |B u k u A p p r o v e
Project.09
• 1 10uF capacitor
Contoh Implementasi
Anda bisa membaca arus listrik pada setiap output kabel listrik
dari tempat yang berbeda – beda.
24 |B u k u A p p r o v e
Skematik dan Penyusunan / Pengkabelan
25 |B u k u A p p r o v e
Program Arduino dan CT – Sensor
void setup()
{
Serial.begin(9600);
void loop()
{
double Irms = emon1.calcIrms(1480); // Calculate Irms only
Emonlib.h
/*
Emon.h - Library for openenergymonitor
Created by Trystan Lea, April 27 2010
GNU GPL
modified to use up to 12 bits ADC resolution (ex. Arduino Due)
by boredman@boredomprojects.net 26.12.2013
Low Pass filter for offset removal replaces HP filter 1/1/2015 - RW
*/
#ifndef EmonLib_h
#define EmonLib_h
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
26 |B u k u A p p r o v e
// otherwise will default to 10 bits, as in regular Arduino-based
boards.
#if defined(__arm__)
#define ADC_BITS 12
#else
#define ADC_BITS 10
#endif
class EnergyMonitor
{
public:
long readVcc();
//Useful value variables
double realPower,
apparentPower,
powerFactor,
Vrms,
Irms;
private:
//----------------------------------------------------------------
----------------------
// Variable declaration for emon_calc procedure
//----------------------------------------------------------------
----------------------
int sampleV; //sample_ holds
the raw analog read value
int sampleI;
27 |B u k u A p p r o v e
boolean lastVCross, checkVCross; //Used to
measure number of times threshold is crossed.
};
#endif
28 |B u k u A p p r o v e
Project 10
Sensor Sentuh ( Touch Sensor ) dengan Arduino
• Arduino Board
• Touch Sensor
Contoh Implementasi
29 |B u k u A p p r o v e
Coding yang digunakan
// -------------------------------
// Contoh penggunaan sensor sentuh
// -------------------------------
void setup()
{
Serial.begin(9600);
pinMode(PIN_DIGITAL, INPUT);
}
void loop()
{
int d0 = digitalRead(PIN_DIGITAL);
Serial.println(d0);
delay(100);
}
PROJECT 11.
Arduino Dan Ultrasonik
Contoh Implementasi
Anda bisa mengatur jarak tertentu dengan Ultrasonik dan diberi
indikator buzzer saat memenuhi jarak tertentu sesuai kebutuhan.
30 |B u k u A p p r o v e
Skematik dan Penyusunan / Pengkabelan
The circuit:
* +V connection of the PING))) attached to +5V
* GND connection of the PING))) attached to ground
* SIG connection of the PING))) attached to digital pin 7
http://www.arduino.cc/en/Tutorial/Ping
*/
void setup() {
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;
31 |B u k u A p p r o v e
// The PING))) is triggered by a HIGH pulse of 2 or more
microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the
sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);
}
32 |B u k u A p p r o v e
Project 12
Water Level Sensor Arduino
Water Level Sensor adalah Sensor yang digunakan untuk mengukur tingkat
curah hujan.
Untuk menguji bisa ditempatkan disuatu wadah datar. Anggaplah berada di
tanah, apabila terdapat air atau bercak air maka sensor akan memunculkan
pada serial port berupa teks atau keterangan tidak hujan atau hujan, apabila
terdapat air.
void setup()
{
Serial.begin(9600);
}
void loop()
33 |B u k u A p p r o v e
{
// Baca sensor
int dataSensor = analogRead(PIN_A0);
Serial.print(dataSensor);
// Cek ambang
if (dataSensor < 300)
Serial.println(". Hujan deras");
else
if (dataSensor < 500)
Serial.println(". Hujan biasa");
else
Serial.println(". Tidak hujan");
delay(100);
}
Project 13
Sensor Kelembaban Tanah dengan Arduino
Apabila dikoneksikan dengan Arduino, maka ada 3 inputan disini yaitu AREF,
GND dan A0.
34 |B u k u A p p r o v e
// Contoh penggunaan sensor kelembaban tanah
// -------------------------------------------
void setup() {
Serial.begin(9600);
pinMode(PIN_DIGITAL, INPUT);
}
void loop() {
int a0 = analogRead(PIN_ANALOG);
int d0 = digitalRead(PIN_DIGITAL);
Serial.print(d0);
Serial.print(" - ");
Serial.println(a0);
delay(1000);
}
Project 14.
Arduino dan Joystick
35 |B u k u A p p r o v e
Code Programnya seperti berikut :
int sensorPin = 5;
int value = 0;
void setup() {
pinMode(7, OUTPUT);
Serial.begin(9600);
}
void loop() {
value = analogRead(0);
Serial.print("X:");
Serial.print(value, DEC);
value = analogRead(1);
Serial.print(" | Y:");
Serial.print(value, DEC);
value = digitalRead(7);
Serial.print(" | Z: ");
Serial.println(value, DEC);
delay(100);
}
Referring Sample Code :
int JoyStick_X = 0; //x
int JoyStick_Y = 1; //y
int JoyStick_Z = 3; //key
void setup()
{
pinMode(JoyStick_X, INPUT);
pinMode(JoyStick_Y, INPUT);
pinMode(JoyStick_Z, INPUT);
Serial.begin(9600); // 9600 bps
}
void loop()
{
int x,y,z;
x=analogRead(JoyStick_X);
y=analogRead(JoyStick_Y);
z=digitalRead(JoyStick_Z);
Serial.print(x ,DEC);
Serial.print(",");
Serial.print(y ,DEC);
Serial.print(",");
Serial.println(z ,DEC);
delay(100);
}
36 |B u k u A p p r o v e
Project 15
Sensor API ( Flame Sensor ) dan Arduino
Contoh Implementasi :
Sensor APi bisa digunakan untuk aplikasi Robot pendeteksi Api, atau bisa
dipasang di tempat-tempat yang tidak boleh ada percikan api seperti di
SPBU, mall atau di kantor-kantor.
Berikut adalah Wiring Flame Sensor dan Arduino, terdapat 3 Output Flame
Sensor, yaitu GND, VCC dan Out Pin Analog.
37 |B u k u A p p r o v e
Code Program yang digunakan
// ----------------------------
// Contoh penggunaan sensor api
// ----------------------------
void setup()
{
Serial.begin(9600);
pinMode(PIN_DIGITAL, INPUT);
}
void loop()
{
int a0 = analogRead(PIN_ANALOG);
int d0 = digitalRead(PIN_DIGITAL);
Serial.print(d0);
Serial.print(" - ");
Serial.println(a0);
delay(1000);
}
38 |B u k u A p p r o v e
Project 16.
Sensor Gas dan Arduino
Contoh Implementasi :
Sensor Gas MQ2 digabung dengan Arduino dan Buzzer, bisa juga
ditambahkan dengan LCD Misalnya 16x2 untuk mendeteksi kebocoran
gas LPG. Ini sangat bermanfaat bagi masyarakat.
39 |B u k u A p p r o v e
Coding yang digunakan untuk Sensor MQ – 2
// -------------------------------
// Contoh penggunaan sensor MQ-2
// untuk mendeteksi gas
// -------------------------------
const int PIN_ANALOG = 0;
const int PIN_DIGITAL = 12;
void setup()
{
Serial.begin(9600);
pinMode(PIN_DIGITAL, INPUT);
}
void loop()
{
int a0 = analogRead(PIN_ANALOG);
int d0 = digitalRead(PIN_DIGITAL);
Serial.print(d0);
Serial.print(" - ");
Serial.println(a0);
delay(1000);
}
void setup()
{
Serial.begin(9600);
pinMode(PIN_LED, OUTPUT);
}
void loop()
{
int a0 = analogRead(PIN_ANALOG);
Serial.println(a0);
if (a0 >= AMBANG)
{
// Berikan peringatan
Serial.println("LED");
digitalWrite(PIN_LED, HIGH);
delay(500);
digitalWrite(PIN_LED, LOW);
}
else
delay(500);
}
40 |B u k u A p p r o v e
Project 17.
41 |B u k u A p p r o v e
Koneksi PIN nya sebagai berikut :
int motion_1 = 2;
int light_1 = 13;
void setup(){
pinMode (motion_1,INPUT);
pinMode (light_1, OUTPUT);
}
}
}
42 |B u k u A p p r o v e
Kode Program yang digunakan :
int motion_1 = 2;
int light_1 = 13;
void setup(){
pinMode (motion_1,INPUT);
pinMode (light_1, OUTPUT);
}
}
}
int pirPin = 7;
void setup()
{
pinMode(pirPin, INPUT);
Serial.begin(9600);
}
void loop()
{
long now = millis();
if (digitalRead(pirPin) == HIGH)
{
if (now > (lastSend + minSecsBetweenEmails * 1000l))
{
Serial.println("MOVEMENT");
lastSend = now;
}
else
{
Serial.println("Too soon");
}
}
delay(500);
}
43 |B u k u A p p r o v e
Percobaan :
void setup()
{
Serial.begin(9600);
pinMode(PIN_MOTION, INPUT);
}
void loop()
{
nilai = digitalRead(PIN_MOTION);
if (nilai == HIGH) {
Serial.println("HIGH");
}
else {
Serial.println("LOW");
}
delay(1000);
}
Lakukan proses Verifikasi kemudian Upload, untuk hasilnya bisa dilihat di serial
monitor :
44 |B u k u A p p r o v e
Keterangan : Akan Low jika tidak ada gerakan, dan apabila ada gerakan
maka High.
PROJECT 18
ARDUINO DAN RFID – RC522A
45 |B u k u A p p r o v e
Keterangan Pin yang digunakan :
46 |B u k u A p p r o v e
D6 = Pin 3
D7 = Pin 2
/*
* MFRC522 - Library to use ARDUINO RFID MODULE KIT 13.56 MHZ WITH
TAGS SPI W AND R BY COOQROBOT.
* The library file MFRC522.h has a wealth of useful info. Please read
it.
* The functions are documented in MFRC522.cpp.
*
* Based on code Dr.Leong ( WWW.B2CQSHOP.COM )
* Created by Miguel Balboa (circuitito.com), Jan, 2012.
* Rewritten by Søren Thing Andersen (access.thing.dk), fall of 2013
(Translation to English, refactored, comments, anti collision, cascade
levels.)
* Released into the public domain.
*
* Sample program showing how to read data from a PICC using a MFRC522
reader on the Arduino SPI interface.
*--------------------------------------------------------------------
--------- empty_skull
* Aggiunti pin per arduino Mega
* add pin configuration for arduino mega
* http://mac86project.altervista.org/
---------------------------------------------------------------------
-------- Nicola Coppola
* Pin layout should be as follows:
* Signal Pin Pin Pin
* Arduino Uno Arduino Mega MFRC522 board
* ------------------------------------------------------------
* Reset 9 5 RST
* SPI SS 10 53 SDA
* SPI MOSI 11 51 MOSI
* SPI MISO 12 50 MISO
* SPI SCK 13 52 SCK
*
* The reader can be found on eBay for around 5 dollars. Search for
"mf-rc522" on ebay.com.
*/
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
void setup() {
Serial.begin(9600); // Initialize serial communications with
the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println("Scan PICC to see UID and type...");
}
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
47 |B u k u A p p r o v e
// Dump debug info about the card. PICC_HaltA() is automatically
called.
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
PROJECT 19
48 |B u k u A p p r o v e
Program Arduino dan Pulse SENSOR bisa dilihat pada program dibawah ini :
/*
>> Pulse Sensor Amped <<
This code is for Pulse Sensor Amped by Joel Murphy and Yury
Gitman
www.pulsesensor.com
>>> Pulse Sensor purple wire goes to Analog Pin 0 <<<
Pulse Sensor sample aquisition and processing happens in
the background via Timer 1 interrupt. 1mS sample rate.
PWM on pins 9 and 10 will not work when using this code!
The following variables are automatically updated:
Pulse : boolean that is true when a heartbeat is sensed
then false in time with pin13 LED going out.
Signal : int that holds the analog signal data straight
from the sensor. updated every 1mS.
HRV : int that holds the time between the last two
beats. 1mS resolution.
BPM : int that holds the heart rate value. derived
every pulse from averaging previous 10 HRV values.
QS : boolean that is made true whenever Pulse is
found and BPM is updated. User must reset.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// VARIABLES
int green_pin = 8;
int yellow_pin = 9;
int red_pin = 10;
int x=0;
int a=0;
int a_sent=0;
boolean kuning = false;
boolean merah = false;
boolean bunyi = false;
int kondisi=0;
boolean sts = true;
49 |B u k u A p p r o v e
volatile int Signal; // holds the incoming
raw data
volatile int HRV; // holds the time
between beats
volatile boolean Pulse = false; // true when pulse wave
is high, false when it's low
volatile boolean QS = false; // becomes true when
pulse rate is determined. every 20 pulses
volatile boolean B=false;
void setup(){
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print(" BPM ");
lcd.setCursor(0, 1);
lcd.print("0 ");
pinMode(6,OUTPUT);
pinMode(red_pin, OUTPUT);
pinMode(yellow_pin, OUTPUT);
pinMode(green_pin, OUTPUT);
50 |B u k u A p p r o v e
kuning=false;
merah=false;
}
else
if((BPM>44 && BPM<60) || (BPM>100 && BPM<116))
{
digitalWrite(yellow_pin, HIGH);
digitalWrite(red_pin, LOW);
digitalWrite(green_pin, LOW);
x=0 ;
kuning=true;
merah=false;
}
else
{
digitalWrite(yellow_pin, LOW);
digitalWrite(red_pin, HIGH);
digitalWrite(green_pin, LOW);
kuning=false;
merah=true;
}
QS = false; // reset the
Quantified Self flag for next time
}
ledFadeToBeat();
a++;
if(a%1==0 && kuning==true)
{
if (bunyi==true) bunyi=false;
else bunyi=true;
}
if(merah==true)
{
x++;
if(x>=5) bunyi=false; else bunyi=true;
}
void ledFadeToBeat(){
fadeRate -= 15; // set LED fade
value
fadeRate = constrain(fadeRate,0,255); // keep LED fade
value from going into negative numbers!
//analogWrite(11,fadeRate); // fade LED
}
51 |B u k u A p p r o v e
Keluaran / output nya seperti berikut, menggunakan program Processing
Project 20.
Modul SIM900 dan Arduino
52 |B u k u A p p r o v e
Koneksi dengan Arduino
//ERFINDER CODE
#include <SoftwareSerial.h>
void setup()
{
Serial.begin(9600);
Serial.println("Called ATDxxxxxxxxxx");
// print response over serial port
if (mySerial.available())
Serial.write(mySerial.read());
}
53 |B u k u A p p r o v e
Code untuk Mengirim Pesan ( Message )
//ERFINDER CODE
#include <SoftwareSerial.h>
void setup()
{
mySerial.begin(9600); // Setting the baud rate of GSM Module
Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
delay(100);
}
void loop()
{
if (Serial.available()>0)
switch(Serial.read())
{
case 's':
SendMessage();
break;
case 'r':
RecieveMessage();
break;
}
if (mySerial.available()>0)
Serial.write(mySerial.read());
}
void SendMessage()
{
mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
mySerial.println("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // Replace x with mobile
number
delay(1000);
mySerial.println("I am SMS from GSM Module");// The SMS text you want to send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
void RecieveMessage()
{
mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to recieve a live SMS
delay(1000);
}
54 |B u k u A p p r o v e
PROJECT 21.
ARDUINO, BUZZER, LED AND ULTRASONIC SENSOR
Pada project berikut kita akan membuat objek menggunakan Ultrasonik sensor,
kita akan menggunakan buzzer dan LED untuk memberikan suatu petunjuk
indikator dari hasil perubahan jarak yang ditentukan dari program yang
• Sensor Ultrasonik
• Buzzer 5V
• Cable Jumper
55 |B u k u A p p r o v e
Codingnya seperti dibawah ini
56 |B u k u A p p r o v e
float pingTime; //time for ping to travel from sensor to target
and return
float targetDistance; //Distance to Target in inches
float speedOfSound=776.5; //Speed of sound in miles per hour when
temp is 77 degrees.
void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
void loop() {
57 |B u k u A p p r o v e
Project 22.
Arduino Ethernet Shield
58 |B u k u A p p r o v e
merupakan suatu cara untuk menentukan rentang alamat suatu
perangkat yang dapat diakses langsung melalui gateway.
1. Arduino Board
2. Ethernet Shield
3. Arduino IDE
Arduino IDE bisa didownload di
https://www.arduino.cc/en/Main/Software
4. Kabel Cross LAN & RJ45
59 |B u k u A p p r o v e
Langkah Kerja :
60 |B u k u A p p r o v e
Tuliskan Code berikut pada Arduino IDE
/*
Web Server
A simple web server that shows the value of the analog
input pins.
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5
(optional)
created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your
controller below.
// The IP address will be dependent on your local
network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for
Leonardo only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print(“server is at “);
Serial.println(Ethernet.localIP());
}
void loop() {
// listen for incoming clients
61 |B u k u A p p r o v e
EthernetClient client = server.available();
if (client) {
Serial.println(“new client”);
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you’ve gotten to the end of the line (received a
newline
// character) and the line is blank, the http request
has ended,
// so you can send a reply
if (c == ‘\n’ && currentLineIsBlank) {
// send a standard http response header
client.println(“HTTP/1.1 200 OK”);
client.println(“Content-Type: text/html”);
client.println(“Connection: close”); // the connection
will be closed after completion of the response
client.println(“Refresh: 5”); // refresh the page
automatically every 5 sec
client.println();
client.println(“<!DOCTYPE HTML>”);
client.println(“<html>”);
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6;
analogChannel++) {
int sensorReading = analogRead(analogChannel);
client.print(“analog input “);
client.print(analogChannel);
client.print(” is “);
client.print(sensorReading);
client.println(“<br />”);
}
client.println(“</html>”);
break;
}
if (c == ‘\n’) {
// you’re starting a new line
currentLineIsBlank = true;
}
else if (c != ‘\r’) {
// you’ve gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println(“client disconnected”);
}
}
Hasil :
62 |B u k u A p p r o v e
Setelah mengikuti perintah di atas, kita akan melihat nilai analog dari ADC
channel 0 hingga 5. Data tersebut akan ter-refresh setiap 5 detik, bergantung
nilai yang kita set. Sekarang kita sudah bisa membuat server sensor kita sendiri.
PROJECT 23
MENAMPILKAN SUHU, TEMPERATURE DAN INTENSITAS CAHAYA
DENGAN ARDUINO UNO DAN SENSOR DHT11 DI LCD 16 X 2
DHT11 adalah sensor Suhu dan Kelembaban, dia memiliki keluaran sinyal
digital yang dikalibrasi dengan sensor suhu dan kelembaban yang kompleks.
Teknologi ini memastikan keandalan tinggi dan sangat baik stabilitasnya dalam
Sensor ini termasuk elemen resistif dan perangkat pengukur suhu NTC. Memiliki
Setiap sensor DHT11 memiliki fitur kalibrasi sangat akurat dari kelembaban ruang
kalibrasi. Koefisien kalibrasi yang disimpan dalam memori program OTP, sensor
63 |B u k u A p p r o v e
internal mendeteksi sinyal dalam proses, kita harus menyebutnya koefisien
kalibrasi. Sistem antarmuka tunggal-kabel serial terintegrasi untuk menjadi cepat
dan mudah. Kecil ukuran, daya rendah, sinyal transmisi jarak hingga 20 meter,
sehingga berbagai aplikasi dan bahkan aplikasi yang paling menuntut. Produk
ini 4-pin pin baris paket tunggal. Koneksi nyaman, paket khusus dapat diberikan
sesuai dengan kebutuhan pengguna.
spesifikasi
• Pasokan Voltage: 5 V
• Rentang temperatur :0-50 ° C kesalahan ± 2 ° C
• Kelembaban :20-90% RH ± 5% RH error
• Interface: Digital
64 |B u k u A p p r o v e
Serial.println("dht11 start condition 1 not met"); // wait for DHT
response signal: LOW
delay(1000);
return;
}
delayMicroseconds(80);
dht11_in = PINC & _BV(DHT11_PIN); //
if(!dht11_in)
{
Serial.println("dht11 start condition 2 not met"); //wair for
second response signal:HIGH
return;
}
delayMicroseconds(80);// now ready for data reception
for (i=0; i<5; i++)
{ dht11_dat[i] = read_dht11_dat();} //recieved 40 bits data.
Details are described in datasheet
DDRC |= _BV(DHT11_PIN); //let analog port 0 be output port
after all the data have been received
PORTC |= _BV(DHT11_PIN); //let the value of this port be '1'
after all the data have been received
byte dht11_check_sum =
dht11_dat[0]+dht11_dat[1]+dht11_dat[2]+dht11_dat[3];// check check_sum
if(dht11_dat[4]!= dht11_check_sum)
{
Serial.println("DHT11 checksum error");
}
Serial.print("Kelembaban = ");
Serial.print(dht11_dat[0], DEC);
Serial.print(".");
Serial.print(dht11_dat[1], DEC);
Serial.print("% ");
Serial.print("Suhu = ");
Serial.print(dht11_dat[2], DEC);
Serial.print(".");
Serial.print(dht11_dat[3], DEC);
Serial.println("C ");
delay(2000); //fresh time
}
65 |B u k u A p p r o v e
66 |B u k u A p p r o v e
Code yang digunakan
byte bGlobalErr; //for passing error code back from complex functions.
byte dht_dat[4]; //Array to hold the bytes sent from sensor.
int light_intensity = 0;
unsigned int flip = 0;
void setup(){
//Blink LED to detect hangs
pinMode(13, OUTPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.print("HALLO, PUPUT!");
InitDHT(); //Do what's necessary to prepare for reading DHT
//Serial.begin(9600);
delay(300); //Let system settle
//Serial.println("Humidity and temperature\n\n");
delay(700); //Wait rest of 1000ms recommended delay before
//accessing sensor
} //end "setup()"
void loop(){
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with
0):
//lcd.setCursor(0, 1);
// print the number of seconds since reset:
//lcd.print("100");
//lcd.print(millis()/1000);
if ( flip & 1 )
{
digitalWrite(13, HIGH);
} else {
67 |B u k u A p p r o v e
digitalWrite(13, LOW);
}
flip++;
light_intensity=analogRead(LIGHT_SENSOR_PIN);
ReadDHT(); //This is the "heart" of the program.
//Fills global array dht_dpin[], and bGlobalErr, which
//will hold zero if ReadDHT went okay.
//Must call InitDHT once (in "setup()" is usual) before
//calling ReadDHT.
//Following: Display what was seen...
switch (bGlobalErr) {
case 0:
lcd.setCursor(0, 0);
// Serial.print("humdity = ");
lcd.print("Suhu = C");
lcd.setCursor(7, 0);
lcd.print( dht_dat[2], DEC);
//Serial.print(dht_dat[0], DEC);
//Serial.print(".");
//Serial.print(dht_dat[1], DEC);
//Serial.print("% ");
lcd.setCursor(0, 1);
//Every 7 out of 15 times we show humidity, rest temp
if ((flip % 15) > 7 )
{
lcd.print("Kelembaban %");
lcd.setCursor(11, 1);
lcd.print( dht_dat[0], DEC);
} else {
lcd.print("Cahaya = ");
lcd.setCursor(8, 1);
lcd.print( light_intensity, DEC);
}
//Serial.print("temperature = ");
//Serial.print(dht_dat[2], DEC);
//Serial.print(".");
//Serial.print(dht_dat[3], DEC);
//Serial.println("C ");
break;
case 1:
//Serial.println("Error 1: DHT start condition 1 not
met.");
68 |B u k u A p p r o v e
break;
case 2:
//Serial.println("Error 2: DHT start condition 2 not
met.");
break;
case 3:
//Serial.println("Error 3: DHT checksum error.");
break;
default:
//Serial.println("Error: Unrecognized code
encountered.");
break;
} //end "switch"
delay(800); //Don't try to access too frequently... in theory
//should be once per two seconds, fastest,
//but seems to work after 0.8 second.
} // end loop()
/*Below here: Only "black box" elements which can just be plugged
unchanged
unchanged into programs. Provide InitDHT() and ReadDHT(), and a
function
one of them uses.*/
void InitDHT(){
//DDRC |= _BV(dht_PIN);//set data pin... for now... as output
//DDRC is data direction register for pins A0-5 are on
//PORTC |= _BV(dht_PIN);//Set line high
//PORTC relates to the pins A0-5 are on.
//Alternative code...
// if (dht_dpin-14 != dht_PIN){Serial.println("ERROR- dht_dpin
must be 14 more than dht_PIN");};//end InitDHT
pinMode(dht_dpin,OUTPUT); // replaces DDRC... as long as
dht_dpin=14->19
digitalWrite(dht_dpin,HIGH); //Replaces PORTC |= if
dht_pin=14->19
} //end InitDHT
void ReadDHT(){
/*Uses global variables dht_dat[0-4], and bGlobalErr to pass
"answer" back. bGlobalErr=0 if read went okay.
Depends on global dht_PIN for where to look for sensor.*/
bGlobalErr=0;
byte dht_in;
69 |B u k u A p p r o v e
byte i;
// Send "start read and report" command to sensor....
// First: pull-down i/o pin for 18ms
digitalWrite(dht_dpin,LOW); //Was: PORTC &= ~_BV(dht_PIN);
delay(18);
delayMicroseconds(600);//TKB, frm Quine at Arduino forum
/*aosong.com datasheet for DHT22 says pin should be low at least
500us. I infer it can be low longer without any]
penalty apart from making "read sensor" process take
longer. */
//Next line: Brings line high again,
// second step in giving "start read..." command
digitalWrite(dht_dpin,HIGH); //Was: PORTC |= _BV(dht_PIN);
delayMicroseconds(40); //DHT22 datasheet says host should
//keep line high 20-40us, then watch for sensor taking line
//low. That low should last 80us. Acknowledges "start read
//and report" command.
if(dht_in) {
bGlobalErr=1; //Was: Serial.println("dht11 start
condition 1 not met");
return;
} //end "if..."
delayMicroseconds(80);
if(!dht_in) {
bGlobalErr=2; //Was: Serial.println("dht11 start
condition 2 not met");
return;
} //end "if..."
/*After 80us low, the line should be taken high for 80us by the
sensor. The low following that high is the start of the first
70 |B u k u A p p r o v e
bit of the forty to come. The routine "read_dht_dat()"
expects to be called with the system already into this low.*/
delayMicroseconds(70);
//now ready for data reception... pick up the 5 bytes coming from
// the sensor
for (i=0; i<5; i++)
dht_dat[i] = read_dht_dat();
byte read_dht_dat(){
//Collect 8 bits from datastream, return them interpreted
//as a byte. I.e. if 0000.0101 is sent, return decimal 5.
byte i = 0;
byte result=0;
for(i=0; i< 8; i++) {
//We enter this during the first start bit (low for
50uS) of the byte
//Next: wait until pin goes high
while(digitalRead(dht_dpin)==LOW) ; //Was:
while(!(PINC & _BV(dht_PIN)));
//signalling end of start of bit's transmission.
71 |B u k u A p p r o v e
//Dataline will now stay high for 27 or 70 uS,
depending on
//whether a 0 or a 1 is being sent, respectively.
delayMicroseconds(30); //AFTER pin is high, wait
further period, to be
//into the part of the timing diagram where a 0 or a 1
denotes
//the datum being send. The "further period" was 30uS
in the software
//that this has been created from. I believe that a
higher number
//(45?) would be more appropriate.
72 |B u k u A p p r o v e
Project 24.
RTC (Real Time Clock )dan Arduino
RTC ( Real Time Clock ) digunakan untuk menghasilkan waktu yang tepat
karena dilengkapi dengan Pembangkit waktu dan baterai.
73 |B u k u A p p r o v e
{
// sets time and date data to DS3231
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set next input to start at the seconds
register
Wire.write(decToBcd(second)); // set seconds
Wire.write(decToBcd(minute)); // set minutes
Wire.write(decToBcd(hour)); // set hours
Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday,
7=Saturday)
Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
Wire.write(decToBcd(month)); // set month
Wire.write(decToBcd(year)); // set year (0 to 99)
Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set DS3231 register pointer to 00h
Wire.endTransmission();
Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
// request seven bytes of data from DS3231 starting from
register 00h
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f);
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}
void displayTime()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
// retrieve data from DS3231
readDS3231time(&second, &minute, &hour, &dayOfWeek,
&dayOfMonth, &month,
&year);
// send it to the serial monitor
Serial.print(hour, DEC);
// convert the byte variable to a decimal number when
displayed
Serial.print(":");
if (minute<10)
{
Serial.print("0");
}
Serial.print(minute, DEC);
Serial.print(":");
if (second<10)
{
Serial.print("0");
}
Serial.print(second, DEC);
Serial.print(" ");
Serial.print(dayOfMonth, DEC);
Serial.print("/");
74 |B u k u A p p r o v e
Serial.print(month, DEC);
Serial.print("/");
Serial.print(year, DEC);
Serial.print(" Day of week: ");
switch(dayOfWeek){
case 1:
Serial.println("Sunday");
break;
case 2:
Serial.println("Monday");
break;
case 3:
Serial.println("Tuesday");
break;
case 4:
Serial.println("Wednesday");
break;
case 5:
Serial.println("Thursday");
break;
case 6:
Serial.println("Friday");
break;
case 7:
Serial.println("Saturday");
break;
}
}
void loop()
{
displayTime(); // display the real-time clock data on the
Serial Monitor,
delay(1000); // every second
}
75 |B u k u A p p r o v e
PROJECT 25.
Arduino dan Bluetooth hc - 06
76 |B u k u A p p r o v e
Code Program yang digunakan
//If youre not using a BTBee connect set the pin connected to the KEY pin
high
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(4,5);
void setup() {
String setName = String("AT+NAME=MyBTBee\r\n"); //Setting name as 'MyBTBee'
Serial.begin(9600);
BTSerial.begin(38400);
BTSerial.print("AT\r\n"); //Check Status
delay(500);
while (BTSerial.available()) {
Serial.write(BTSerial.read());
}
BTSerial.print(setName); //Send Command to change the name
delay(500);
while (BTSerial.available()) {
Serial.write(BTSerial.read());
}}
void loop() {}
Project 26
Arduino dengan KeyPad
Keypad digunakan untuk menginputkan suatu angka 1,2,3,4,5,6,7,8,9,0 dan
karakter * dan #. Keypad ini memiliki 2 tipe 3x4 dan 4x4. Sangat mudah untuk
dikoneksikan dengan Arduino.
Keypad jenis 3x4 memiliki 7 Pin, bisa dilihat pada gambar dibawah ini
77 |B u k u A p p r o v e
Program yang digunakan adalah sebagai berikut :
#include "Keypad.h"
void setup()
{
Serial.begin(9600);
}
void loop()
{
char key = keypad.getKey();
if (key != NO_KEY){
Serial.println(key);
}
}
78 |B u k u A p p r o v e
Project 27.
Arduino dan Seven Segment
79 |B u k u A p p r o v e
Code yang digunakan adalah sebagai berikut :
#define segA 2//connecting segment A to PIN2
void setup()
}
void loop()
switch (COUNT)
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, LOW);
break;
digitalWrite(segA, LOW);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
80 |B u k u A p p r o v e
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
break;
case 2:// when count value is 2 show”2” on disp
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, LOW);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, LOW);
digitalWrite(segG, HIGH);
break;
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, HIGH);
break;
digitalWrite(segA, LOW);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
81 |B u k u A p p r o v e
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
break;
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
82 |B u k u A p p r o v e
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;
break;
if (COUNT<10)
COUNT++;
if (COUNT==10)
delay(1000);
83 |B u k u A p p r o v e
PROJECT 28
ARDUINO DENGAN 4 DIGIT SEVEN SEGMENT
Pada Tutorial ini kita akan membuat lampu Seven Segment 4 Bit
Alat :
1x Arduino Uno
1x Temperature Sensor (I’m using the LM335Z)
1x 4 Digit 7 Segment Display (common anode)
1x 74HC595 8 Bit Shift Register
8x 220 Ohm Resistors
1x 4700 ohm Resistor
1x Breadboard (or two)
Jumper Cables
84 |B u k u A p p r o v e
Program yang digunakan
const int digitPins[4] = {7,6,5,4}; //4 common CATHODE
pins of the display (inverted the pins order)
const int clockPin = 11; //74HC595 Pin 11
const int latchPin = 12; //74HC595 Pin 12
const int dataPin = 13; //74HC595 Pin 14
const int tempPin = A0; //temperature sensor pin
const byte digit[10] = //seven segment digits in
bits
{
B00111111, //0
B00000110, //1
B01011011, //2
B01001111, //3
B01100110, //4
B01101101, //5
B01111101, //6
B00000111, //7
B01111111, //8
B01101111 //9
};
int digitBuffer[4] = {0};
int digitScan = 0;
float tempC; //Deleted kelvin and farenheit
void setup(){
for(int i=0;i<4;i++)
{
pinMode(digitPins[i],OUTPUT);
}
pinMode(tempPin, INPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(tempPin, INPUT);
//Serial.begin(9600);
}
delayMicroseconds(2);
85 |B u k u A p p r o v e
digitalWrite(latchPin, LOW);
if(digitScan==2)
shiftOut(dataPin, clockPin, MSBFIRST,
(digit[digitBuffer[digitScan]] | B10000000)); //print
the decimal point on the 3rd digit
else
shiftOut(dataPin, clockPin, MSBFIRST,
digit[digitBuffer[digitScan]]);
digitalWrite(latchPin, HIGH);
digitScan++;
if(digitScan>3) digitScan=0;
}
void loop(){
tempC = analogRead(tempPin)*0.00488; //multiplied
for this conversion constant
tempC = tempC*10000;
digitBuffer[3] = int(tempC)/1000;
digitBuffer[2] = (int(tempC)%1000)/100;
digitBuffer[1] = (int(tempC)%100)/10;
digitBuffer[0] = (int(tempC)%100)%10;
if (digitBuffer[0]>=5) {
digitBuffer[0] = 5;
}
else {
digitBuffer[0] = 0;
}
delay(4);
updateDisp();
86 |B u k u A p p r o v e
PROJECT 29
ARDUINO SEND & RECEIVE MESSAGE BY SIM900A DENGAN TAMPILAN
LCD, BUZZER DAN SENSOR ULTRASONIK
Pada project kali ini kita akan membuat Arduino bisa mengirim dan
menerima SMS ke nomor Handphone atau Smartphone yang dituju. Adapun
perlengkapan yang harus disiapkan adalah :
1. Arduino UNO / DFRDuino / Arduino Versi lainnya
2. SIM 900A
3. Breadboard / Papan Rangkaian
4. Wire
5. Potensiometer
6. Buzzer
7. LCD 16X2 Blue / Green
#include <SoftwareSerial.h>
SoftwareSerial GPRS(7, 8);
void setup()
{
GPRS.begin(9600);
Serial.begin(9600);
}
void loop()
{
while(GPRS.available())
{
buffer[count++]=GPRS.read();
if(count == 64) break;
}
87 |B u k u A p p r o v e
Serial.write(buffer,count);
clearBufferArray();
count = 0;
if(Serial.available()) {
byte b =Serial.read();
if (b == '#')
GPRS.write(0x1a);
else
GPRS.write(b);
}
}
void clearBufferArray()
{
for (int i=0; i<count;i++)
{
buffer[i]=NULL;
}
}
#include <SoftwareSerial.h>
SoftwareSerial GPRS(7, 8);
boolean state, lastState;
void setup()
{
pinMode(2, INPUT_PULLUP);
state = digitalRead(2);
lastState = state;
GPRS.begin(9600);
Serial.begin(9600);
GPRS.println("AT");
delay(1000);
}
void loop()
{
while(GPRS.available()) {
Serial.write(GPRS.read());
}
lastState=state;
state = digitalRead(2);
if (state != lastState) {
sendSMS();
}
delay(500);
}
void sendSMS() {
Serial.print("Switch was turned ");
Serial.println(state ? "on" : "off");
GPRS.println("AT+CMGF=1");
delay(500);
GPRS.println("AT+CMGS=\"+6281227103387\"");
delay(500);
GPRS.print("Switch was turned ");
GPRS.println(state ? "on" : "off");
GPRS.write(0x1a);
delay(500);
}
AT+CMGS="+31638740161" <ENTER>
88 |B u k u A p p r o v e
Nanti akan muncul tanda > , artinya masukkanlah suatu
string atau teks yang akan dikirimkan ke nomor hp tujuan.
AT+CMGL="ALL" <ENTER>
Maka akan muncul semua SMS yang masuk, kalau ingin hanya
pada waktu tertentu saja, missal 2, maka ditulis seperti
berikut :
AT+CMGR=2 <ENTER>
The modem will list the single message:
+CMGR: "REC READ","+31625012254",,"07/07/05,09:56:03+08"
Test message 2
OK
/*
HC-SR04 Ping distance sensor
VCC to arduino 5v GND to arduino GND
Echo to Arduino pin 9 Trig to Arduino pin 8
Buzzer +ve to Arduino pin 13 and GND to GND
Original code sourced from theorycircuit.com
Some code and wiring inspired by arduino.cc
*/
#include <SoftwareSerial.h>
#define trigPin 13
#define echoPin 11
#define Buzzer 12
void setup() {
Serial.begin (9600);
GPRS.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(Buzzer, OUTPUT);
GPRS.println("AT");
delay(1000);
}
void loop() {
while(GPRS.available()) {
Serial.write(GPRS.read());
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
89 |B u k u A p p r o v e
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
}
if (distance >=30 && distance <=199)
{
90 |B u k u A p p r o v e
Project 30.
Komunikasi Arduino Ke Android Via Bluetooth
Pada Percobaan kali ini kita akan membuat suatu komunikasi Microkontroller
Arduino dengan Android Phone lewat Bluetooth.
Aplikasi ini berguna untuk mendeteksi keluaran dari Sensor di Arduino dan
melakukan pengiriman data dari Mikrokontroller Arduino ke Perangkat Android
lewat Bluetooth.
1 x Arduino Uno
3 x 220 Ohm Resistrors
1 x Green LED
1 x Yellow LED
1 x Red LED
1 x TMP36 Temperature Sensor
1 x JY-MCU Bluetooth Slave Module (see introduction)
1 x Breadboard
wires
91 |B u k u A p p r o v e
A simple command structure enables the app to send parameters
and values to Arduino and the other way round.
The circuit:
* Yellow led on Pin 3 with 220 Ohm resistor in series
* Green led on Pin 4 with 220 Ohm resistor in series
* Red led on Pin 5 with 220 Ohm resistor in series
* T36 connected to 5V, Pin A0 and Gnd
* JY-MCU Bluetooth Wireless Serial Port Module (slave) connected
as follows:
VCC <--> 5V
GND <--> GND
TXD <--> Pin 0 (Rx)
RXD <--> Pin 1 (Tx)
The Bluetooth module may interfere with PC to Arduino
communication: disconnect VCC when programming the board
* the built-in led on Pin 13 is also used
created 2014
by Paolo Mosconi
// Command structure
// CMD RED|GREEN|YELLOW=ON|OFF
// CMD TMAX|SECONDS=value
// CMD SECONDS=value
// CMD STATUS
void setup(){
//start serial connection
92 |B u k u A p p r o v e
Serial.begin(9600);
Serial.print("Max T: ");
Serial.print(maxTemp);
Serial.print(" Sensor: ");
Serial.println(maxTempSensor);
inputString.reserve(50);
command.reserve(50);
value.reserve(50);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
pinMode(led3Pin, OUTPUT);
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, LOW);
digitalWrite(led3Pin, LOW);
/*
the following code is needed to initialize the timer interrupt
and set it to fire every second, the slowest that Arduino can do
for detailed information see:
http://www.instructables.com/id/Arduino-Timer-
Interrupts/step1/Prescalers-and-the-Compare-Match-Register/
*/
cli(); // disable global interrupts
93 |B u k u A p p r o v e
}
}
if (stringComplete) {
Serial.println(inputString);
boolean stringOK = false;
if (inputString.startsWith("CMD ")) {
inputString = inputString.substring(4);
int pos = inputString.indexOf('=');
if (pos > -1) {
command = inputString.substring(0, pos);
value = inputString.substring(pos+1,
inputString.length()-1); // extract command up to \n exluded
//Serial.println(command);
//Serial.println(value);
if (command.equals("RED")) { // RED=ON|OFF
value.equals("ON") ? digitalWrite(led3Pin, HIGH) :
digitalWrite(led3Pin, LOW);
stringOK = true;
}
else if (command.equals("GREEN")) { // GREEN=ON|OFF
value.equals("ON") ? digitalWrite(led2Pin, HIGH) :
digitalWrite(led2Pin, LOW);
stringOK = true;
}
else if (command.equals("YELLOW")) { // YELLOW=ON|OFF
value.equals("ON") ? digitalWrite(led1Pin, HIGH) :
digitalWrite(led1Pin, LOW);
stringOK = true;
}
else if (command.equals("TMAX")) { // TMAX=value
intValue = value.toInt();
if (intValue > 0) {
maxTemp = (float) intValue;
maxTempSensor = (int) ((maxTemp / 100 + .5) *
204.8);
stringOK = true;
}
}
else if (command.equals("SECONDS")) { // SECONDS=value
intValue = value.toInt();
if (intValue > 0) {
maxSeconds = intValue;
stringOK = true;
}
}
} // pos > -1
else if (inputString.startsWith("STATUS")) {
Serial.print("STATUS RED=");
Serial.println(digitalRead(led3Pin));
Serial.print("STATUS GREEN=");
Serial.println(digitalRead(led2Pin));
Serial.print("STATUS YELLOW=");
Serial.println(digitalRead(led1Pin));
Serial.print("STATUS TMAX=");
Serial.println(maxTemp);
Serial.print("STATUS SECONDS=");
Serial.println(maxSeconds);
94 |B u k u A p p r o v e
Serial.print("STATUS TEMP=");
Serial.println(temperature);
Serial.print("STATUS THIGH=");
Serial.println(tempHigh);
stringOK = true;
} // inputString.startsWith("STATUS")
} // inputString.startsWith("CMD ")
stringOK ? Serial.println("Command Executed") :
Serial.println("Invalid Command");
// clear the string for next iteration
inputString = "";
stringComplete = false;
} // stringComplete
if (statusReport) {
temperature = (tempVal * 0.0048828125 - .5) * 100;
Serial.print("STATUS TEMP=");
Serial.println(temperature);
Serial.print("STATUS THIGH=");
Serial.println(tempHigh);
statusReport = false;
}
/*
SerialEvent occurs whenever a new data comes in the
hardware serial RX. This routine is run between each
time loop() runs, so using delay inside loop can delay
response. Multiple bytes of data may be available.
*/
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
//Serial.write(inChar);
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline or a carriage
return, set a flag
// so the main loop can do something about it:
if (inChar == '\n' || inChar == '\r') {
stringComplete = true;
}
}
}
95 |B u k u A p p r o v e
96 |B u k u A p p r o v e
Project 31. Voice Recognition Modul
Voice Recognition Modul adalah modul yang digunakan untuk mengkonversi
Suara menjadi masukan berupa data digital dan bisa ditambahkan RGB LED
sebagai indikator .
void setup()
{
Serial.begin(9600);
pinMode(redPin, OUTPUT); // sets the redPin to be an output
pinMode(greenPin, OUTPUT); // sets the greenPin to be an output
pinMode(bluePin, OUTPUT); // sets the bluePin to be an output
delay(2000);
Serial.write(0xAA);
Serial.write(0x37);
delay(1000);
Serial.write(0xAA);
Serial.write(0x21);
97 |B u k u A p p r o v e
}
98 |B u k u A p p r o v e
PROJECT 32
ARDUINO DAN FINGERPRINT
99 |B u k u A p p r o v e
BSD license, all text above must be included in any redistribution
****************************************************/
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
int getFingerprintIDez();
void setup()
{
while (!Serial); // For Yun/Leo/Micro/Zero/...
Serial.begin(9600);
Serial.println("Adafruit finger detect test");
if (finger.verifyPassword()) {
Serial.println("Found fingerprint sensor!");
} else {
Serial.println("Did not find fingerprint sensor :(");
while (1);
}
Serial.println("Waiting for valid finger...");
}
uint8_t getFingerprintID() {
uint8_t p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.println("No finger detected");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
return p;
default:
Serial.println("Unknown error");
return p;
}
// OK success!
p = finger.image2Tz();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image converted");
break;
case FINGERPRINT_IMAGEMESS:
Serial.println("Image too messy");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
100 |B u k u A p p r o v e
case FINGERPRINT_FEATUREFAIL:
Serial.println("Could not find fingerprint features");
return p;
case FINGERPRINT_INVALIDIMAGE:
Serial.println("Could not find fingerprint features");
return p;
default:
Serial.println("Unknown error");
return p;
}
// OK converted!
p = finger.fingerFastSearch();
if (p == FINGERPRINT_OK) {
Serial.println("Found a print match!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
Serial.println("Communication error");
return p;
} else if (p == FINGERPRINT_NOTFOUND) {
Serial.println("Did not find a match");
return p;
} else {
Serial.println("Unknown error");
return p;
}
// found a match!
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
}
p = finger.image2Tz();
if (p != FINGERPRINT_OK) return -1;
p = finger.fingerFastSearch();
if (p != FINGERPRINT_OK) return -1;
// found a match!
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
return finger.fingerID;
}
101 |B u k u A p p r o v e
102 |B u k u A p p r o v e
103 |B u k u A p p r o v e