BASIC4MCU | 질문게시판 | RC카 알콜감지센서
페이지 정보
작성자 봠지니 작성일2020-10-20 11:43 조회3,483회 댓글1건본문
시중에 많은 RC카 프로그램을 바탕으로 MQ-3 알콜감지센서를 이용하여
RC카 운행 중 알콜 측정 센서값 400 이상이면 동작이 되지 않도록 하는 프로그램을 짜보았는데
도무지 되지가 않습니다. 도움 부탁드립니다 ㅜ.ㅜ
int mq3 = A0; // mq3 A0핀 연결
int RightMotor_E_pin = 5; // 오른쪽 모터의 Enable & PWM
int RightMotor_1_pin = 8; // 오른쪽 모터 제어선 IN1
int RightMotor_2_pin = 9; // 오른쪽 모터 제어선 IN2
int LeftMotor_3_pin = 10; // 왼쪽 모터 제어선 IN3
int LeftMotor_4_pin = 11; // 왼쪽 모터 제어선 IN4
int LeftMotor_E_pin = 6; // 왼쪽 모터의 Enable & PWM
int value; // 측정값저장할 변수void SmartCar_Go();
int E_carSpeed = 200;
void setup() {
Serial.begin(9600);
pinMode(RightMotor_E_pin, OUTPUT); // 출력모드로 설정
pinMode(RightMotor_1_pin, OUTPUT);
pinMode(RightMotor_2_pin, OUTPUT);
pinMode(LeftMotor_3_pin, OUTPUT);
pinMode(LeftMotor_4_pin, OUTPUT);
pinMode(LeftMotor_E_pin, OUTPUT);
LeftMotor.setSpeed(200);
LeftMotor.run(RELEASE);
RightMotor.setSpeed(200);
RightMotor.run(RELEASE);
}
void loop() {
SmartCar_Go();
delay(30000);
}void SmartCar_Go() { // 전진
Serial.println("Forward");
digitalWrite(RightMotor_1_pin, HIGH);
digitalWrite(RightMotor_2_pin, HIGH);
digitalWrite(LeftMotor_3_pin, HIGH);
digitalWrite(LeftMotor_4_pin, HIGH);for (int i = 0; i <= E_carSpeed; i = i + 5) {
analogWrite(RightMotor_E_pin, i);
analogWrite(LeftMotor_E_pin, i);
delay(20);
}
}void loop() {
value = analogRead(analogpin);
Serial.print("Alcohol value:");
delay(100);
if (val >= 400) { // 센서 값이 400 이상이면
LeftMotor.run(RELEASE);
RightMotor.run(RELEASE);
delay(300000);
}
else (val < 200) { // 센서 값이 200 미만이면
LeftMotor.run(RELEASE);
RightMotor.run(RELEASE);
delay(100);
}
// put your main code here, to run repeatedly:}
댓글 1
조회수 3,483master님의 댓글
master 작성일
if (val >= 400) { // 센서 값이 400 이상이면
LeftMotor.run(RELEASE); RightMotor.run(RELEASE); delay(300000);
}
else (val < 200) { // 센서 값이 200 미만이면
LeftMotor.run(RELEASE); RightMotor.run(RELEASE); delay(100);
}
400 이상이든 200 이하든 멈추라고 작성했나요?