Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Peguino Proximity Brick
#1
Peguino Proximity Brick

This unit houses and delivers a proximity brick which measures distance with ultrasonic Doppler Effect waves enabling your self driving robot to avoid walls.

[Image: Brick_Proximity_01b.png]


Examples for Peguino Uno Nano and ESP32 V1:

Connect the Proximity Brick to the Peguino Uno Brick Port A. Copy and paste the code below into the Arduino IDE and upload it to the Peguino Uno Brick board.

1. Code example for the Peguino Uno Nano version:

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. Code example for the Peguino Uno ESP 32 version:

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);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)