วันพุธที่ 4 ธันวาคม พ.ศ. 2556

Arduino + PID + RelayOutput +DHT11

/********************************************************
 * PID RelayOutput Example
 * Same as basic example, except that this time, the output
 * is going to a digital pin which (we presume) is controlling
 * a relay.  the pid is designed to Output an analog value,
 * but the relay can only be On/Off.
 *
 *   to connect them together we use "time proportioning
 * control"  it's essentially a really slow version of PWM.
 * first we decide on a window size (5000mS say.) we then
 * set the pid to adjust its output between 0 and that window
 * size.  lastly, we add some logic that translates the PID
 * output into "Relay On Time" with the remainder of the
 * window being "Relay Off Time"
 ********************************************************/

วันจันทร์ที่ 2 ธันวาคม พ.ศ. 2556

Arduino + PHP + Repeating Web client

/*
  Repeating Web client

 This sketch connects to a a web server and makes a request
 using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or
 the Adafruit Ethernet shield, either one will work, as long as it's got
 a Wiznet Ethernet module on board.

 This example uses DNS, by assigning the Ethernet client with a MAC address,
 IP address, and DNS address.

 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13

 created 19 Apr 2012
 by Tom Igoe

 http://arduino.cc/en/Tutorial/WebClientRepeating
 This code is in the public domain.

 */

วันเสาร์ที่ 30 พฤศจิกายน พ.ศ. 2556

การคำนวณหาค่าความต้านทานใช้ต่อ LED

- กำลังวัตต์ของความต้านทาน ใช้สูตร
P=Ir x Vr

โดยที่ P คือกำลังทนไฟฟ้าของความต้านทานมีหน่วยเป็นวัตต์ (W)

Ir = Id เนื่องจากการอนุกรมจะมีกระแสเท่ากัน
ค่ากระแสของ LED ของคุณ Joe ก็ 50mA
เพราะฉะนั้น Ir =50mA ด้วย

Vr แรงดันตกคร่อม R = (Vcc-Vd) ที่นี้ใช้ (6-2) = 4V

สรุป
ที่แรงดัน 6 V แรงดันตกคร่อม LED 2 V กระแสผ่าน LED = 50mA จะมีแรงดันคร่อม R = 4V

ค่า R =( Vcc-Vd ) / Id
= (6-2)/50mA
= 4/ 0.05
= 80 Ohm

เลือกใช้ค่าที่มีขายในท้องตลาด
คือ 86 Ohm หรือ 80.6 ohm

กำลังทนไฟฟ้า
P = Ir x Vr
= 50mA x 4V
= 0.2W
เลือกใช้ ที่ 1/4 W (0.25W)

หรือใช้สูตร p = I ยกกำลัง 2 x r
= 0.05 ยกกำลัง 2 x 80
= 0.2 W

หรือใช้สูตร p = E ยกกำลัง 2 / r

( E คือแรงดันตกคร่อมอุปกรณ์ที่เราต้องการคำนวณ ในที่นี้ คือแรงดันตกคร่อม R )

= (6-2) ยกกำลัง 2 / 80
= 16 / 80
= 0.2 W



สรุป ซื้อ ค่า R 80.6 Ohm 1% 1/4W
หรือ R 86 Ohm 5% 1/4W

ที่มา
http://www.atriumtech.com/cgi-bin/hilightcgi?Home=/home/InterWeb2000&File=/home2/searchdata/Forums/http/www.pantip.com/tech/electronics/topic/EE1643409/EE1643409.html

วันอาทิตย์ที่ 22 กันยายน พ.ศ. 2556

ใช้ Arduino กับ MP3 Module(WTV020SD-16P) ราคาประหยัด

โปรเจคนี้ผมตั้งใจใช้ Arduino กับ MP3 Module(WTV020SD-16P) เล่นไฟล์เพลงต่อเนื่องและวงรอบไปเรื่อยๆครับ

วันจันทร์ที่ 2 กันยายน พ.ศ. 2556

วันอังคารที่ 6 สิงหาคม พ.ศ. 2556

Arduino กับ RFID

/*
 * rfidrelay.c
 *
 * Signals HIGH voltage to a relay when a proper code is received from an RFID
 * swipe event, and switches the voltage back to LOW when the RFID card is
 * swiped again.
 *
 * Authors: Blake Beaupain & Andrew Stucky
 */

#include <SoftwareSerial.h>

#define rxPin 8
#define txPin 9
#define RFID_PIN 2
#define RELAY_PIN 5
#define NUM_CODES 2

// The transmitting flag
int TRANSMITTING = 0;

// The RFID chip code
char *expected_codes[NUM_CODES];

/*
 * Sets up the device
 */
void setup() {
 Serial.begin(2400); // Hardware serial for Monitor 2400bps
 expected_codes[0] = "8400336CFF";
 expected_codes[1] = "00005D7E5C";
 
 // Activate the RFID reader
 pinMode(RFID_PIN, OUTPUT);
 digitalWrite(RFID_PIN, LOW);
 
 // Activate the relay pin
 pinMode(RELAY_PIN, OUTPUT);
 analogWrite(RELAY_PIN, 0);
}

