Devices & Components
Arduino Uno Rev3
SG90 Micro-servo motor
Ceiling Speaker, Two-Way
DFPlayer Mini Mp3 Modul
Ultrasonic Sensor - HC-SR04 (Generic)
Project description
Code
Code
arduino
For this project, we used a simple coding by using Arduino.IDE app.
1#include<Servo.h> 2#include <SoftwareSerial.h> 3#include <DFPlayer_Mini_Mp3.h> 4 5SoftwareSerial mySerial(10, 11); 6 7Servo servo; 8int const trigPin = 6; 9int const echoPin = 5; 10void setup() 11{ 12 Serial.begin (9600); 13mySerial.begin (9600); 14mp3_set_serial (mySerial); 15delay(10); 16pinMode(trigPin, OUTPUT); 17pinMode(echoPin, INPUT); 18 servo.attach(3); 19} 20void loop() 21{ int duration, distance; 22digitalWrite(trigPin, HIGH); 23delay(1); 24digitalWrite(trigPin, LOW); 25// Measure the pulse input in echo pin 26duration = pulseIn(echoPin, HIGH); 27// Distance is half the duration devided by 29.1 (from datasheet) 28distance = (duration/2) / 29.1; 29// if distance less than 0.5 meter and more than 0 (0 or less means over range) 30if (distance <= 20 && distance >= 0) { 31 servo.write(50); 32 delay(3000); 33} else { 34 35 servo.write(160); 36 void setup () ; 37{ 38mp3_set_volume (95); 39delay(10); 40mp3_play (); 41delay(10); 42mp3_play (1); 43delay(10); 44} 45} 46 47// Waiting 60 ms won't hurt any one 48delay(40); 49} 50
Downloadable files
SCHEMATIC
SCHEMATIC

SCHEMATIC
SCHEMATIC

Comments
Only logged in users can leave comments