아두이노 우노 R4 힘 센서

이 튜토리얼은 Arduino UNO R4와 힘 센서를 사용하는 방법을 안내합니다. 자세히는 다음을 배우게 됩니다:

아두이노 우노 R4 및 힘 센서

준비물

1×Arduino UNO R4 WiFi or Arduino UNO R4 Minima
1×(또는) DIYables STEM V4 IoT, Compatible with Arduino Uno R4 WiFi 쿠팡 | 아마존
1×USB 케이블 타입-A to 타입-C (USB-A PC용) 쿠팡 | 아마존
1×USB 케이블 타입-C to 타입-C (USB-C PC용) 아마존
1×힘 센서 쿠팡 | 아마존
1×10 kΩ Resistor 아마존
1×브레드보드 쿠팡 | 아마존
1×점퍼케이블 쿠팡 | 아마존
1×(추천) 아두이노 우노 R4용 스크루 터미널 블록 쉴드 쿠팡 | 아마존
1×(추천) Sensors/Servo Expansion Shield for Arduino UNO R4 쿠팡 | 아마존
1×(추천) 아두이노 우노 R4용 브레드보드 쉴드 쿠팡 | 아마존
1×(추천) 아두이노 우노 R4용 케이스 쿠팡 | 아마존
1×(추천) 아두이노 우노 R4용 전원 분배기 쿠팡 | 아마존
1×(추천) 아두이노 우노용 프로토타이핑 베이스 플레이트 & 브레드보드 키트 아마존
공개: 이 포스팅 에 제공된 일부 링크는 아마존 제휴 링크입니다. 이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.
Arduino Uno R4 WiFi Compatible Boards

힘 센서에 대하여

포스 센서 핀 배치

포스 센서는 때때로 힘 감지 저항기, 민감 저항 또는 단순히 FSR이라고 불립니다. 압력이 가해질 때 저항이 변하는 저항기의 일종입니다.

  • 저렴하고 작동이 간단하다.
  • 물리적 압력이나 압착을 감지하는 데 효과적이다.
  • 파운드로 무게를 측정하는 데 효과적이지 않다.

힘 센서는 전자 드럼, 휴대 전화, 휴대용 게임 장치 및 기타 많은 휴대용 전자 제품에 사용됩니다.

핀아웃

힘 센서는 두 개의 핀이 있습니다. 저항기처럼 작동하기 때문에 이 핀들을 구별할 필요가 없습니다. 그들은 동일합니다.

작동 방식

힘 센서는 눌리는 강도에 따라 저항이 변하는 저항기와 같습니다. 더 세게 누를수록 두 끝 사이의 저항이 낮아집니다.

선연결

아두이노 우노 R4 강제 배선도

이 이미지는 Fritzing을 사용하여 만들어졌습니다. 이미지를 확대하려면 클릭하세요.

Arduino Uno R4와 기타 부품에 전원을 공급하는 가장 효과적인 방법을 확인하시려면, 아래 링크를 참조하세요: 아두이노 우노 R4 전원 공급 방법.

힘 센서를 위한 프로그래밍 방법

Arduino UNO R4에는 아날로그 입력에 사용되는 A0에서 A5로 라벨이 붙은 핀이 있습니다. 이 핀들은 0볼트에서 VCC까지의 전압을 0에서 1023 사이의 정수로 변환합니다. 이 숫자는 ADC 또는 아날로그 값으로 알려져 있습니다.

포스 센서의 핀을 아날로그 입력 핀에 연결하여 analogRead() 함수를 사용하면 핀에서 아날로그 값을 읽을 수 있습니다. 이는 얼마나 많은 압력이 가해지고 있는지를 알려줍니다.

아두이노 UNO R4 코드

/* * 이 아두이노 우노 R4 코드는 newbiely.kr 에서 개발되었습니다 * 이 아두이노 우노 R4 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/arduino-uno-r4/arduino-uno-r4-force-sensor */ #define FORCE_SENSOR_PIN A0 // The Arduino UNO R4 pin connected to the FSR force sensor with 10K pulldown void setup() { Serial.begin(9600); } void loop() { int analogReading = analogRead(FORCE_SENSOR_PIN); Serial.print("Force sensor reading = "); Serial.print(analogReading); // print the raw analog reading if (analogReading < 10) // from 0 to 9 Serial.println(" -> no pressure"); else if (analogReading < 200) // from 10 to 199 Serial.println(" -> light touch"); else if (analogReading < 500) // from 200 to 499 Serial.println(" -> light squeeze"); else if (analogReading < 800) // from 500 to 799 Serial.println(" -> medium squeeze"); else // from 800 to 1023 Serial.println(" -> big squeeze"); delay(1000); }

자세한 사용 방법