/*
 * Main logic loop
 */
void loop() {
SoftwareSerial RFID = SoftwareSerial(rxPin,txPin); 
RFID.begin(2400);

 // Read data from the chip
 if (RFID.available() > 0) {
  // Read the full code
  char code[10];
  int amount = 0;
  while (amount < 10) {
   int data = RFID.read();
   if (data == 10 || data == 13)
   { Serial.println("Incomplete packet"); return; }// Incomplete packet
   code[amount++] = data;
  }
  
  // Authenticate the code
  int i, n, found = 0;
  for (i = 0; i < NUM_CODES; i++) {
   char *c = expected_codes[i];
   for (n = 0; n < 10; n++)
    if (code[n] != c[n])
     continue;
   found = 1;
   Serial.println("Pass"); //Passed Auth
  }
  if (found == 0)
  Serial.println("Fail"); //Failed Auth
    
  // Toggle the transmitting flag
  TRANSMITTING ^= 1;
  
  // Apply the proper voltage to the relay pin
  if (TRANSMITTING) {
   // Set to high voltage
   analogWrite(RELAY_PIN, 255);
  } else {
   // Set to low voltage
   analogWrite(RELAY_PIN, 0);
  }
  
  // Disable the RFID chip temporarily
  digitalWrite(RFID_PIN, HIGH);
  delay(2000);
  digitalWrite(RFID_PIN, LOW);
 }
}

ที่มา 
http://forum.arduino.cc/index.php/topic,87305.0.html

########################################################################
## Modified code to work with Arduino 1.0.1      /     ## 
## Credits to Petushka, http://www.instructables.com/member/Petushka/ ##
##                  ##
########################################################################

#include <SoftwareSerial.h>

#define ADD_TAG_CODE "210014DFE309"  //change this ID with your own card TAG
#define DEL_TAG_CODE "210014E2BD6A"  //change this ID with your own card TAG

SoftwareSerial rfid = SoftwareSerial(5, 6);
String msg;
String ID ;  //string to store allowed cards

void setup()  
{
  Serial.begin(9600);
  Serial.println("Serial Ready");

  rfid.begin(9600);
  Serial.println("RFID Ready");
}

char c;

void loop(){
  
  while(rfid.available()>0){
    c=rfid.read(); 
    msg += c;
    Serial.println(msg);  
    Serial.println(msg.length());
  }
  msg=msg.substring(1,13);
  if(msg.indexOf(ADD_TAG_CODE)>=0) add(); 
  else if(msg.indexOf(DEL_TAG_CODE)>=0) del();  
  else if(msg.length()>10) verifica();
  msg="";
  
}

void add(){
  Serial.print("What TAG do you wanna grant access?: ");
  msg="";
  while(msg.length()<13){
    while(rfid.available()>0){
      c=rfid.read(); 
      msg += c;
    }
  }
  if(ID.indexOf(msg)>=0) {
    Serial.println("\nAccess already granted for this card.");
    msg="";
  }
  else{
    Serial.print("Card: ");
    Serial.println(msg); 
    ID += msg;
    ID += ",";
    //Serial.print("ID: ");
   // Serial.println(ID);
    msg="";
    Serial.println("Access granted for this card.");
  }

}

void del(){
  msg="";
  Serial.print("What TAG do you wanna deny access?: ");
  while(msg.length()<13){
    while(rfid.available()>0){
      c=rfid.read(); 
      msg += c;
    }
  }
  msg=msg.substring(1,13);
  if(ID.indexOf(msg)>=0){
    Serial.println(msg);
    Serial.println("TAG found. Access for this card denied.");
    //ID.replace(card,"");
    int pos=ID.indexOf(msg);
    msg="";
    msg += ID.substring(0,pos);
    msg += ID.substring(pos+15,ID.length());
    ID="";
    ID += msg;
    //Serial.print("ID: ");
    //Serial.println(ID);
  } else Serial.println("\nTAG not found or already denied");
  msg="";
}

void verifica(){
    msg=msg.substring(1,13);
    if(ID.indexOf(msg)>=0) Serial.println("Access granted.");
    
    else Serial.println("Access denied.");
}


ที่มา 
http://www.instructables.com/files/orig/FM4/KU9W/H91LGBA6/FM4KU9WH91LGBA6.txt



#include <SoftwareSerial.h>
#include <SimpleTimer.h>

#define TAG_CODE "0800683B9BC0"  //change this ID with your own card TAG
int led3 = 3;
int wd_timer_id;
// The transmitting flag
int TRANSMITTING = 0;

SoftwareSerial rfid = SoftwareSerial(8, 9);
String msg;
String ID ;  //string to store allowed cards

SimpleTimer timer;

// function to be called just once
void OnceOnlyTask() {
  Serial.println("This timer only triggers once");  
 digitalWrite(led3, LOW); 
}

void setup()  
{
  Serial.begin(9600);
  Serial.println("Serial Ready");

  rfid.begin(9600);
  Serial.println("RFID Ready");
  
  pinMode(led3, OUTPUT); 
}

