산책로봇(faet. 비컨)

산책로봇(faet. 비컨)

Makerist 0 720

이번예제는 비콘을 사용한 산책로봇  입니다.

#include <SoftwareSerial.h>


SoftwareSerial bluetoothSerial(2, 3); // HM-10 Bluetooth 모듈을 위한 소프트웨어 시리얼 설정
int robotSpeed = 100; // 로봇의 이동 속도 설정
int beaconLocation = 0; // 비콘의 위치 정보를 저장할 변수


void setup() {
  Serial.begin(9600); // 시리얼 통신 시작
  bluetoothSerial.begin(9600); // Bluetooth 시리얼 통신 시작
}


void loop() {
  if (bluetoothSerial.available()) { // Bluetooth 모듈로부터 데이터를 수신했는지 확인
    char receivedChar = (char)bluetoothSerial.read(); // 수신된 문자를 읽음
    if (receivedChar == 'n') { // 줄 바꿈 문자가 수신되었는지 확인
      // 수신된 데이터를 비콘 위치로 저장
      beaconLocation = atoi(receivedData.c_str());
      Serial.print("비콘 위치: ");
      Serial.println(beaconLocation);
      
      // 비콘 위치로 이동하는 함수 호출
      moveTo(beaconLocation);
      
      receivedData = ""; // 수신된 데이터를 저장한 변수 초기화
    } else {
      receivedData += receivedChar; // 수신된 문자를 데이터 변수에 추가
    }
  }
}


// 비콘 위치로 이동하는 함수
void moveTo(int targetLocation) {
  Serial.print("로봇이 ");
  Serial.print(targetLocation);
  Serial.println("로 이동합니다.");
  // 로봇을 이동시키는 코드를 추가하세요.
}

0 Comments
Category
반응형 구글광고 등
State
  • 현재 접속자 51 명
  • 오늘 방문자 2,885 명
  • 어제 방문자 3,313 명
  • 최대 방문자 4,586 명
  • 전체 방문자 674,777 명
  • 전체 게시물 25,586 개
  • 전체 댓글수 36 개
  • 전체 회원수 22 명
Facebook Twitter GooglePlus KakaoStory KakaoTalk NaverBand