Sabtu, 18 April 2020

Program arduino untuk Alat pengingat Cuci Tangan

Halo sobat Arduino Indonesia, gencar gencarnya cuci tangan pada saat ini guna menaggulangi virus corona atau covid-19. kami sendiri yang sering lupa untuk cuci tangan ketika masuk rumah, berinisiatif untuk membuat alat yang bisa membantu mengingatkan buat cuci tangan.

Bahan-bahan yang diperlukan adalah sebagai berikut :
  1. Arduino nano 
  2. Sensor ultrasonic 
  3. Mp3 Player (DFPlayer mini) 
  4. Speaker 
  5. Breadboard 
  6. Kabel Jumper
untuk penyusunan pengkabelan bisa di lihat di video berikut :



Coding untuk Project Alat pencuci tangan Otomatis adalah sebagai berikut :


/*
 * Alat Cuci Tangan Otomatis
 * Sekolah Robot Indonesia
 */
 #include "Arduino.h"
#include "SoftwareSerial.h"
#include "DFRobotDFPlayerMini.h"
#include <NewPing.h>

#define TRIGGER_PIN  6  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     7  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
SoftwareSerial mySoftwareSerial(4, 2); // RX, TX
DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);

int data = 0;
void setup() {
  mySoftwareSerial.begin(9600);
  Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
Serial.println();
  Serial.println(F("DFRobot DFPlayer Mini Demo"));
  Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));
 
  if (!myDFPlayer.begin(mySoftwareSerial)) {  //Use softwareSerial to communicate with mp3.
    Serial.println(F("Unable to begin:"));
    Serial.println(F("1.Please recheck the connection!"));
    Serial.println(F("2.Please insert the SD card!"));
    while(true){
      delay(0); // Code to compatible with ESP8266 watch dog.
    }
  }
  Serial.println(F("DFPlayer Mini online."));
 
  myDFPlayer.volume(30);  //Set volume value. From 0 to 30
  myDFPlayer.play(1);  //Play the first mp3
}

void loop() {
  delay(50);                     // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  static unsigned long timer = millis();
  Serial.print("Ping: ");
  Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
  Serial.println("cm");
   if(sonar.ping_cm()>1 && sonar.ping_cm() <6)
 {

 if (millis() - timer > 4500) {
    timer = millis();
    myDFPlayer.next();  //Play next mp3 every 3 second.
  }
  }
}

*sumber video : https://youtu.be/dDFZZFkg-d4

1 komentar:

  1. Ford Titanium Ecosport - Titanium Arratic Games
    Ford Titanium, titanium bar Arratic Games created the first virtual game designed titanium hair straightener by independent artists with the intention of titanium density creating titanium damascus knives an titanium trim hair cutter experience of

    BalasHapus