본문 바로가기

arduino

Wifi모듈(ESP8266) 사용법(1) - 펌웨어 업데이트 하기(MAC) 0. 업데이트에 앞서서.. - ESP8266는 3.3V를 사용하나 아두이노 보드의 TX, RX는 5V - 따라서, ESP8266이 고장날 수 있으나 진행결과 3개의 모듈 정상작동(운이 좋았을지도) - 가장 좋은 방법은 저항을 통해 5V → 3.3V로 만들어서 진행하는 방법. - 하지만 저는 그냥 진행. 1. 왜 업데이트를 해야 할까? - 아두이노와 연결해서 사용하기 위해 필요한 SoftwareSerial이 지원하는 최대 보드레이트: 19200 - ESP8266의 기본 보드레이트: 115500 - 사용하기 위해서는 ESP8266의 보드레이트를 낮춰야 함. 이를 위한 펌웨어를 업데이트. - 여기 설명하는 방법대로 업데이트를 완료 하면 9600 보드레이트로 변경. 2. ESP8266 설명 및 ESP8266과 .. 더보기
가변저항으로 servo모터 움직이기 준비물 - servo모터 1개 - 가변저항 1개 코드 #include Servo myServo; void setup() { myServo.attach(9); } void loop() { int val = analogRead(A0); int rad = map(val, 0, 1023, 0, 179); myServo.write(rad); delay(15); } 영상 알게된 점 - 가변저항(potentiometer) 1) VCC(5V)와 GND의 방향은 상관 없음, 가운데는 analog 출력 2) 가변저항을 돌릴 때 마다 저항 크기가 바뀌고 그에 따라 전류가 변경 3) 1번이 VCC(5V)이고 3번이 GND여서 1번에서 3번으로 전류가 흐르는 경우(하단 그림 참고) 0] 전류가 저항을 더 많이 지날 수록 전류는.. 더보기
servo모터 자동으로 움직이기 준비물 - servo모터 1개 코드 #include Servo myServo; void setup() { //servo pinnumber attach myServo.attach(9); } void loop() { for (int i = 0 ; i < 180 ; i++) { //servo angle setting myServo.write(i); delay(15); // 꼭 delay를 사용하여 각도를 변경할 시간을 줘야 함 } myServo.write(0); delay(1000); } 영상 알게된 점 - servo모터 관련 1) 갈색: GND 빨간색: VCC(5V) 주황색: digital핀 2) servo.attach(digitPinNum) 함수를 사용하여 핀 설정 3) servo.write(angle) .. 더보기
버튼스위치로 숫자 변경하기 준비물 - 7segment 1개 - 버튼스위치 2개 - 10㏀ 저항 2개 - 220Ω 저항 1개 코드 int digit = 0; byte digits[10][7] = { {1, 1, 1, 1, 1, 1, 0}, {0, 1, 1, 0, 0, 0, 0}, {1, 1, 0, 1, 1, 0, 1}, {1, 1, 1, 1, 0, 0, 1}, {0, 1, 1, 0, 0, 1, 1}, {1, 0, 1, 1, 0, 1, 1}, {0, 0, 1, 1, 1, 1, 1}, {1, 1, 1, 0, 0, 0, 0}, {1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 0, 0, 1, 1}, }; const int minusButtonPin = 2; const int plusButtonPin = 3; void setup(.. 더보기
카운터 만들기 준비물 - 7segment 1개 - 220Ω 저항 1개 코드 //카운터 출력을 위한 값 byte digits[10][7] = { {1, 1, 1, 1, 1, 1, 0}, //0 {0, 1, 1, 0, 0, 0, 0}, //1 {1, 1, 0, 1, 1, 0, 1}, //2 {1, 1, 1, 1, 0, 0, 1}, //3 {0, 1, 1, 0, 0, 1, 1}, //4 {1, 0, 1, 1, 0, 1, 1}, //5 {0, 0, 1, 1, 1, 1, 1}, //6 {1, 1, 1, 0, 0, 0, 0}, //7 {1, 1, 1, 1, 1, 1, 1}, //8 {1, 1, 1, 0, 0, 1, 1} //9 }; void setup() { //핀모드 설정 for (int i = 2 ; i < 10 ; i++).. 더보기
거리 값을 LCD에 표시하기 준비물 - LCD 모니터 1개 - 초음파 센서 1개 - 1㏀ 저항 2개 코드 #include //초음파 센서 핀 설정 const int distTrigPin = 8; const int distEchoPin = 9; const float distVal = 58.2; //LCD 핀 설정 const int lcdRSPin = 12; const int lcdEPin = 11; const int lcdD4Pin = 2; const int lcdD5Pin = 3; const int lcdD6Pin = 4; const int lcdD7Pin = 5; LiquidCrystal lcd(lcdRSPin, lcdEPin, lcdD4Pin, lcdD5Pin, lcdD6Pin, lcdD7Pin); void setup() { p.. 더보기
주위 밝기 값을 LCD에 표시하기 준비물 - LCD 모니터 1개 - 조도 센서 1개 - 1㏀ 저항 2개 - 10㏀ 저항 1개 코드 #include const int inputLightPin = A0; const int lcdRsPin = 12; const int lcdEPin = 11; const int lcdD4Pin = 2; const int lcdD5Pin = 3; const int lcdD6Pin = 4; const int lcdD7Pin = 5; //LCD 초기화(RS, E, D4, D5, D6, D7); LiquidCrystal lcd(lcdRsPin, lcdEPin, lcdD4Pin, lcdD5Pin, lcdD6Pin, lcdD7Pin); void setup() { //LCD 크기 지정(2x16) lcd.begin(16, 2.. 더보기
거리에 따른 piezo 스피커 출력시간 조절 준비물 - 초음파 센서 1개 - piezo 스피커 1개 코드 //초음파센서 trig, echo핀 설정 const int distTrigPin = 2; const int distEchoPin = 3; const int piezoPin = 8; void setup() { pinMode(distTrigPin, OUTPUT); pinMode(distEchoPin, INPUT); } void loop() { //거리 측정 digitalWrite(distTrigPin, HIGH); delayMicroseconds(10); digitalWrite(distTrigPin, LOW); long duration = pulseIn(distEchoPin, HIGH); if (duration == 0) { return; } lo.. 더보기
거리에 따른 3색 LED 색 변경 준비물 - 초음파 센서 1개 - 3색 LED 1개 코드 //초음파센서 trig, echo핀 설정 const int distTrigPin = 2; const int distEchoPin = 3; //3색 LED 핀 설정 const int ledRedPin = 11; const int ledGreenPin = 10; const int ledBluePin = 9; void setup() { pinMode(distTrigPin, OUTPUT); pinMode(distEchoPin, INPUT); } void loop() { analogWrite(ledRedPin, 0); analogWrite(ledGreenPin, 0); analogWrite(ledBluePin, 0); //거리 측정 digitalWrite(d.. 더보기
주위 밝기에 따라 piezo 스피커 음 변경 준비물 - 조도센서 1개 - piezo 스피커 1개 - 10㏀ 저항 1개 코드 const int lightInputPin = A0; const int piezoOutputPin = 8; void setup() { } void loop() { int light = analogRead(lightInputPin);//0(0V) ~ 1023(5V) int hertz = map(light, 0, 1023, 31, 4978); tone(piezoOutputPin, hertz, 100); delay(100); noTone(piezoOutputPin); delay(200); } 영상 더보기