//停車場柵欄
#include <Servo.h>
Servo myservo;
const int IR_InPin = A3; // A3 接 IR
int sensorValue = 0;
void setup() {
Serial.begin(57600);
pinMode(IR_InPin, INPUT);
myservo.attach(4); //180度馬達接第4腳
}
void loop() {
sensorValue = analogRead(IR_InPin);
if (sensorValue >= 300)
{
myservo.write(0);
}
else if (sensorValue < 150)
{
myservo.write(85);
}
delay(1000);
}
智高 1247 A 完成一個停車場柵欄, 再將此程式燒錄到 arduino 上
車子靠近柵欄時, 柵欄會自動昇起, 當 IR前的物體消失, 柵欄會自動放下
2017-03-14