บทความ

กำลังแสดงโพสต์จาก กันยายน, 2018

ปรับแก้คะแนน แยกอธิบายส่วนต่างๆ

รูปภาพ
HARDWARE 1.Arduino uno r3 2.Bluetooth hc 06 3.2N2222 4.1N4007 5.Relay 6.Load 7.Res INPUT 1.Telephon 2.Bluetooth hc-06 MCU 1.Arduino UNO R3 OUTPUT 1.Relay 2.Load SOFTWARE #include <SoftwareSerial.h> //กำหนดเรียกใช้ใน ไลบรารี่ Bluetooth const int rxPin = 4; //กำหนดไปที่ rxPinขา4 const int txPin = 2; //กำหนดไปที่ txPinขา2          SoftwareSerial mySerial(rxPin, txPin); //ไว้ใช้กำหนดค่าลงใน ไลบรารี่ Bluetooth const int Loads[] = {9, 10, 11, 12}; //ตัวแปรอาเรย์ int state = 0; //นี่คือตัวแปล state = 0 int flag = 0; ////นี่คือตัวแปล flag = 0 void setup() //เป็นฟังก์ชั่นแรกที่เมื่อ Arduino ทำงานแล้วจะเรียกเพื่อทำการ setup ค่าตามจุดประสงค์ของฟังก์ชั่น  { for (int i=0;i<4;i++) //int=0<4และi+เรื่อยๆ { pinMode(Loads[i], OUTPUT); //สั่งกำหนดใช้ Load เก็บค่าตัวแปร อาเรย์ i เป็น OUTPUT ครับ } mySerial.begin(9600); //แสดงค่าออกทาง Serial Monitor for (int i=0;i<4;i++) //int=0<4และi+เรื่อยๆ { digitalWrite(Loads[i], LOW); //Load[i]เป็นLOW } } void lo

งานปฏิบัติ 15

รูปภาพ
Code1 #include <LedControl.h> #include <DHT11.h> int pin=4; DHT11 dht11(pin); LedControl lc=LedControl(8,10,9,1); // Pin 8->DIN, 10->CLK, 9->CS(LOAD), 1 = No.of devices void show2digit(int h,int t) {   int seg1,seg2,seg3,seg4;   seg1 = h%10;   seg2 = h/10;   lc.setDigit(0,4,seg1,false);   lc.setDigit(0,5,seg2,false);   seg3 = t%10;   seg4 = t/10;   lc.setDigit(0,0,seg3,false);   lc.setDigit(0,1,seg4,false);   delay(300); } void setup() {   Serial.begin(9600);   while (!Serial) {       ; // wait for serial port to connect. Needed for Leonardo only     }   lc.shutdown(0,false);    lc.setIntensity(0,5);   lc.clearDisplay(0); } void loop() {   int err;   float temp, humi;   if((err=dht11.read(humi, temp))==0)   {     Serial.print("temperature:");     Serial.print(temp);     Serial.print(" humidity:");     Serial.print(humi);     Serial.println();       }   else   {     Serial.println();     Serial.prin

งานปฏิบัติ 14

รูปภาพ
Code 1 #include <LedControl.h> #include <OneWire.h> #include <DallasTemperature.h> #define ONE_WIRE_BUS 11 OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); float Tfloat; long Tint; LedControl lc=LedControl(8,10,9,1);  // Pin 8->DIN, 10->CLK, 9->CS(LOAD), 1 = No.of devices void show6digit(int num) {   int seg1,seg2;   seg2 = (((((num%100000)%10000)%1000)%100)/10);   seg1 = (((((num%100000)%10000)%1000)%100)%10);   lc.setDigit(0,0,seg1,false);    if (num>=10)       lc.setDigit(0,1,seg2,false);   delay(300); } void setup(void) {   sensors.begin();   lc.shutdown(0,false);     lc.setIntensity(0,5);    lc.clearDisplay(0); }  void loop(void) {   sensors.requestTemperatures();    Tfloat = sensors.getTempCByIndex(0);   Tint = int(Tfloat);   lc.clearDisplay(0);   show6digit(Tint); } Code 2 #include <LedControl.h> #include <OneWire.h> #include <D

งานปฏิบัติ 13

รูปภาพ
Code 1 #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,16,2); int PIRpin = 8; void setup()  {    lcd.begin();   pinMode(PIRpin,INPUT);   lcd.home();   lcd.print("Waiting for PIR");   delay(10000);          lcd.clear(); } void loop() {    int x = digitalRead(PIRpin);   lcd.home();   lcd.print("PIR = ");   lcd.print(x);   delay(100); }

งานปฏิบัติ 12

รูปภาพ
Code 1 #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,16,2); int triggerPin = 13; int echoPin = 12; long duration,distCM,temp_distCM=0; void setup()  {   lcd.begin();   lcd.setCursor(0,0);   lcd.print("Dist =      cm");   pinMode(triggerPin,OUTPUT);   pinMode(echoPin,INPUT); } void loop()  {   digitalWrite(triggerPin,LOW);   delayMicroseconds(2);   digitalWrite(triggerPin,HIGH);   delayMicroseconds(10);   digitalWrite(triggerPin,LOW);   duration = pulseIn(echoPin,HIGH);   distCM = duration/58;   if (temp_distCM != distCM)   {     lcd.setCursor(7,0);     lcd.print("    ");   }   lcd.setCursor(7,0);   lcd.print(distCM);   temp_distCM = distCM;   delay(300); } Code 2 #include <LiquidCrystal_I2C.h> LiquidCrystal_I2C lcd(0x27,16,2); int triggerPin = 13; int echoPin = 12; long duration,distCM; void setup()  {   lcd.begin();   pinMode(triggerPin,OUTPUT);   pinMod

MINI project arduino เปิดปิดไฟบ้านด้วยบลูทูธ hc-05

รูปภาพ
เปิด-ปิดไฟบ้านด้วย บลูทูธ HC-05 อุ ปกรณ์           1. arduino nano            2. bluetooth module hc-05           3. relay 5v 3 channal           4.หลอดไฟ 220V           5. แป้นฐานหลอดไฟ Wiri ng diagram Block การต่อสาย Wiring diagram Bluetooth    Rx = 11    Tx = 10    Vcc = 5v    Gnd = Gnd Relay    Ch1 = A1    Ch2 = A0    Vcc = 5v    Gnd = Gnd Code #include <SoftwareSerial.h>//เป็นการเรียกใช้ไลบรารี่ SoftwareSerial.h SoftwareSerial mySerial(10, 11); // RX, TX//ฟังก์ชั่นรับสัญญาณเข้าออกแบบอนุกรม const int relay1=A1;//เป็นตัวแปรชนิด อินทิเจอร์ const int relay2=A0;//เป็นตัวแปรชนิด อินทิเจอร์ const int led1=A2;//เป็นตัวแปรชนิด อินทิเจอร์ const int led2=A3;//เป็นตัวแปรชนิด อินทิเจอร์ void setup() { pinMode(relay1,OUTPUT);// รีเลย์1เป็นเอาท์พุต pinMode(relay2,OUTPUT);// รีเลย์2เป็นเอาท์พุต pinMode(led1,OUTPUT);// led 1 เป็นเอาท์พุต pinMode(led2,OUTPUT);// led 2 เป็นเอาท์พุต digitalWrite(relay1,LOW);//คำสั่ง r