Friday, August 21, 2015

Infrared with interrupt

const int irRelayPin = 4; // the number of the pushbutton pin
const int alarmPin = 13; // the number of the Buzzer pin
// variables will change:
int irState = 0; // variable for reading the pushbutton status
void setup() {
attachInterrupt(0, stopAlarm, FALLING);
// initialize the LED pin as an output:
pinMode(alarmPin, OUTPUT); 
// initialize the pushbutton pin as an input:
pinMode(irRelayPin, INPUT); 
}
void loop(){
// read the state of the pushbutton value:
irState = digitalRead(irRelayPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (irState == HIGH) { 
// turn LED on: 
digitalWrite(alarmPin, HIGH); 
//Serial.println("alarm");
delay(10 * 60 * 1000); //bunyikan alarm selama 10 menit
digitalWrite(alarmPin, LOW); //matiin

}
void stopAlarm(){
digitalWrite(alarmPin, LOW); //stop alarm
}

PIR alarm with interrupt


int calibrationTime = 10; 


//the time when the sensor outputs a low impulse
long unsigned int lowIn; 

//the amount of milliseconds the sensor has to be low 
//before we assume all motion has stopped
long unsigned int pause = 5000; 

boolean lockLow = true;
boolean takeLowTime; 

int pirPin = 6; //the digital pin connected to the PIR sensor's output
int ledPin = 10;
int resetbutton = 2;
volatile boolean buttonState=1;
volatile int buttonState1=1;

/////////////////////////////
//SETUP
void setup(){
Serial.begin(9600);
pinMode(resetbutton, INPUT); // Pin 2 is input to which a switch is connected = INT0
attachInterrupt(0, disarm, CHANGE); 
pinMode(pirPin, INPUT); //input pin
pinMode(ledPin, OUTPUT); //alarm pin
digitalWrite(pirPin, LOW);
buttonState = digitalRead(resetbutton);
//give the sensor some time to calibrate
Serial.print("calibrating sensor ");
for(int i = 0; i < calibrationTime; i++){
Serial.print(".");
delay(1000);
}
Serial.println(" done");
Serial.println("SENSOR ACTIVE");
delay(50);
}

////////////////////////////
//LOOP
void loop(){

if(digitalRead(pirPin) == HIGH){
digitalWrite(ledPin, HIGH); //the led visualizes the sensors output pin state
//makes sure we wait for a transition to LOW before any further output is made:
lockLow = false; 
Serial.println("---");
//Serial.print("motion detected at ");
//Serial.print(millis()/1000);
//Serial.println(" sec"); 
for(int i=0;i<30;i++){
delay(1000);
if(buttonState1 == 0){ //jika ada interupt
buttonState1 = 1;
digitalWrite(ledPin, LOW);
break; //keluar dari loop for

}
digitalWrite(ledPin, LOW);
}
}
void disarm(){
buttonState1 =0;
}

Friday, July 3, 2015

FINGERPRINT R-308 PINOUT | FINGER SCANNER R-308 SENSOR MODULE PINOUT

This documentation is for fingerprint R308 sensor module

Pin No.                Description                                Remarks
6                          finger detect power +                 3.6-5V
5                          finger detection signal output      high active
4                          Power +                                  Power Positive
3                          module sends                            TX
2                          module receives                         RX
1                          power -                                   power negative

sample code can be search at google

Friday, April 19, 2013

ARDUINO INJECT TO MYSQL DATABASE

(this content for my personal documentation only)

Introducing MySQL Connector/Arduino

Have you ever wanted to use a local database server to store data from your Arduino projects? Would you like to be able to send queries directly to a MySQL database from your Arduino sketch? Well, now you can!

The MySQL Connector/Arduino is a new technology made for the Arduino permitting you to connect your Arduino project to a MySQL server via an Ethernet shield without using an intermediate computer or a web-based service. 
Having direct access to a database server means you can store data acquired from your project as well as check values stored in tables on the server and keep the network local to your facility including having a network that isn't connected to the internet or any other network.


Example Code

The Connector/Arduino is an Arduino library that encapsulates everything you need to communicate with a MySQL server. It's also very easy to use. The following shows a simple sketch to connect to a MySQL server and insert a row of data at startup.

/**
* Example: Hello, MySQL!
*
* This code module demonstrates how to create a simple 
* database-enabled sketch.
*/
#include "SPI.h"
#include "Ethernet.h"
#include "sha1.h"
#include "mysql.h"


/* Setup for Ethernet Library */
byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server_addr(10, 0, 1, 23);

/* Setup for the Connector/Arduino */
Connector my_conn; // The Connector/Arduino reference

char user[] = "root";
char password[] = "secret";
char INSERT_SQL[] = 
 "INSERT INTO test_arduino.hello VALUES ('Hello, MySQL!', NULL)";

void setup() {
  Ethernet.begin(mac_addr);
  Serial.begin(115200);
  delay(1000);
  Serial.println("Connecting...");
  if (my_conn.mysql_connect(server_addr, 3306, user, password))
  {
    delay(500);
     /* Write Hello, World to MySQL table test_arduino.hello */
     my_conn.cmd_query(INSERT_SQL);
     Serial.println("Query Success!");
  }
  else
    Serial.println("Connection failed.");
}

void loop() {
}


As you can see, the library adds very few methods for communicating with a MySQL server.




source link :
http://drcharlesbell.blogspot.com/2013/04/introducing-mysql-connectorarduino_6.html




Friday, August 17, 2012

Tiniest arduino | Smallest arduino





Tiniest arduino | Smallest arduino

From website :
http://hlt.media.mit.edu/?p=1695


This tutorial shows you how to program an ATtiny45, ATtiny85, ATtiny44 or ATtiny84 microcontroller using the Arduino software (version 1.0.1). These are small, cheap ($2-3) microcontrollers that are convenient for running simple programs. The ATtiny45 and ATtiny85 have eight legs and are almost identical, except that the ATtiny85 has twice the memory of the ATtiny45 and can therefore hold more complex programs. The ATtiny44 and ATtiny84 have 14-legs and more inputs and outputs. Thanks to Mark Sproul for his work on making the Arduino core portable across processors.
Materials and Tools


For this tutorial, you’ll need:
An in-system programmer (ISP), a piece of hardware used to load programs onto the ATtiny. Options include:


A commercial programmer like the AVRISP mkII or USBtinyISP.
a Arduino Uno or Duemilanove (w/ an ATmega328, not an older board with an ATmega168). See this tutorial for using an Arduino board as a programmer
the TinyProgrammer, a board that we’ve developed to make it as easy as possible to program the ATtiny45 and 85.
ATtiny45 or ATtiny85 (8-pin DIP package) or an ATtiny44 or ATtiny84.
a solderless breadboard and jumper wires (unless you’re using the TinyProgrammer w/ the ATtiny45 or 85)


For more information, see our list of materials and parts and our list of prototyping supplies.
Software


You’ll need the Arduino software, version 1.0.1. (Instructions for Arduino 0022 are also available.) You can download Arduino 1.0.1 from the Arduino site. Installation instructions are available for Windows and for Mac OS X.


Download: Arduino 1.0.1 and the ATtiny zip (from this GitHub repository)
Installing ATtiny support in Arduino
Download: ATtiny (from this GitHub repository)
Locate your Arduino sketchbook folder (you can find its location in the preferences dialog in the Arduino software)
Create a new sub-folder called “hardware” in the sketchbook folder.
Copy the attiny folder from inside the .zip to the hardware folder. You should end up with folder structure like Documents > Arduino > hardware > attiny that contains the fileboards.txt and another folder called variants.
Restart the Arduino development environment.
You should see ATtiny entries in the Tools > Board menu.




Connecting the ATtiny


You’ll need to provide power to the ATtiny and connect it to your programmer. That is, connecting MISO, MOSI, SCK, RESET, VCC, and GND of the programmer to the corresponding pins on the ATtiny. (Or, if you’re using an circuit w/ an ATtiny, simply connect the programmer to the ISP header on the board – you may also need to power the board separately.)


Instructions and diagrams are available for:








Configuring the ATtiny to run at 8 MHz (for SoftwareSerial support)


By default, the ATtiny’s run at 1 MHz (the setting used by the unmodified “ATtiny45″, etc. board menu items). You need to do an extra step to configure the microcontroller to run at 8 MHz – necessary for use of the SoftwareSerial library. Once you have the microcontroller connected, select the appropriate item from the Boards menu (e.g. “ATtiny45 (8 MHz)”). Then, run the “Burn Bootloader” command from the Tools menu. This configures the fuse bits of the microcontroller so it runs at 8 MHz. Note that the fuse bits keep their value until you explicitly change them, so you’ll only need to do this step once for each microcontroller. (Note this doesn’t actually burn a bootloader onto the board; you’ll still need to upload new programs using an external programmer.)
Programming the ATtiny


Next, we can use the Arduino as an ISP to upload a program to the ATtiny:




Open the Blink sketch from the examples menu.
  • Change the pin numbers from 13 to 0.
  • Select the appropriate item from the Tools > Board menu (leave the serial port set to that of your Arduino board).
  • Select the appropriate item from the Tools > Programmer menu (e.g. “Arduino as ISP” if you’re using an Arduino board as the programmer, USBtinyISP for the USBtinyISP, FabISP, or TinyProgrammer, etc).
  • Upload the sketch.

You should see “Done uploading.” in the Arduino software and no error messages. If you then connect an LED between pin 0 and ground, you should see it blink on and off. Note that you may need to disconnect the LED before uploading a new program.
ATtiny Microcontroller Pin-Outs






Reference


The following Arduino commands should be supported:
pinMode()
digitalWrite()
digitalRead()
analogRead()
analogWrite()
shiftOut()
pulseIn()
millis()
micros()
delay()
delayMicroseconds()
SoftwareSerial (has been updated in Arduino 1.0)
References
arduino-tiny: alternative approach to ATtiny support for Arduino
TinyWireM & TinyWireS: Wire (I2C / TWI) library for the ATtiny85 (using USI)