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

Arduino 12

Activated Home Automation Project by using Arduino For Smart Home





Components Required

  • Arduino UNO x 1
  • HC – 05 Bluetooth Module x 1
  • Smart Phone or Tablet x 1
  • 2N2222 NPN Transistor x 4
  • 12V Relay x 4
  • 1 KΩ Resistor x 4
  • 1N4007 PN Junction Diode x 4
  • Power Supply
  • Connecting Wires
  • Breadboard (Prototyping Board)
  • App for transmitting voice to Bluetooth

Source Code: 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<pre>#include <SoftwareSerial.h>
 
const int rxPin = 2;
const int txPin = 3;              
SoftwareSerial mySerial(rxPin, txPin);
 
int ac=4;
int light=5;
int fan=6;
int tv=7;
String data;
 
void setup()
{
   Serial.begin(9600);
   mySerial.begin(9600);
    
   pinMode(ac, OUTPUT);
   pinMode(light, OUTPUT);
   pinMode(fan, OUTPUT);
   pinMode(tv, OUTPUT);
  
   digitalWrite(ac, LOW);
   digitalWrite(light, LOW);
   digitalWrite(fan, LOW);
   digitalWrite(tv, LOW);
}
 
void loop()
{
    int i=0;
    char ch=0;
    data="";
    while(1)
    {
      while(mySerial.available()<=0);
      ch = mySerial.read();
      if(ch=='#')
      break;
      data+=ch;
    }
   Serial.println(data);
     
    if(data=="*turn on AC")
    {
      digitalWrite(ac,HIGH);
      Serial.println("ac on");
    }
    else if(data=="*turn off AC")
    {
      digitalWrite(ac,LOW);
      Serial.println("ac off");
    }
    else if(data=="*turn on light")
    {
      digitalWrite(light,HIGH);
      Serial.println("light on");
    }
    else if(data=="*turn off light")
    {
      digitalWrite(light,LOW);
      Serial.println("light off");
    }
    else if(data=="*turn on fan")
    {
      digitalWrite(fan,HIGH);
      Serial.println("fan on");
    }
    else if(data=="*turn off fan")
    {
      digitalWrite(fan,LOW);
      Serial.println("fan off");
    }
    else if(data=="*turn on TV")
    {
      digitalWrite(tv,HIGH);
      Serial.println("tv on");
    }
    else if(data=="*turn on TV")
    {
      digitalWrite(tv,LOW);
      Serial.println("tv off");
    }
    else if(data=="*turn on all")
    {
      digitalWrite(ac,HIGH);
      digitalWrite(light,HIGH);
      digitalWrite(fan,HIGH);
      digitalWrite(tv,HIGH);
      Serial.println("all on");
    }
    else if(data=="*turn off all")
    {
      digitalWrite(ac,LOW);
      digitalWrite(light,LOW);
      digitalWrite(fan,LOW);
      digitalWrite(tv,LOW);
      Serial.println("all off");
     
    }
     
}

Arduino 11

เครื่องวัดปริมาณเเอลกอฮอล์




#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
const int buttonPin = 2;
const int buzzerPin = 7;
const int AOUTpin=0;//the AOUT pin of the alcohol sensor goes into analog pin A0 of the arduino
const int DOUTpin=8;//the DOUT pin of the alcohol sensor goes into digital pin D8 of the arduino
const int ledPin=13;//the anode of the LED connects to digital pin D13 of the arduino
int ledpin1 = 3;
int ledpin2 = 4;
int ledpin3 = 5;
int limit;
int value;
int buttonState = 0;
void setup() {
Serial.begin(9600);
 lcd.init();
 lcd.backlight();
pinMode(buttonPin, INPUT);
pinMode(buzzerPin,OUTPUT);
pinMode(DOUTpin, INPUT);//sets the pin as an input to the arduino
pinMode(ledpin1, OUTPUT);
pinMode(ledpin2, OUTPUT);
pinMode(ledpin3, OUTPUT);//sets the pin as an output of the arduino
}
void loop(){
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
value= analogRead(AOUTpin);//reads the analaog value from the alcohol sensor's AOUT pin
  Serial.println(value);
 if(value<200)
  {
      Serial.println("You are fine.");
      lcd.print("Result ");
      lcd.print(value);
      lcd.setCursor(0,1);
      lcd.print("You are fine.");
      digitalWrite(buzzerPin,LOW);
      digitalWrite(ledpin1, HIGH);
      delay(1000);
      digitalWrite(buzzerPin,HIGH);
      digitalWrite(ledpin1, LOW);
  }
  if (value>=200 && value<280)
  {
      Serial.println("Alcohol detected");
      lcd.print("Result ");
      lcd.print(value);
      lcd.setCursor(0,1);
      lcd.print("Alcohol Detected");
      digitalWrite(buzzerPin,LOW);
      digitalWrite(ledpin2, HIGH);
      delay(750);
      digitalWrite(buzzerPin,HIGH);
      digitalWrite(ledpin2, LOW);
  }
  if (value>=280 && value<350)
  {
      Serial.println("Just A Little.");
      lcd.print("Result ");
      lcd.print(value);
      lcd.setCursor(0,1);
      lcd.print("Just A Little.");
      digitalWrite(buzzerPin,LOW);
      digitalWrite(ledpin2, HIGH);
      delay(500);
      digitalWrite(buzzerPin,HIGH);
      digitalWrite(ledpin2, LOW);
  }
  if (value>=350 && value <450)
  {
      Serial.println("Serious Booze here! ");
      lcd.print("Result ");
      lcd.print(value);
      lcd.setCursor(0,1);
      lcd.print("No More Drink!");
      digitalWrite(buzzerPin,LOW);
      digitalWrite(ledpin3, HIGH);
      delay(250);
      digitalWrite(buzzerPin,HIGH);
      digitalWrite(ledpin3, LOW);
  }
  if(value>450)
  {
     Serial.println("You are drunk!");
     lcd.print("Result ");
     lcd.print(value);
     lcd.setCursor(0,1);
     lcd.print("R.I.P");
     digitalWrite(buzzerPin,LOW);
     digitalWrite(ledpin3, HIGH);
  }
  delay (500);
  lcd.clear();
}
else{
  lcd.setCursor(0,0);
  lcd.print("Alcohor Meter");
  lcd.setCursor(0,1);
  lcd.print("Press Button...");
  digitalWrite(buzzerPin,HIGH);
  delay(500);
  lcd.clear();
  }
}



