เครื่องช่วยจอดรถ
อุปกรณ์
Arduino Nano แถมสาย USB https://raka.is/r/Jzgk
HC-SR04 Ultrasonic Sensor Module https://raka.is/r/ejen
โฟโต้บอร์ด https://raka.is/r/BJpQ
โค้ด
#define Trig 2
#define Echo 3
const int LED = 4;
long duration;
int distance;
void setup() {
pinMode(LED, OUTPUT);
pinMode(Trig, OUTPUT);
pinMode(Echo, INPUT);
}
void loop() {
digitalWrite(Trig, LOW);
delayMicroseconds(5);
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
duration = pulseIn(Echo, HIGH);
distance = duration * 0.034 / 2;
if (distance <= 20)
{
digitalWrite(LED, HIGH);
delay(40);
}
else {
digitalWrite(LED, LOW);
}
}
delay arduino 在 Audom Idea Facebook 八卦
ทำวงจรควบคุมมอเตอร์ระยะไกลด้วยรีโมทวิทยุ+Arduino
https://www.youtube.com/watch?v=PsXB_kWwp8Y
-------------------------------------------
โค้ด
int ch1;
int ch2;
int ch3;
const int relay1 = 2;
const int relay2 = 3;
const int relay3 = 4;
const int relay4 = 5;
#include <Servo.h>
Servo myservo;
void setup() {
myservo.attach(A1);
pinMode(6, INPUT); // Set our input pins as such
pinMode(7, INPUT);
pinMode(8, INPUT);
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
Serial.begin(9600); // Pour a bowl of Serial
}
void loop() {
ch1 = pulseIn(5, HIGH, 25000); // Read the pulse width of
ch2 = pulseIn(6, HIGH, 25000); // each channel
ch3 = pulseIn(7, HIGH, 25000);
Serial.print("Channel 1:"); // Print the value of
Serial.println(ch1); // each channel
Serial.print("Channel 2:");
Serial.println(ch2);
Serial.print("Channel 3:");
Serial.println(ch3);
delay(10); // I put this here just to make the terminal
// window happier
if (ch3 >1700)
{
digitalWrite(relay1,LOW);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, LOW);
digitalWrite(relay4, HIGH);
}
else {
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
}
if (ch3 <1200)
{
digitalWrite(relay1, HIGH);
digitalWrite(relay2, LOW);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, LOW);
}
if (ch2 >1700)
{
digitalWrite(relay1,LOW);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, LOW);
}
if (ch2 <1300)
{
digitalWrite(relay1,HIGH);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
digitalWrite(relay4, HIGH);
}
}
delay arduino 在 Audom Idea Facebook 八卦
ทำเครื่องกดเจลล้างมืออัตโนมัติแบบพกพา
คลิป https://www.youtube.com/watch?v=xRvFsj59aZM
วัสดุที่ใช้
1.Arduino nano
2.Ultrasonic Module HC-SR04
3.เซอโว
4.สายจั๊มเปอร์
5.รางถ่าน aa3ก้อน
---------------------------------------------
โค้ด
#define Trig 2
#define Echo 3
#include <Servo.h>
Servo myservo;
Servo myservo1;
long duration;
int distance;
void setup() {
myservo.attach(A0);
myservo1.attach(A1);
pinMode(Trig, OUTPUT);
pinMode(Echo, INPUT);
}
void loop() {
digitalWrite(Trig, LOW);
delayMicroseconds(5);
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
duration = pulseIn(Echo, HIGH);
distance = duration * 0.034 / 2;
if (distance <= 20)
{
myservo.write(50);
myservo1.write(0);
delay(2000);
}
else {
myservo.write(0);
myservo1.write(50);
delay(500);
}
}
delay arduino 在 Arduino Delay Function, and Why You Shouldn't Use it 的八卦
Jun 24, 2016 - While delay() is handy for basic demonstrations of how Arduino works, you really shouldn't be using it in the real world. ... <看更多>