FPP

by 679930 in Circuits > Arduino

215 Views, 0 Favorites, 0 Comments

FPP

Screen Shot 2022-01-20 at 4.36.30 PM.png

The closer your hand gets to the HC-SRO4, the LEDs should progressively light up until and the closer your hand gets, the buzzer will produce a higher tone each time.

Buzzer

Which is an electrical device, similar to a bell, that makes a buzzing noise and is used for signalling.It is usually powered by DC voltage. It is widely used in alarms, computers, printers and other electronic products as sound devices.

Ultrasonic proximity sensor

An ultrasonic sensor is an instrument that measures the distance to an object using ultrasonic sound waves. An ultrasonic sensor uses a transducer to send and receive ultrasonic pulses that relay back information about an object's proximity

Supplies

Exquisite Jarv.png

supplies needed:

  1. Breadboard
  2. 330 resistors(7)
  3. Buzzer
  4. Ultrasonic Distance Sensor
  5. Leds(7)
  6. Slideswitch
  7. Some wires
  8. Arduino

Connecting the Components (how-to Lesson)

Copy of fp.png

The ultrasonic distance sensor includes 4 pins
Vcc

Trig

EchoGnd

The Vcc slot for voltage connecting it to the voltage in the Arduino supplying power. the trig and echo directing connecting to pin 7 and 6 on the Arduino and the ground cable also connecting to the Arduino but supplying ground.

The buzzer has 2 pins, positive and negative. Positive connecting to the resistor and Negative connecting to pin 3 on the Arduino.

Each LEDs anode connects to a 330 resistor and the cathode connects to a different pin in the Arduino. And finally, a slide switch has 3 pins: terminal 1, common and terminal 2 . Terminal 1 is connected to the ground on the breadboard and the common is connected to a pin in the Arduino and finally, terminal 2 is connected to power on the breadboard.

And finally connecting a power and ground wire with the power and ground in the Arduino which has pins saying gnd and 5V on the left side of the Arduino.

Code

10-1.jpeg

int trigPin = 7;
int echopin = 6;

int led = 13; int

led2 = 12;

int led3 = 11;

int led4 = 10;

int led5 = 9;

int led6 = 8;

int buzzer = 3;

int master = 4;

int led7 = 2;

int sound = 250;

void setup() { Serial.begin (9600);

pinMode(trigPin, OUTPUT);

pinMode(echopin, INPUT);

pinMode(led, OUTPUT);

pinMode(led2, OUTPUT);

pinMode(led3, OUTPUT);

pinMode(led4, OUTPUT);

pinMode(led5, OUTPUT);

pinMode(led6, OUTPUT);

pinMode(buzzer, OUTPUT);

pinMode (master, INPUT);

pinMode (led7, OUTPUT) ; }

void loop() { long duration, distance;

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echopin, HIGH);

distance = (duration/2) / 29.1;

if (distance <= 30) { digitalWrite(led, HIGH); sound = 250; }

else { digitalWrite(led,LOW); }

if (distance < 25) { digitalWrite(led2, HIGH); sound = 260; }

else { digitalWrite(led2, LOW); }

if (distance < 20) { digitalWrite(led3, HIGH); sound = 270; }

else { digitalWrite(led3, LOW); }

if (distance < 15) { digitalWrite(led4, HIGH); sound = 280; }

else { digitalWrite(led4,LOW); }

if (distance < 10) { digitalWrite(led5, HIGH); sound = 290; }

else { digitalWrite(led5,LOW); }

if (distance < 5) { digitalWrite(led6, HIGH); sound = 300; }

else { digitalWrite(led6,LOW); }

if (distance > 30 || distance <= 0){ Serial.println("Out of range");

noTone(buzzer); }

else { Serial.print(distance); Serial.println(" cm"); tone(buzzer, sound);

} delay(500);

int M; if (digitalRead(master)==1){ digitalWrite(led7, HIGH);

digitalWrite(led6, HIGH);

digitalWrite(led5, HIGH);

digitalWrite(led4, HIGH);

digitalWrite(led3, HIGH);

digitalWrite(led2, HIGH);

digitalWrite(led, HIGH);

digitalWrite(buzzer, HIGH);

delay(100); // Wait for 100 millisecond(s) distance==1;

} else { digitalWrite(led7, LOW);

digitalWrite(led6, LOW);

digitalWrite(led5, LOW);

digitalWrite(led4, LOW);

digitalWrite(led3, LOW);

digitalWrite(led2, LOW);

digitalWrite(led, LOW);

digitalWrite(buzzer, LOW); delay(100); // Wait for 100 millisecond(s) distance==0; } }