char c;

void loop(){
timer.run();
if(rfid.available()>0){
  while(rfid.available()>0){
    c=rfid.read(); 
    msg += c;
   // Serial.println(msg);  
   // Serial.println(msg.length());
  }
  msg=msg.substring(1,13);
  if(msg.length()==12) 
  Serial.println(msg);  
  ID = msg;
  msg="";
  if (ID.indexOf(TAG_CODE)>=0){
    Serial.println(ID);
    digitalWrite(led3, HIGH); 
    timer.deleteTimer(wd_timer_id);
    delay(1000);
    TRANSMITTING = 1;
  }


}else{
    //Serial.println(ID);
    if(TRANSMITTING){
      if(timer.getNumTimers()<=0){
                      timer.enable(wd_timer_id);
                      timer.setTimeout(5000, OnceOnlyTask);
      }
      TRANSMITTING = 0;
    }
  }
  
}

วันอังคารที่ 23 กรกฎาคม พ.ศ. 2556

สร้างหุ่นยนต์ด้วย Arduino ตอนที่ 1 ฝึกให้หุ่นยนต์หลบหลีกสิ่งกีดขวาง

วันนี้ก็จะเริ่มทดลองใช้ Arduino รุ่น UNO R3 MEGA328P เป็นตัวประมวลผล, Servo ในส่วนเคลื่อนที่ซ้าย-ขวา และ Ping Ultrasonic Sensor (HC-SR04) เป็นตัว Sensor ว่าหุ่นยนต์อยู่ในระยะไหนจากวัตถุ  ผลออกมาเป็นที่น่าพอใจ

วันจันทร์ที่ 1 กรกฎาคม พ.ศ. 2556

การคำนวณแรงบิด กำลังและประสิทธิภาพของมอเตอร์ไฟฟ้ากระแสตรง

         การคำนวณแรงบิด กำลังและประสิทธิภาพของมอเตอร์ไฟฟ้ากระแสตรง
แรงบิด(Torque)                                T   =   F x R                     (N.M.)
งานที่ได้จากแรงใน 1 รอบการหมุน
                                                                     =   แรง x ระยะทาง
                                                                     =    F x 2pr                 (Jule)
กำลังที่เกิดขึ้น(PO)                                    =    F x 2pr x N/60    (Jule/s)
                                                                     =    (F x r)(2pN/60)  (Jule/s)
เมื่อความเร็วเชิงมุม                            v =    2pN/60                  (Rad/s)
ดังนั้น    กำลังที่เกิดขึ้น(PO)                                 =     T x v                   (Jule/s, W)
              กำลังไฟฟ้า(P)                                        =     V x I                      (W)
              ประสิทธิภาพ(h)                                  =     (PO/PI) x100
เมื่อ                                        PO   =   กำลังด้านเอาท์พุท

                                                PI   =   กำลังด้านอินพุท

วันเสาร์ที่ 15 มิถุนายน พ.ศ. 2556

ตัวอย่างที่น่าสนใจเกี่ยวกับ W5100

- Webserver + Ajex + LED + Switch
http://startingelectronics.com/tutorials/arduino/ethernet-shield-web-server-tutorial/SD-card-IO/

ใช้ Arduino + W5100 กับ Servo มอเตอร์


//zoomkat 3-17-12
//simple button GET server code to control servo and arduino pin 5
//for use with IDE 1.0
//open serial monitor to see what the arduino receives
//use the \ slash to escape the " in the html 
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields
//Powering a servo from the arduino usually DOES NOT WORK.
//note that the below bug fix may be required
// http://code.google.com/p/arduino/issues/detail?id=605 

วันพุธที่ 12 มิถุนายน พ.ศ. 2556

ใช้ Arduino + W5100 เปิดปิด Relay

/*
Control 2 relays over Ethernet (Ethernet shield)
Supports DHCP
Relays are connected to pins 6 (relay 1) and 7 (relay 2). More relays can be added by putting their pin numbers to the relayPins array
Listening on TCP/IP port 22000
Control command syntax: R([aa],[bb])<CR><LF> where [aa]= relay number 00 for both, 01 or 02. [bb] is 00 (off) or 01 (on)
Response: OK<CR><LF> or ERROR<CR><LF> if a bad relay number or command is given
Multiple commands may be given. The server closes the client socket after 30s inactivity timeout
*/

ใช้ Arduino + ENC28J60 เปิดปิด Relay

ENC28J60 Ethernet Module utilizes the new Microchip ENC28J60 Stand-Alone Ethernet Controller IC featuring a host of features to handle most of the network protocol requirements. This Ethernet LAN module connects directly to most microcontrollers.
Description:
  • Ethernet LAN Module for Arduino/AVR/LPC/STM3
  • ENC28J60 Ethernet chips
  • Can be easily mounted with the MCU
  • Network Interface: HR911105A
  • Supply Voltage: 3.3 V (5V Tolerant DIO)
  • 25Mhz crystal oscillator
  • Size (L x W x H): Approx. 2.3 x 1.3 x 0.7 inch / 58 x 34 x 17 mm