BASIC4MCU | 질문게시판 | 아두이노 서보모터 음성제어 질문있습니다!!
페이지 정보
작성자 어렵다어려워 작성일2020-11-25 16:43 조회5,270회 댓글2건본문
안녕하십니까! ㅎㅎ 이공계열 1학년 대학생입니다. 아두이노로 재미있는 장난감 만들어 보려다 너무 어려워서 인터넷 찾다가 질문드립니다! ㅠㅠ 여기에 고수분들 많은걸로 알고있습니다,, 부디,, 알려주시옵서서,,
아두이노를 이용한 서보모터 음성제어 램프를 만들고 있었습니다. 만들려고 했던 작품의 출처는 바로 >> https://www.instructables.com/Bluetooth-Voice-Controlled-Moving-Lamp/
문제점 1. 소스 내용을 그대로 가져다 쓰다보니 소스 내용이 무슨 말인지 하나도 모르겠습니다. ㅜㅜ 주석이나 해석글을 달아주실수 있으실까요!!
#include
String command;
String value;
Servo servo_rotation;
Servo servo_tilt;
Servo servo_height;
int step_delay = 50;
void setup() {
Serial.begin(9600);
servo_rotation.attach(3);
servo_tilt.attach(5);
servo_height.attach(6);
servo_rotation.write(90);
servo_tilt.write(90);
servo_height.write(100);
//that's for relay
pinMode(7, OUTPUT);
digitalWrite(7, HIGH);
}
void loop() {
while (Serial.available()){
delay(10);
char command_char = Serial.read();
if (command_char == '#') {break;}
command += command_char;
}
if (command.length() > 0) {
Serial.println(command);
if(command.indexOf("*counterclockwise") >= 0) {
value = command.substring(17, command.length());
for(int a = 0; a < value.toInt(); a++){
if((servo_rotation.read()+1) >= 0 && (servo_rotation.read()+1) <= 180){
servo_rotation.write(servo_rotation.read()+1);
delay(step_delay);
}
}
}
if(command.indexOf("*counter clockwise") >= 0) {
value = command.substring(18, command.length());
for(int a = 0; a < value.toInt(); a++){
if((servo_rotation.read()+1) >= 0 && (servo_rotation.read()+1) <= 180){
servo_rotation.write(servo_rotation.read()+1);
delay(step_delay);
}
}
}
if(command.indexOf("*clockwise") >= 0) {
value = command.substring(10, command.length());
for(int a = 0; a < value.toInt(); a++){
if((servo_rotation.read()-1) >= 0 && (servo_rotation.read()-1) <= 180){
servo_rotation.write(servo_rotation.read()-1);
delay(step_delay);
}
}
}
if(command.indexOf("*front") >= 0) {
value = command.substring(7, command.length());
for(int a = 0; a < value.toInt(); a++){
if((servo_tilt.read()+1) < 140 && (servo_tilt.read()+1) > 50){
servo_tilt.write(servo_tilt.read()+1);
}
if((servo_height.read()-1) < 150 && (servo_height.read()-1) >= 0){
servo_height.write(servo_height.read()-1);
}
delay(step_delay);
}
}
if(command.indexOf("*back") >= 0) {
value = command.substring(5, command.length());
for(int a = 0; a < value.toInt(); a++){
if((servo_tilt.read()-1) < 140 && (servo_tilt.read()-1) > 50){
servo_tilt.write(servo_tilt.read()-1);
}
if((servo_height.read()+1) < 150 && (servo_height.read()+1) >= 0){
servo_height.write(servo_height.read()+1);
}
delay(step_delay);
}
}
if(command.indexOf("*up") >= 0) {
value = command.substring(3, command.length());
for(int a = 0; a < value.toInt(); a++){
if((servo_height.read()-1) < 150 && (servo_height.read()-1) >= 0){
servo_height.write(servo_height.read()-1);
delay(step_delay);
}
}
}
if(command.indexOf("*down") >= 0) {
value = command.substring(5, command.length());
for(int a = 0; a < value.toInt(); a++){
if((servo_height.read()+1) < 150 && (servo_height.read()+1) >= 0){
servo_height.write(servo_height.read()+1);
delay(step_delay);
}
}
}
if(command.equals("*on")) {
digitalWrite(7, LOW);
}
if(command.equals("*off")) {
digitalWrite(7, HIGH);
}
}
command="";
}
문제점 2. 일단 그대로 복사붙이기 해서 바로 밑의 회로 그대로 구성했더니, ~6번 핀에 꼽혀있는 서보모터가 혼자서 빙글빙글 돌고 led도 혼자서 불이 들어와서 on / off 제어가 되질 않습니다. 회로구성이 틀린것은 아닌지 싶어서 5번 넘게 다시 구성해보고 다시 검사해보고 했는데 회로는 정확히 구성을 하였습니다.
댓글 2
조회수 5,270master님의 댓글
master 작성일
빙글빙글이라는 뜻이 360도를 회전한다는 뜻일까요?
0~180도 범위로 움직이는 서보모터로 변경하세요
360도 회전하는 모터는 바퀴용 서보모터 입니다.
master님의 댓글
master 작성일
주석은 달아드리지 않습니다.
주석달아드리는 것은 시간이 많이 걸리기도 하며
어느 수준에 맞춰서 주석을 달아야 할런지도 모르기 때문입니다.
유료라면 가능하겠습니다.
본인이 주석을 달고, 어려운 몇개의 라인에 대해서 묻는다면 답변을 해드리겠지만
전체 주석을 다는 것은 교수님이 학생들 공부하도록 요구 할 때만 가능한 일이죠