Hello everyone, I saw someone controlling a number of LEDS using Ultrasonic HC-SR04 by changing the distance between hand and ultrasonic sensor. I also saw youtube videos showing two Arduinos communicate with each other using two HC-05.
I plan to combine those two systems, in which the Master consisting of (Arduino + HC-05 + HC-SR04) and the slave consisting of (Arduino + HC-05 + LED or DC motors, servo, etc). When I change the distance between my hand and the HCSR04, the LED or motors will activate accordingly.
In other words, its a wirelessly hand-gesture (sort-of) system control. Has anyone ever done this? Is it possible to execute this kind of project? Where can I find references? Thank you very much.
If the said project is feasible, I might consider to employ 7 or 8 HCSR04 Ultrasonic sensors for the Master. Is there any limit to the number of HCSR04 I can use?
Theoretically not I suppose. One limit is the number of usefule I/O pins available.
Split the project in smaller parts. One is to read the HS-SR04 and learn how to run it.
Number two can be operating the communication using the HC-05. When that works You know that piece.
Cocking together a kind of protocol for sending several parameters and recover them at the receiver is the third.
Then You can start to integrate the parts, one new at the time.
Here is some example code using one HCSR04 rangefinder to get distance and send via a HC05 Bluetooth module on an Uno to another Uno with a bound HC05. Serial reception code from the serial input basics tutorial. This code has been tested and works as advertised.
Sender (master):
//Bluetooth Master
//Sends the ultrasonic distance to the Slave
#include <SoftwareSerial.h>
SoftwareSerial BTserial(4, 7); // RX | TX
// defines pins numbers
const int trigPin = 5;
const int echoPin = 6;
// defines variables
long duration;
int distance;
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
BTserial.begin(9600);
Serial.println("Sonar sender starting");
BTserial.println("Sonar sender starting");
}
void loop()
{
static unsigned long timer = 0;
unsigned long interval = 1000;
if (millis() - timer >= interval)
{
timer = millis();
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
// Send the distance via Bluetooth
BTserial.println(distance);
}
}