วันจันทร์ที่ 20 สิงหาคม พ.ศ. 2561

ส่งงานครั้งที่10 DIY Project เซ็นเซอร์ตรวจจับไฟไหม้




DIY Project  

 เซ็นเซอร์ตรวจจับไฟไหม้





อุปกรณ์

  • Arduino UNO
  • Flame Sensor
  • 2N2222 NPN Transistor (or BC548)
  • 5V Buzzer
  • 1N4007 PN Junction Diode
  • 1KΩ Resistor
  • Connecting Wires
  • Mini Breadboard
  • Power Supply

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

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
const int buzzerPin = 12;
const int flamePin = 11;
int Flame = HIGH;
void setup()
{
  pinMode(buzzerPin, OUTPUT);
  pinMode(flamePin, INPUT);
  Serial.begin(9600);
}
void loop()
{
  Flame = digitalRead(flamePin);
  if (Flame== LOW)
  {
    Serial.println("Fire!!!");
    digitalWrite(buzzerPin, HIGH);
  }
  else
  {
    Serial.println("No worries");
    digitalWrite(buzzerPin, LOW);
  }
}













วันอาทิตย์ที่ 5 สิงหาคม พ.ศ. 2561

ส่งงานครั้งที่9 ตัวอย่าง เครื่องวัดปริมาณเเอลกอฮอล์







#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();
  }
}

ส่งงานครั้งที่8 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 
  }
}

ส่งงานครั้งที่7 เเสดงผล LCD





#include<LiquidCrystal.h>
LiquidCrystal lcd(8,9,10,11,12,13);
#include <Wire.h>
#include <MPU6050.h>
#define period 10000
MPU6050 mpu;
int count=0;
char okFlag=0;
byte degree[8] = {
  0b00000,
  0b00110,
  0b01111,
  0b00110,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};

void setup()
{
  lcd.begin(16,2); //จอมี 2 แถว 16 คอลัมน์
  lcd.createChar(0, degree);
  Serial.begin(9600);
  Serial.println("Initialize MPU6050");
  while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))
  {
    lcd.clear();
    lcd.print("Device not Found");
    Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
    delay(500);
  }
  count=0;
  mpu.calibrateGyro();
  mpu.setThreshold(3);

void loop()
{
    lcd.clear();
    lcd.print("Temperature");//แสดงผลลคำว่า Temperature
    long st=millis();
    Serial.println("Temperature");
    while(millis()<st+period)
    {
      lcd.setCursor(0,1); //เลื่อนเคอเซอร์ไปคอลัมน์ที่ 0 แถวที่ 1 (ก่อนหน้าตัวอักษรแรก)
      tempShow();
    }
    lcd.clear(); //ล้างหน้าจอ
    lcd.print("Gyro"); //แสดงผลลคำว่า Gyro
    delay(2000); //หน่วงเวลา 2 วินาที
    st=millis();
    Serial.println("Gyro");
    while(millis()<st+period)
    {
      lcd.setCursor(0,1);
      gyroShow();
    }
    lcd.clear();
    lcd.print("Accelerometer");
    delay(2000);
    st=millis();

ส่งงานครั้งที่6 ตัวอย่าง โปรเจค Arduino เปิด ปิดไฟ AC 220V ด้วยเสียง


โปรเจค Arduino เปิด ปิดไฟ AC 220V ด้วยเสียง




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


1. Arduino UNO R3 - Made in italy


2. Sensor Shield V 5.0

3. สาย Jumper Female to Male ยาว 20cm.

4. สาย Jumper Female to Female ยาว 20cm. 

5. Relay 1 Channel 5V DC Solid State High Level Trigger


6. Voice Sound Detection Sensor Module

7. สกรูหัวกลม+น็อตตัวเมีย ขนาด 3มม ยาว 12มม


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

int sound_sensor = 4;
int relay = 5;

int clap = 0;
long detection_range_start = 0;
long detection_range = 0;
boolean status_lights = false;

void setup() {
  pinMode(sound_sensor, INPUT);
  pinMode(relay, OUTPUT);
}

void loop() {
  int status_sensor = digitalRead(sound_sensor);
  if (status_sensor == 0)
  {
    if (clap == 0)
    {
      detection_range_start = detection_range = millis();
      clap++;
    }
    else if (clap > 0 && millis()-detection_range >= 50)
    {
      detection_range = millis();
      clap++;
    }
  }
  if (millis()-detection_range_start >= 400)
  {
    if (clap == 2)
    {
      if (!status_lights)
        {
          status_lights = true;
          digitalWrite(relay, HIGH);
        }
        else if (status_lights)
        {
          status_lights = false;
          digitalWrite(relay, LOW);
        }
    }
    clap = 0;
  }

}


อ้างอิง

วันเสาร์ที่ 21 กรกฎาคม พ.ศ. 2561

งานที่ 7


#include "LedControl.h"
#define C4  262
#define D4  294
#define E4  330
#define F4  349
#define G4  392
#define A4  440
#define B4  494
#define C5  523
int melody[] = {C4,D4,E4,F4,G4,A4,B4,C5};
float beats[] ={1,1,1,1,1,1,1,1};
int buzzerpin = 11;
int timestop = 70;
LedControl lc=LedControl(8,10,9,1);
// Pin 8->DIN, 10->CLK, 9->CS(LOAD), 1 = No.of devices
void setup()
{
  lc.shutdown(0,false); 
  lc.setIntensity(0,5);
  lc.clearDisplay(0);
  int dl = 500;
  pinMode(buzzerpin,OUTPUT);
  int numnote;
  numnote = sizeof(melody)/2; 
  for (int i=0;i<numnote;i++)
  {
    lc.setChar(0,7-i,'-',false);
    tone(buzzerpin, melody[i],dl*beats[i]);
    delay(dl*beats[i]);
    digitalWrite(buzzerpin,HIGH);
    delay(timestop);
  }
}
void loop()
{
}