Arduino 10

Arduino Motion Detector using PIR Sensor




Arduino Motion Detector using PIR Sensor


อุปกรณ์ที่ใช้

  1. PIR Sensor Module
  2. Arduino UNO (any version)
  3. LED
  4. Buzzer
  5. Breadboard
  6. Connecting Wires
  7. 330 ohm resistor

code


void setup() {

  pinMode(2, INPUT); //Pin 2 as INPUT
  pinMode(3, OUTPUT); //PIN 3 as OUTPUT
}

void loop() {
  if (digitalRead(2) == HIGH)
  {
  digitalWrite(3, HIGH);   // turn the LED/Buzz ON
  delay(100);                       // wait for 100 msecond 
  digitalWrite(3, LOW);   // turn the LED/Buzz OFF
  delay(100);                       // wait for 100 msecond 
  }
}

Arduino 9

หุ่นยนต์เดินตามเส้น 2 เซ็นเซอร์ Arduino



     อุปกรณ์ที่ต้องใช้ก็คือ


  
     2. Arduino UNO R3 - Made in italy    

    
     4. Motor Drive Module L298N    

    

    
    
      








ตัวอย่างโค้ด Arduino

 /*-------definning Inputs------*/
int LS = 2;     // left sensor
int RS  = 3;      // right sensor

/*-------definning Outputs------*/
int LM1 = 4;      // left motor
int LM2 =  5;       // left motor
int RM1 =  6;       // right motor
int RM2 =  7;       // right motor

/*-------PWM ควบคุมความเร็วมอเตอร์-----*/
int PWM1 = 10;    // PWM left motor
int PWM2 = 11;    // PWM right motor
int SPEED = 90;  // Speed PWM สามารถปรับความเร็วได้ถึง 255

void setup()
{
  pinMode(LS, INPUT);
  pinMode(RS, INPUT);
  pinMode(LM1, OUTPUT);
  pinMode(LM2, OUTPUT);
  pinMode(RM1, OUTPUT);
  pinMode(RM2, OUTPUT);
  pinMode(PWM1, OUTPUT);
  pinMode(PWM2, OUTPUT);
}

void loop()

{

  if (!(digitalRead(LS)) && !(digitalRead(RS)))    // Move Forward
  {
    analogWrite(PWM1, SPEED);
    digitalWrite(LM1, HIGH);
    digitalWrite(LM2, LOW);
    analogWrite(PWM2, SPEED);
    digitalWrite(RM1, HIGH);
    digitalWrite(RM2, LOW);
  }


  if (!(digitalRead(LS)) && digitalRead(RS))    // Turn right
  {
    digitalWrite(LM1, LOW);
    digitalWrite(LM2, LOW);
    analogWrite(PWM2, SPEED);
    digitalWrite(RM1, HIGH);
    digitalWrite(RM2, LOW);
  }

  if (digitalRead(LS) && !(digitalRead(RS)))    // turn left
  {
    analogWrite(PWM1, SPEED);
    digitalWrite(LM1, HIGH);
    digitalWrite(LM2, LOW);
    digitalWrite(RM1, LOW);
    digitalWrite(RM2, LOW);
  }

 if (digitalRead(LS) && digitalRead(RS))    // stop

  {
    digitalWrite(LM1, LOW);
    digitalWrite(LM2, LOW);
    digitalWrite(RM1, LOW);
    digitalWrite(RM2, LOW);
  }

}

Internet of Things (IoT)

Internet of Things หรือ IoT Internet of Things (IoT)  คือ การที่อุปกรณ์อิเล็กทรอนิกส์ต่างๆ สามารถเชื่อมโยงหรือส่งข้อมูลถึงกันได้ด้วยอิน...