Introduction: Virtual Bumper
The kids are constantly fighting ?
Let them wear the virtual bumper,
set the distance to your prefernce.
The bumper will worn them whenever they are too close to, well, everything...
Let them wear the virtual bumper,
set the distance to your prefernce.
The bumper will worn them whenever they are too close to, well, everything...
Step 1: Parts :
-Arduino pro mini
-4 HC-SR04 ultra sonic distance meter
-Small breadboard
-Vibration motor
-Potentiometer
-Few 220ohm resistors
-PNP Transistor
-Battary ?
-A belt
-Some zip ties
-Cables
-4 HC-SR04 ultra sonic distance meter
-Small breadboard
-Vibration motor
-Potentiometer
-Few 220ohm resistors
-PNP Transistor
-Battary ?
-A belt
-Some zip ties
-Cables
Step 2: Diagram
There are 4 distace meters connected together to the arduino at the vcc, gnd and trig pins.
trig pin connected to arduino´s pin 3.
each distance meter connected by it self from the echo pin to arduino´s 4-7 pins.
The potentiometer connects to 5v and gnd and its output pin to arduino´s analog pin 3.
The transistor connected to pin 3 at the gate and also connects the ground through a led and a resistor.
The Vibration motor connects the emitter for power and also connects to ground.
* Note that the pic is an old ver, i made changes on build, fllow the discription.
trig pin connected to arduino´s pin 3.
each distance meter connected by it self from the echo pin to arduino´s 4-7 pins.
The potentiometer connects to 5v and gnd and its output pin to arduino´s analog pin 3.
The transistor connected to pin 3 at the gate and also connects the ground through a led and a resistor.
The Vibration motor connects the emitter for power and also connects to ground.
* Note that the pic is an old ver, i made changes on build, fllow the discription.
Step 3: The Code
#define trigPin 3 //Sonar Triger
#define echoPinL 4 //Left sonar echo
#define echoPinF 5 //Front sonar echo
#define echoPinR 6 //Right sonar echo
#define echoPinB 7 //Back sonar echo
#define Vibrate 10 //Vibrate + Led pin
#define disSelect A3 //Distance Selector analog pin
int durationL, durationF, durationR, durationB, distanceL, distanceF, distanceR, distanceB, dSelValue;
void setup() {
Serial.begin (9600);
pinMode (trigPin, OUTPUT);
pinMode (echoPinL, INPUT);
pinMode (echoPinF, INPUT);
pinMode (echoPinR, INPUT);
pinMode (echoPinB, INPUT);
pinMode (Vibrate, OUTPUT);
pinMode (disSelect, INPUT);
pinMode (13, OUTPUT);
digitalWrite (13, LOW);
}
void loop() {
dSelValue = map (analogRead (disSelect),0,1023,20,400);
Serial.print ("Distance Select : ");
Serial.println (dSelValue);
triger();
durationL = pulseIn (echoPinL, HIGH);
distanceL = (durationL/2) /29.1;
Serial.print ("Left = ");
Serial.println (distanceL);
//Serial.print ("Triger = ");
//Serial.println (digitalRead (trigPin));
delay (200);
triger();
durationF = pulseIn (echoPinF, HIGH);
distanceF = (durationF/2) /29.1;
Serial.print ("Front = ");
Serial.println (distanceF);
//Serial.print ("Triger = ");
//Serial.println (digitalRead (trigPin));
delay (200);
triger();
durationR = pulseIn (echoPinR, HIGH);
distanceR = (durationR/2) /29.1;
Serial.print ("Right = ");
Serial.println (distanceR);
//Serial.print ("Triger = ");
//Serial.println (digitalRead (trigPin));
delay (200);
triger();
durationB = pulseIn (echoPinB, HIGH);
distanceB = (durationB/2) /29.1;
Serial.print ("Back = ");
Serial.println (distanceB);
//Serial.print ("Triger = ");
//Serial.println (digitalRead (trigPin));
delay (200);
if ( distanceL <= dSelValue || distanceF <= dSelValue || distanceR <= dSelValue || distanceB <= dSelValue ) {
for (int times=1; times <=8; times++) {
Serial.println (times);
digitalWrite (Vibrate, HIGH);
digitalWrite (13, HIGH);
delay (100);
digitalWrite (Vibrate, LOW);
digitalWrite (13, LOW);
delay (100);
}
}
}
void triger() {
digitalWrite (trigPin, LOW);
//digitalWrite (13, LOW);
delayMicroseconds (1000);
digitalWrite (trigPin, HIGH);
//digitalWrite (13, HIGH);
//Serial.print ("Triger = ");
//Serial.println (digitalRead (trigPin));
delayMicroseconds (1000);
digitalWrite (trigPin, LOW);
//digitalWrite (13, LOW);
}
#define echoPinL 4 //Left sonar echo
#define echoPinF 5 //Front sonar echo
#define echoPinR 6 //Right sonar echo
#define echoPinB 7 //Back sonar echo
#define Vibrate 10 //Vibrate + Led pin
#define disSelect A3 //Distance Selector analog pin
int durationL, durationF, durationR, durationB, distanceL, distanceF, distanceR, distanceB, dSelValue;
void setup() {
Serial.begin (9600);
pinMode (trigPin, OUTPUT);
pinMode (echoPinL, INPUT);
pinMode (echoPinF, INPUT);
pinMode (echoPinR, INPUT);
pinMode (echoPinB, INPUT);
pinMode (Vibrate, OUTPUT);
pinMode (disSelect, INPUT);
pinMode (13, OUTPUT);
digitalWrite (13, LOW);
}
void loop() {
dSelValue = map (analogRead (disSelect),0,1023,20,400);
Serial.print ("Distance Select : ");
Serial.println (dSelValue);
triger();
durationL = pulseIn (echoPinL, HIGH);
distanceL = (durationL/2) /29.1;
Serial.print ("Left = ");
Serial.println (distanceL);
//Serial.print ("Triger = ");
//Serial.println (digitalRead (trigPin));
delay (200);
triger();
durationF = pulseIn (echoPinF, HIGH);
distanceF = (durationF/2) /29.1;
Serial.print ("Front = ");
Serial.println (distanceF);
//Serial.print ("Triger = ");
//Serial.println (digitalRead (trigPin));
delay (200);
triger();
durationR = pulseIn (echoPinR, HIGH);
distanceR = (durationR/2) /29.1;
Serial.print ("Right = ");
Serial.println (distanceR);
//Serial.print ("Triger = ");
//Serial.println (digitalRead (trigPin));
delay (200);
triger();
durationB = pulseIn (echoPinB, HIGH);
distanceB = (durationB/2) /29.1;
Serial.print ("Back = ");
Serial.println (distanceB);
//Serial.print ("Triger = ");
//Serial.println (digitalRead (trigPin));
delay (200);
if ( distanceL <= dSelValue || distanceF <= dSelValue || distanceR <= dSelValue || distanceB <= dSelValue ) {
for (int times=1; times <=8; times++) {
Serial.println (times);
digitalWrite (Vibrate, HIGH);
digitalWrite (13, HIGH);
delay (100);
digitalWrite (Vibrate, LOW);
digitalWrite (13, LOW);
delay (100);
}
}
}
void triger() {
digitalWrite (trigPin, LOW);
//digitalWrite (13, LOW);
delayMicroseconds (1000);
digitalWrite (trigPin, HIGH);
//digitalWrite (13, HIGH);
//Serial.print ("Triger = ");
//Serial.println (digitalRead (trigPin));
delayMicroseconds (1000);
digitalWrite (trigPin, LOW);
//digitalWrite (13, LOW);
}