아두이노 적외선 근접센서

******************** 적외선 근접센서 ********************  3.3~5V 사이 동작 2~30cm 이내 동작 LM393칩 사용 int LED=13; // use the onboard Uno LED int isObstaclePin=7; // This is our input pin int isObstacle=HIGH; // HIGH means no obstacle void setup(){ pinMode(LED, output); pinMode(isObstaclePin, INPUT); Serial.begin(9600); } void loop(){ isObstacle=digitalRead(isObstaclePin); if(isObstacle==LOW) { Serial.println("OBSTACLE!!, OBSTACLE!!"); digitalWrite(LED, HIGH); } else { Serial.println("clear"); digitalWrite(LED, LOW); } delay(200); } ******************** 포토인터럽트 ********************  ******************** a0핀으로 테스트 ********************  int value=0; void setup() { Serial.begin(9600); } void loop(){ value=analogRead(A0); Serial.println(value); delay(10); } ******************** 포토인터럽트 ********************  ******************** d2 디지털 핀 테스트********************  int value=0; int pin=2; void setup() { Serial.begin(9600); } void loop(){ value=digitalRead(pin); Serial.println("digital=...

Arduino Timers & Interrupts

이미지
 https://www.robotshop.com/community/forum/t/arduino-101-timers-and-interrupts/13072 Arduino 101: Timers and Interrupts Let's Make Robots Tutorials legacy arduino pwm interrupt timer timers counter Aug 2011 1 / 35 Aug 2011 Back Feb 15 robotfreak Aug '11 arduino-exposure.jpg 800×601 96.4 KB Arduino101-Timers.zip  975  (33689Bytes) ArduinoTimer101.zip  724  (2802Bytes)     Update  07/24/2013  04/24/2013 Example 3 has been updated to work with Arduino v1.x. Added ArduinoTimer101.zip examples source code for Arduino v1.x .     This tutorial shows the use of timers and interrupts for Arduino boards. As Arduino programmer you will have used timers and interrupts without knowledge, bcause all the low level hardware stuff is hidden by the Arduino API. Many Arduino functions uses timers, for example the time functions:    delay()   876 ,   millis()   2.0k  and   micros()   868  and ...

Arduino PWM 2N2222

이미지
https://sizzf.tistory.com/19   2. 펄스(PWM)으로 부저 연주하기 회로를 보시면 새로운 부품이 보일겁니다. 아날로그회로에서 증폭기 역할을 해주는 npn트랜지스터입니다.  int speakerPin = 8; int numTones = 10; int tones[] = {261, 277, 294, 311, 330, 349, 370, 392, 415, 440}; // mid C C# D D# E F F# G G# A void setup() { }   void loop() {     for (int i = 0; i < numTones; i++) { tone(speakerPin, tones[i]); delay(500); } noTone(speakerPin); delay(1000); }   새로운 함수가 보입니다.  tone(pin,frequency)함수 입니다. tone(pin,frequency) 는 pin번호에  frequncey값에 맞는 주파수를 출력하여 소리를 내게해주는 함수입니다. 이때  tone(pin,frequency,duration)으로 시간(ms)까지 설정 이 가능 합니다. 또한 tone함수는 아두이노3번핀과 11번핀에서는  사용이 불가능 하며 31~65545의 주파수를 재생 가능합니다. 소리를 끄고 싶을때는 notone() 함수를 사용하시면 됩니다. 소스코드 설명 : tones배열의 각각의 음계에 맞는 주파수를 저장한뒤 for문을 통해서 해당음계를 하나씩 소리냄 Simple Audio Player https://www.arduino.cc/en/Tutorial/SimpleAudioPlayer Hardware Required Arduino Due Board 8-ohm speaker or headphones Arduino shield with an SD card with cs CS 4 (like the Ethernet shi...