หากต้องการใบเสนอราคา / ใบแจ้งหนี้ ติดต่อได้ทาง LINE Official: @mikroelec |
![]() |
รหัสสินค้า | SKU-02182 |
หมวดหมู่ | เซนเซอร์วัดระยะทาง |
ราคา | 45.00 บาท |
สถานะสินค้า | พร้อมส่ง |
ลงสินค้า | 10 ธ.ค. 2565 |
อัพเดทล่าสุด | 29 ธ.ค. 2567 |
จำนวน | ชิ้น |
Ultrasonic distance sensor HC-SR04+ version 2022. An improved version of the well-known sensor with an extended power range on the RCWL-9610 controller.
The use of the new controller complements the sensor interfaces: I2C, UART and 1-Wire. To change the interface, you need to install jumpers on the contacts on the back of the board.
No soldered jumpers, works exactly the same as the old version of the HC-SR04 module
Specification:
// ตัวอย่างโคด โหมด GPIO (default) – the standard HC-SR04 mode /** HC-SR04 (2022 Version RCWL-9610 Chip) |
//ตัวอย่างโคด โหมด I2C (IIC) /**
HC-SR04 (2022 Version RCWL-9610 Chip)
==========================================
IIC (I2C/TWI "Wire") Control Demonstration
------------------------------------------
This Arduino sketch demonstrates using the IIC
mode of the HC-SR04 2022 Version to read a
distance in centimeters.
To configure the module foro IIC the solder
jumper "M2" (back of board bottom right)
must be closed by putting a blob of solder
on it (M1 must be open, no blob).
-VCC = 3.3V/5.5V
-Trig_RX_SCL_I/O = A5
-Echo_TX_SDA = A4
-GND = GND
*/
#include <Wire.h>
float get_distance_cm()
{
// Setup the connection
static byte WireWasBegun = false;
if(WireWasBegun == false)
{
Wire.begin();
WireWasBegun = true;
}
// We need to delay by at least 30ms between readings
// so we don't get a false reading
static unsigned long lastread = 0;
if(millis() - lastread < 30)
{
delay(millis()-lastread);
}
lastread = millis();
// Send the trigger command 0x01 to the I2C address 0x57
// (the address can not be changed)
Wire.beginTransmission(0x57);
Wire.write(0x01);
Wire.endTransmission();
// Wait 150mS for the ping to complete
delay(150);
// Read 3 bytes from 0x57
byte response[3];
Wire.requestFrom(0x57,3);
for(byte i = 0; Wire.available() && (i <= 2); i++)
{
response[i] = Wire.read();
}
// Those three bytes get assembled like this to get the
// distance in micrometers
float micrometers = ((response[0]*65536UL)+(response[1]*256UL)+response[2]);
// And now we can return that in centimeters
// um / 1000000 = m
// m * 100 = cm
return micrometers / 1000000 * 100;
}
void setup()
{
Serial.begin(9600);
}
void loop()
{
float distance = get_distance_cm();
Serial.print("Distance: ");
Serial.print(distance);
Serial.println("cm");
delay(150);
}
|
//ตัวอย่างโคด โหมด UART
/**
HC-SR04 (2022 Version RCWL-9610 Chip)
==========================================
UART Control Demonstration
------------------------------------------
This Arduino sketch demonstrates using the UARTO
mode of the HC-SR04 2022 Version to read a distance in
centimeters.
To configure the module for UART the solder
jumper "M1" (back of board top right)
must be closed by putting a blob of solder
on it (M2 must be open, no blob).
-VCC = 3.3V/5.5V
-Trig_RX_SCL_I/O = A5
-Echo_TX_SDA = A4
-GND = GND
*/
#include "SoftwareSerial.h"
float get_distance_cm()
{
// Connect the arduino to the SR04 pins as defined here
// (you can change A4 and A5 to any othoer uonused pins for UART mode)
const int SR04_Trig_RX_SCL = A5;
const int SR04_Echo_TX_SDA = A4;
// Create our UART connection to the device using SoftwareSerial
static SoftwareSerial *SR04;
if(!SR04)
{
SR04 = new SoftwareSerial(SR04_Echo_TX_SDA, SR04_Trig_RX_SCL);
SR04->begin(9600);
}
// We need to delay by at least 30ms between readings
// so we don't get a false reading
static unsigned long lastread = 0;
if(millis() - lastread < 30)
{
delay(millis()-lastread);
}
lastread = millis();
// Send the trigger command 0XA0
SR04->flush();
SR04->write(0xA0);
// Wait 150mS for the ping to complete
delay(150);
// Read 3 bytes
byte response[3];
for(byte i = 0; SR04->available() && i <= 2; i++)
{
response[i] = SR04->read();
}
// Those three bytes get assembled like this to get the
// distance in micrometers
float micrometers = ((response[0]*65536UL)+(response[1]*256UL)+response[2]);
// And now we can return that in centimeters
// um / 1000000 = m
// m * 100 = cm
return micrometers / 1000000 * 100;
}
void setup()
{
Serial.begin(9600);
}
void loop()
{
float distance = get_distance_cm();
Serial.print("Distance: ");
Serial.print(distance);
Serial.println("cm");
delay(150);
}
|
หน้าที่เข้าชม | 563,672 ครั้ง |
ผู้ชมทั้งหมด | 321,315 ครั้ง |
ร้านค้าอัพเดท | 19 ต.ค. 2568 |