이 지침을 단계별로 따르세요:

  • Arduino Uno R4 WiFi/Minima를 처음 사용하는 경우, 아두이노 우노 R4 - 소프트웨어 설치을 참조하십시오.
  • 제공된 다이어그램에 따라 힘 센서를 Arduino Uno R4에 연결하십시오.
  • USB 케이블을 사용하여 Arduino Uno R4 보드를 컴퓨터에 연결하십시오.
  • 컴퓨터에서 Arduino IDE를 실행하십시오.
  • 적절한 Arduino Uno R4 보드(예: Arduino Uno R4 WiFi)와 COM 포트를 선택하십시오.
  • 위의 코드를 복사하여 Arduino IDE에서 엽니다.
  • Arduino IDE에서 Upload 버튼을 클릭하여 코드가 Arduino UNO R4에 업로드되도록 하십시오.
  • 힘 센서를 누르십시오.
  • 시리얼 모니터에서 결과를 확인하십시오.
Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
Arduino Uno R4 WiFi
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno R4 WiFi' on 'COM15')
New Line
9600 baud
Force sensor reading = 0 -> no pressure Force sensor reading = 0 -> no pressure Force sensor reading = 132 -> light touch Force sensor reading = 147 -> light touch Force sensor reading = 394 -> light squeeze Force sensor reading = 421 -> light squeeze Force sensor reading = 607 -> medium squeeze Force sensor reading = 791 -> medium squeeze Force sensor reading = 921 -> big squeeze Force sensor reading = 987 -> big squeeze Force sensor reading = 0 -> no pressure Force sensor reading = 0 -> no pressure
Ln 11, Col 1
Arduino Uno R4 WiFi on COM15
2

동영상

비디오 제작은 시간이 많이 걸리는 작업입니다. 비디오 튜토리얼이 학습에 도움이 되었다면, YouTube 채널 을 구독하여 알려 주시기 바랍니다. 비디오에 대한 높은 수요가 있다면, 비디오를 만들기 위해 노력하겠습니다.

아래 동영상 데모는 아래 코드를 사용합니다:

/* * 이 아두이노 우노 R4 코드는 newbiely.kr 에서 개발되었습니다 * 이 아두이노 우노 R4 코드는 어떠한 제한 없이 공개 사용을 위해 제공됩니다. * 상세한 지침 및 연결도에 대해서는 다음을 방문하세요: * https://newbiely.kr/tutorials/arduino-uno-r4/arduino-uno-r4-force-sensor */ #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> // OLED display configuration #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 Adafruit_SSD1306 display( SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET ); // Force-sensitive resistor input #define FORCE_SENSOR_PIN A0 // LED pins used to indicate force level const int ledPins[8] = { 2, 3, 4, 5, 6, 7, 8, 9 }; // Calibrated force sensor range const int FORCE_MIN = 0; const int FORCE_MAX = 1000; // Exponential moving average filter float smoothValue = 0; const float alpha = 0.3; // Initialize hardware and display void setup() { Serial.begin(115200); // Configure LED outputs and turn all LEDs off. for (int i = 0; i < 8; i++) { pinMode(ledPins[i], OUTPUT); digitalWrite(ledPins[i], LOW); } // Initialize the OLED using I2C communication. if (!display.begin( SSD1306_SWITCHCAPVCC, 0x3C )) { Serial.println("OLED failed!"); // Stop execution if the OLED cannot be initialized. while (1); } display.clearDisplay(); display.setTextColor(SSD1306_WHITE); // Display startup screen. display.setTextSize(2); display.setCursor(20, 25); display.println("DIYables"); display.display(); delay(1500); // Initialize the filter with the first sensor reading // to prevent an incorrect initial value. smoothValue = analogRead(FORCE_SENSOR_PIN); } void loop() { // Read the current FSR value. int rawValue = analogRead(FORCE_SENSOR_PIN); // Apply exponential moving average filtering // to reduce sensor noise and fluctuations. smoothValue = alpha * rawValue + (1.0 - alpha) * smoothValue; int forceValue = (int)smoothValue; // Convert the sensor value into 8 force levels. int level = map( forceValue, FORCE_MIN, FORCE_MAX, 0, 8 ); level = constrain(level, 0, 8); // Turn on LEDs progressively according to the force level. for (int i = 0; i < 8; i++) { if (i < level) { digitalWrite(ledPins[i], HIGH); } else { digitalWrite(ledPins[i], LOW); } } // Output sensor data for monitoring and calibration. Serial.print("FSR = "); Serial.print(forceValue); Serial.print(" | Level = "); Serial.println(level); // Refresh OLED display. display.clearDisplay(); // Display title. display.setTextSize(2); display.setCursor(50, 0); display.println("FSR"); // Configure the force indicator as a battery-style bar. int barX = 10; int barY = 25; int barWidth = 108; int barHeight = 18; // Draw the outer bar. display.drawRect( barX, barY, barWidth, barHeight, SSD1306_WHITE ); // Draw the battery terminal. display.fillRect( barX + barWidth, barY + 5, 4, 8, SSD1306_WHITE ); // Calculate the filled portion based on the force level. int fillWidth = map( level, 0, 8, 0, barWidth - 4 ); if (fillWidth > 0) { display.fillRect( barX + 2, barY + 2, fillWidth, barHeight - 4, SSD1306_WHITE ); } // Display current force level. display.setTextSize(1); display.setCursor(5, 50); display.print("LEVEL: "); display.print(level); display.print("/8"); // Display project branding. display.setCursor(78, 50); display.print("DIYables"); display.display(); // Short delay for stable display updates. delay(30); }

관련 튜토리얼