Giter VIP home page Giter VIP logo

arduino_distance_beeper's Introduction

아두이노를 이용한 접근 경보기

Intro

둘째 딸이 학교 방과후 수업(3D펜 수업)에서 작품을 만들어 왔는데,
초음파센서하고 피에조가 붙어있길래 물어보니,
아두이노를 붙여서 가까이 가면 소리나는 거라고 하더라.

근데, 아두이노는 비싸서 같이 못준다고 껍데기만 집에 가져왔다.

작품

아빠가 만들어 줄께

아빠가 아두이노 붙여줄께..

공구함에 쌓여있는 아두이노 하나 꺼내서 연결하고, 코딩하고..

회로도

아두이노

아두이노뒷면

배터리를 달아보려 했으나, 지금 가진 배터리 케이스나 커넥터가 없어서,
Micro USB 케이블로 연결해서 쓸 수 있도록
아두이노 micro USB / Leonardo 호환 보드를 이용해서 만들었다.

Arduino Code

const int trig= 2;
const int echo= 3;
const int piezo = 8;

unsigned long nextBeepTime = 0;

void setup() {
}

void loop()
{
  long val= readUltrasonicDistance(trig, echo);

  unsigned long current = millis();
  
  if(val < 200) { //20cm 미터 이내
    if(current > nextBeepTime) {
      tone(piezo, 440, 100);
      nextBeepTime = millis() + val * 2;
    }
  }

  delay(50);
}

long readUltrasonicDistance(int triggerPin, int echoPin)
{
  pinMode(triggerPin, OUTPUT);  // Clear the trigger
  digitalWrite(triggerPin, LOW);
  delayMicroseconds(2);
  // Sets the trigger pin to HIGH state for 10 microseconds
  digitalWrite(triggerPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(triggerPin, LOW);
  pinMode(echoPin, INPUT);
  // Reads the echo pin, and returns the sound wave travel time in microseconds
  return pulseIn(echoPin, HIGH) * 1723 / 10000; // mm
}

결과물

Video Label
Video

Outro

아두이노 우노에다가 커넥커로 연결해주는게 편할텐데,
우노는 1개밖에 없어서 소모하긴 싫고, 커넥터도 마땅한게 없어서,
마이크로 버전에다가 회로 꾸미다 보니 복잡하게 된 듯 하지만,
결과는 잘 나왔다.

Devices

Arduino
Pro Micro ATmega32U4 5V 16MHz Replace ATmega328 For arduino ATMega 32U4 Pro Mini With 2 Row Pin Header

HC-SR04
Ultrasonic Wave Detector Ranging Module for arduino Distance Sensor

Piezo
Mini Piezo Buzzers For Arduino

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.