WisCam Ultrasonic ranging

Laboratory equipment

1.Wiscam Video development board (one)

2. arduino R3 Development board (one)

3. HC-SR04 Ultrasonic ranging module(one)

4. 5V Power Supply (one)

5.Dupont Line (four)

Basic principle

WisCam works in AP or STA mode; in AP mode, the host computer connects the hot spots of WisCam; in STA mode, the WisCam and the upper secret are connected to the same router. Wiscam through the serial port and Arduino serial connection, Arduino connect an ultrasonic ranging module, and then measured distance through the serial port to WisCam, and finally transferred from WisCam to the upper computer (Windows PC side).

Hardware connection

The Wiscam is directly inserted into the Arduino base on (port complete docking), as shown in Figure 2 HC-SR04 ultrasonic ranging module Trig connected to Arduino Pin 8 and Echo Pin 9 feet by Arduino (can be customized in the program), HC-SR04 VCC (Arduino) VCC 5V, HC-SR04 GND (Arduino) GND. After the assembly, power is supplied to the Wiscam individually (5V) or to the Arduino (5V).

Figure 1

Figure 2

Test code

1.Upper computer software (source code)

(1)Control interface

(2)Download address

https://github.com/RAKWireless/wiscam-Ultrasonic-ranging.git

2.Lower computer (Arduino code)

// 引脚定义

const int trig = 8; // Trigger signal

const int echo = 9; // Feedback signal

char sen[1];

int flase = 0;

//Initialization

void setup() {

pinMode(echo, INPUT);//the feedback port is set as input

pinMode(trig, OUTPUT);//The trigger port is set to output

Serial.begin(115200);

while (!Serial)

{

; // wait for serial port to connect. Needed for Leonardo only

}

}

//Main cycle

void loop() {

long IntervalTime=0; //Define a time variable

digitalWrite(trig, 1);//set high level

delayMicroseconds(15);//delay 15us

digitalWrite(trig, 0);//set low level

IntervalTime=pulseIn(echo, HIGH);//The width of the high level of the feedback from the built-in functions, the unit us

float S=IntervalTime/58.00;

//Use floating point to compute the distance, the unit cm

Serial.println(S);//output distance by serial port

if (Serial.available() > 0)

{

flase = 1;

for (int i = 0; i < 1; i++)

{

sen[i] = S;

Serial.write(sen[i] );

}

}

S=0;IntervalTime=0;//The corresponding value is cleared

delay(500);

//The delay interval determines the frequency of the sampling

}