Halo Sobat Arduino, Barusan saya post di video tentang bagaimana cara mengambil data dari website penyedia API untuk sebaran pasien COVID-19 di Indonesia.
Kalau belum lihat videonya, berikut videonya
Oke bahan yang di butuhkan adalah sebagai berikut :
ESP8266 Modul IOT
OLED 1.3"
Kabel Jumper
Projectboard
Susun Seperti berikut ini
Dengan susunan pin sebagai berikut :
OLED --> ESP8266
GND -- GND
VCC -- 3V3
SCL -- D1
SDA -- D2
Untuk API nya bisa registrasi dahulu du web berikut
Serial.begin(115200); //Starting Serial Communication
WiFi.disconnect(true); //Disconecting the WiFi if we are previouly connected.
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64 | You can change this to 0x3C if your display doesn't work
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
//Intro Page - Change according to your needs
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(40, 0);
display.println("DATA");
display.setCursor(20, 20);
display.println("SEBARAN");
display.setTextSize(2);
display.setCursor(5, 40);
display.println("INDONESIA"); // display Country name
display.display();
delay(2000);
WiFi.begin(ssid, password); // Connecting to the WiFi
while (WiFi.status() != WL_CONNECTED) { //Wait till we are connected
animate_oled_wifi(); // Animate it on the Screen
}
display.clearDisplay();
display.display(); //update the display
Serial.println("Connected to the WiFi network");
// Initialize a NTPClient to get time
timeClient.begin();
// Set offset time in seconds to adjust for your timezone, for example:
// GMT +1 = 3600
// GMT +8 = 28800
// GMT -1 = -3600
// GMT 0 = 0
timeClient.setTimeOffset(0);
}
if ((WiFi.status() == WL_CONNECTED)) { //Check the current connection status
HTTPClient http;
http.begin("http://covid.vinteq.in/api/get_data/?country=Indonesia"); //Specify the URL - You can change th country name as per your need to get the country specific data
http.addHeader("auth-key", "authnya dimasukkin sini"); //Insert your Auth-key here in quotes (as String)
int httpCode = http.GET(); //Make the request
if (httpCode > 0) { //Check for the returning code
String payload = http.getString();
// Serial.println(payload); //Print the Payload received
// Parse JSON object
DeserializationError error = deserializeJson(doc, payload);
if (error)
{
Serial.print(F("deserializeJson() failed: "));
Serial.println(error.c_str());
return;
}
root = doc.as<JsonObject>(); //Mapping the data to Json Object
}
http.end(); //Free the resources
}
// Handle the Data
for (JsonPair kv : root) {
if (String(kv.key().c_str()) == "history")
{
HISTORY = kv.value().as<String>();
}
}
//Removing Brackets
HISTORY = HISTORY.substring(0, HISTORY.length() - 1);
HISTORY = HISTORY.substring(1);
// Serial.println(HISTORY);
//We need the latest data - the first one
String DATA = HISTORY.substring(0, HISTORY.indexOf('}') + 1);
// Serial.println(DATA);
DynamicJsonDocument sub_doc(DATA.length() * 2);
DeserializationError error = deserializeJson(sub_doc, DATA); //Converting the Extracted Nested Data from String to Json
root = sub_doc.as<JsonObject>();
for (JsonPair kv : root)
{
//Finding specific keys and extracting their values in varibales
if (String(kv.key().c_str()) == "active_cases")
{
ACTIVE_CASES = kv.value().as<String>() ;
}
if (String(kv.key().c_str()) == "recovered_cases")
{
RECOVERED_CASES = kv.value().as<String>() ;
}
if (String(kv.key().c_str()) == "total_cases")
{
TOTAL_CASES = kv.value().as<String>() ;
}
if (String(kv.key().c_str()) == "deaths")
{
DEATHS = kv.value().as<String>();
}
}
getdate();
/*
This is the display rountine
What it does:
Shows the above extracted data on the OLED Display
Loops again as we need ot to display the same data for 1 minute before new data is fetched (You can change it according to your need)
dealy of 5 seconds x 4 display values = 20 seconds per loop - Repeating for 3 Times = 60 Seconds ~ 1 Minute
*/
for (byte i = 0; i < 3; i++)
{
display.clearDisplay();
display.setTextSize(2);
display.setCursor(8, 0);
display.println("INDONESIA");
display.setCursor(15, 25);
display.setTextSize(2);
display.println("COVID-19");
display.setCursor(30, 50);
display.setTextSize(1);
display.println(currentDate);
display.display();
delay(5000);
// Serial.println(ACTIVE_CASES);
// display.clearDisplay();
// display.setTextSize(2);
// display.setCursor(0, 0);
// display.println("ACTIVE:");
// display.setCursor(0, 30);
// display.setTextSize(3);
// display.println(ACTIVE_CASES);
// display.display();
// delay(5000);
// Serial.println(RECOVERED_CASES);
display.clearDisplay();
display.setTextSize(2);
display.setCursor(0, 0);
display.println("SEMBUH:");
display.setCursor(0, 30);
display.setTextSize(3);
display.println(RECOVERED_CASES);
display.display();
delay(5000);
// Serial.println(DEATHS);
display.clearDisplay();
display.setTextSize(2);
display.setCursor(0, 0);
display.println("MENINGGAL:");
display.setCursor(0, 30);
display.setTextSize(3);
display.println(DEATHS);
display.display();
delay(5000);
// Serial.println(TOTAL_CASES);
display.clearDisplay();
display.setTextSize(2);
display.setCursor(0, 0);
display.println("POSITIF:");
display.setCursor(0, 30);
display.setTextSize(3);
display.println(TOTAL_CASES);
display.display();
delay(5000);
}
}
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 :
Arduino nano
Sensor ultrasonic
Mp3 Player (DFPlayer mini)
Speaker
Breadboard
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.
}
}
}
Sensor suhu contactless atau bisa kita sebut sensor suhu thermogun sekarang ini sangat langka, dan mahal harganya. maka dari itu kami dari Sekolah Robot Indonesia membuat produk baru dan dijadikan tutorial membuat sensor suhu contactless yang terhubung langsung dengan smartphone.
adapun langkah langkah pembuatannya bisa dilihat di youtube