HC-SR04 Demo For Arduino
January 3, 2019DDS Signal Generator – SG100x Operating Guide
January 3, 2019
SDM-IO ultrasonic sensor is non-contact distance measurement module, which is also compatible with electronic brick. It’s designed for easy modular project usage with industrial performance.SDM-IO non-blind area (0cm start measuring) design and fast response, supporting superior performance, especially for car avoidance and robot control.The distance measurement is 0cm~1500mm, resolution is 3mm. Hardware Installation
A short ultrasonic pulse is transmitted at the time T1, reflected by an object. The senor receives this signal and converts it to an electric signal. The next pulse can be transmitted when the echo is faded away. This time period is called cycle period. The recommend cycle period should be no less than 10ms. If a 10μs width trigger pulse is sent to the signal pin, the Ultrasonic module will output some 40kHz ultrasonic signal and detect the echo back, each back pulse width is 150us so there is different to HC-SR04 module.The measured distance we can’t use the echo pulse width to calculate by the formula, but can be calculated by
Formula: distance = (T2 – T1 – 250Us) * (High speed of sound(340M/S)) / 2 // 250us is circuit delay’s time.
The arduino demo you can reference to HC-SR04, but you should note that transmitted signal is LOW to HIGH trigger and you should not use pulseIn() function for the pulse width, however you need start a Timer for count T1 and T2.
The following is a demo for 51:
#include "reg51.h" #include
"sio.h" sbit TRIG = P2^7;
sbit ECHO = P2^6;
#define XTAL 19660800L #define PERIOD12MS (12L * XTAL / 12L / 256L / 1000L)
void delay(unsigned int t) { while(t--) ; }
void main (void) { EA = 0; TMOD &= ~0x0F;
// clear timer 0 mode bits TMOD |= 0x01;
// put timer 0 into MODE 1, 16bit com_initialize ();
/* initialize interrupt driven serial I/O */ com_baudrate (14400);
/* setup for 14400 baud */ EA = 1;
// Enable Interrupts while (1) { START: TR0 = 0; TH0 = 0; TL0 = 0; TRIG = 0;
//Sends a negative pulse, delay(100); TRIG = 1;
//start detect TR0 = 1;
//start timer0 while (ECHO)
//listen ECHO signal { if (TH0 >= PERIOD12MS)
//The cycle period timeout goto START; } TR0 = 0;
//stop timer0 com_putchar(TH0);
//printf com_putchar(TL0);
TR0 = 1; while (TH0 < PERIOD12MS) ;
//keep 12ms cycle period } }