01-09-2019, 05:03 PM
(This post was last modified: 01-09-2019, 05:11 PM by Peguinohero.)
Peguino Proximity Brick (Näherungssensor)
Dieser Peguino Baustein beinhaltet einen Ultraschall-Näherungssensor. Mit ihm kann unter Zuhilfenahme des sogenannten Doppler-Effekts der Abstand im Bereich von ca. 2 Zentimeter bis zu 4 Meter zu einem Hindernis gemessen werden. Damit kann z.B. ein selbstfahrender Roboter Wände vor sich wahrnehmen und darauf reagieren.
![[Image: Brick_Proximity_01b.png]](https://www.peguino.com/chat/images/Brick_Proximity_01b.png)
Beispiel für Peguino Uno Nano und Peguino Uno ESP32 V1:
Stecke den Peguino Proximity Brick an Port A des Peguino Uno Bausteins. Kopiere das Programmskript unten (CTRL+C) und fühe es in die Arduino IDE ein (CTRL+V). Kompiliere und übertrage das fertige Programm mit der Arduino IDE auf das Peguino Uno Board. Mit dem Serial Monitor der Arduino IDE kannst Du nun die gemessenen Werte des Lichtsensors sichtbar machen
1. Programmskript für einen Peguino Uno Nano Baustein:
2. Programmskript für einen Peguino Uno ESP32 Baustein:
Dieser Peguino Baustein beinhaltet einen Ultraschall-Näherungssensor. Mit ihm kann unter Zuhilfenahme des sogenannten Doppler-Effekts der Abstand im Bereich von ca. 2 Zentimeter bis zu 4 Meter zu einem Hindernis gemessen werden. Damit kann z.B. ein selbstfahrender Roboter Wände vor sich wahrnehmen und darauf reagieren.
![[Image: Brick_Proximity_01b.png]](https://www.peguino.com/chat/images/Brick_Proximity_01b.png)
Beispiel für Peguino Uno Nano und Peguino Uno ESP32 V1:
Stecke den Peguino Proximity Brick an Port A des Peguino Uno Bausteins. Kopiere das Programmskript unten (CTRL+C) und fühe es in die Arduino IDE ein (CTRL+V). Kompiliere und übertrage das fertige Programm mit der Arduino IDE auf das Peguino Uno Board. Mit dem Serial Monitor der Arduino IDE kannst Du nun die gemessenen Werte des Lichtsensors sichtbar machen
1. Programmskript für einen Peguino Uno Nano Baustein:
Code:
/*
Proximity Brick
(C) 2018 by Peguino LTD
Connect the Proximity Brick to port A
Version 1
Note: Use the Serial Plotter to see the values
Peguino Uno Nano Board Pinout
┌─╥─┐
D_13 1 │ │ 30 D_12
3.3 V 2 │ │ 29 D_11
AREF 3 │ │ 28 D_10
D_14 A_0 4 │ │ 27 D_9
D_15 A_1 5 │ │ 26 D_8
D_16 A_2 6 │ │ 25 D_7
D_17 A_3 7 │ │ 24 D_6
D_18 A_4 8 │ │ 23 D_5
D_19 A_5 9 │ │ 22 D_4
A_6 10 │ │ 21 D_3
A_7 11 │ │ 20 D_2
5V 12 │ │ 19 GND
Reset 13 │ │ 18 Reset
GND 14 │ │ 17 D_0 RX
Power In 15 │ │ 16 D_1 TX
└───┘
Visit https://www.peguino.com
*/
int trigPin = 15; // Trigger Signal
int echoPin = 14; // Echo
long duration, cm, inches;
void setup() {
//Serial Port begin
Serial.begin (9600); // Press Ctrl+Shift+M and set the serial monitor to the same baud rate!
//Define inputs and outputs
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
// The sensor triggers by a HIGH pulse of 10 or more microseconds - a short LOW pulse first ensures a clean HIGH pulse:
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Signal readout: The HIGH pulse duration is the time (in microseconds) from sending ping to receiving the echo bumping from an object.
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
// Convert time of flight to distance
cm = (duration/2) / 29.1; // Divide by 29.1
inches = (duration/2) / 74; // Divide by 74
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(200);
}
2. Programmskript für einen Peguino Uno ESP32 Baustein:
Code:
/*
Proximity Brick
(C) 2018 by Peguino LTD
Connect the Proximity Brick to port A
Version 1
Note: Use the Serial Plotter to see the values
Peguino Uno ESP 32 Development Board Pinout
┌─╥─┐
3.3 1 │ │ 30 5V
GND 2 │ │ 29 GND
GPIO15 3 │ │ 28 GPIO13
GPIO2 4 │ │ 27 GPIO12
GPIO4 5 │ │ 26 GPIO14
GPIO16 6 │ │ 25 GPIO27
GPIO17 7 │ │ 24 GPIO26
GPIO5 8 │ │ 23 GPIO25
GPIO18 9 │ │ 22 GPIO33
GPIO19 10 │ │ 21 GPIO32
GPIO21 11 │ │ 20 GPIO35
GPIO3 12 │ │ 19 GPIO34
GPIO1 13 │ │ 18 GPIO39
GPIO22 14 │ │ 17 GPIO36
GPIO23 15 │ │ 16 Chip enable
└───┘
Visit https://www.peguino.com
*/
int trigPin = 2; // Trigger Signal
int echoPin = 15; // Echo
long duration, cm, inches;
void setup() {
//Serial Port begin
Serial.begin (115200); // Press Ctrl+Shift+M and set the serial monitor to the same baud rate!
//Define inputs and outputs
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
// The sensor triggers by a HIGH pulse of 10 or more microseconds - a short LOW pulse first ensures a clean HIGH pulse:
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Signal readout: The HIGH pulse duration is the time (in microseconds) from sending ping to receiving the echo bumping from an object.
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
// Convert time of flight to distance
cm = (duration/2) / 29.1; // Divide by 29.1
inches = (duration/2) / 74; // Divide by 74
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(200);
}