المكونات الاساسية :
- Arduino UNO R3
- Servo motor 9g
- Sensor Ultrasonic HC-sr04
- Breadboard
- Jumper Wires
#diy_channel #arduino_maroc #iot_maroc
++ مخطط الرسم البياني :
++ الكود البرمجي هنا :
المكونات الاساسية :
- Arduino UNO R3
- Servo motor 9g
- Sensor Ultrasonic HC-sr04
- Breadboard
- Jumper Wires
#diy_channel #arduino_maroc #iot_maroc
++ الكود البرمجي هنا :
#include <Servo.h>
Servo servo;
const int trig = 2, echo = 3 ;
int pos = 0, distcm = 0;
void setup()
{
Serial.begin(9600);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
servo.attach(9);
}
void loop()
{
for (pos = 0; pos <= 180; pos += 1)
{
servo.write(pos);
delay(50);
Serial.println(radar());
}
for (pos = 180; pos >= 0; pos -= 1)
{
servo.write(pos);
delay(50);
Serial.println(radar());
}
}
long radar(void)
{
digitalWrite(trig, HIGH);
delayMicroseconds(15);
digitalWrite(trig, LOW);
long dur = pulseIn(echo, HIGH);
distcm = dur / 58;
return distcm;
}
------------------------------------------------------------------------ Download the app : LINK ----------------------------------------...
No comments:
Post a Comment