Translate
Timer Counter Balapan Mini 4WD RACING TAMIYA
Arduino Smart Home
Arduino Smart Home
b. Program Arduino IDE
#include <SPI.h>
#include <Keypad.h>
#include <Adafruit_PN532.h>
#include "DHT.h" //library dht11
#include <LiquidCrystal_I2C.h> //i2C LCD Library
#include <DS3231.h>
#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); //library i2c lcd 16x2
LiquidCrystal_I2C lcd2(0x3E, 20, 4); //library i2c lcd 16x2
SoftwareSerial mySerial(10,11); // RX, TX
#define DHTPIN 28 // pin digital untuk dht11
#define DHTTYPE DHT11 // set dht11
#define trigPin 37
#define echoPin 35
DHT dht(DHTPIN, DHTTYPE); //set dht11
// If using the breakout with SPI, define the pins for SPI communication.
#define PN532_SCK (2)
#define PN532_MOSI (3)
#define PN532_SS (4)
#define PN532_MISO (5)
#define IRQ (2)
#define RESET (3)
Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS);
//Adafruit_NFCShield_I2C nfc(IRQ, RESET);
int sw1 = A3;
int sw2 = A5;
int sw3 = A7;
int sw1x;
int sw2x;
int sw3x;
float h;
float t;
long duration, distance;
int mq6,mq3;
int suara;
int api;
int hujan;
int pir;
int ledm = 23;
int ledk = 25;
int ledh = 27;
long first;
int relaykipas1 = 31;
int relaykipas2 = 29;
int buzzer = 16;
char customKey;
const byte ROWS = 4;
const byte COLS = 4;
DS3231 rtc(SDA, SCL);
char keys[ROWS][COLS] = {
{'/', 'C', '-', '+'},
{'=', '9', '6', '3'},
{'0', '8', '5', '2'},
{'*', '7', '4', '1'}
};
byte rowPins[ROWS] = {32,A14,A12,A10}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {A8,A6,A4,A2}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
pinMode(sw1,INPUT_PULLUP);
pinMode(sw2,INPUT_PULLUP);
pinMode(sw3,INPUT_PULLUP);
Serial.begin(9600);
//Serial.println("Hello!");
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
//Serial.print("Didn't find PN53x board");
while (1); // halt
}
// Got ok data, print it out!
//Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
//Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
//Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
// configure board to read RFID tags
nfc.SAMConfig();
//Serial.println("Waiting for an ISO14443A Card ...");
//Serial.begin(9600);
lcd.begin(); //set lcd i2c
lcd.noCursor(); //biar gak ada cursor di lcd
lcd.clear(); //clear lcd
lcd2.begin(); //set lcd i2c
lcd2.noCursor(); //biar gak ada cursor di lcd
lcd2.clear(); //clear lcd
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(suara, INPUT);
pinMode(api, INPUT);
pinMode(hujan, INPUT);
pinMode(pir, INPUT);
pinMode(ledm, OUTPUT);
pinMode(ledk, OUTPUT);
pinMode(ledh, OUTPUT);
digitalWrite(ledm,LOW);
digitalWrite(ledk,HIGH);
digitalWrite(ledh,LOW);
pinMode(buzzer, OUTPUT);
digitalWrite(buzzer,LOW);
pinMode(relaykipas1, OUTPUT);
pinMode(relaykipas2, OUTPUT);
digitalWrite(relaykipas1,HIGH);
digitalWrite(relaykipas2,HIGH);
rtc.begin();
// The following lines can be uncommented to set the date and time
//rtc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(10, 22, 0); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(12, 14, 2022); // Set the date to January 1st, 2014
mySerial.begin(9600);
mp3_set_serial(mySerial); //set softwareSerial for DFPlayer-mini mp3 module
delay(1); //wait 1ms for mp3 module to set volume
mp3_set_volume(30); //volume 0-30
inputkartu();
inputpasswd();
}
void loop() {
customKey = customKeypad.getKey();
switch(customKey)
{
case 'B':
inputpasswd();
break;
}
suara = digitalRead(18);
api = digitalRead(26);
hujan = digitalRead(24);
pir = digitalRead(30);
mq6 = analogRead(A0);
mq3 = analogRead(A1);
h = dht.readHumidity(); //ambil data humidity
t = dht.readTemperature(); //ambil data suhu c
digitalWrite(trigPin, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
sw1x = digitalRead(sw1);
sw2x = digitalRead(sw2);
sw3x = digitalRead(sw3);
lcd.setCursor(0,0);
lcd.print("LOGIN");
lcd2.setCursor(0,0);
lcd2.print("T/H:");
lcd2.print(t,0);lcd2.print("/");lcd2.print(h,0);lcd2.print(" ");
lcd2.print("S:");
lcd2.print(distance);lcd2.print(" ");
lcd2.setCursor(0,1);
lcd2.print("Q6:");lcd2.print(mq6);lcd2.print(" ");
lcd2.print("Q3:");lcd2.print(mq3);lcd2.print(" ");
lcd2.setCursor(0,2);
lcd2.print("S/A/H/P:");lcd2.print(suara);lcd2.print("/");lcd2.print(api);lcd2.print("/");lcd2.print(hujan);lcd2.print("/");lcd2.print(pir);
lcd2.setCursor(0,3);
lcd2.print(rtc.getTimeStr());
lcd2.print(" ");
lcd2.print(sw1x);
lcd2.print(sw2x);
lcd2.print(sw3x);
Serial.print("*");
Serial.print(t);
Serial.print(",");
Serial.print(h);
Serial.print(",");
Serial.print(distance);
Serial.print(",");
Serial.print(mq6);
Serial.print(",");
Serial.print(mq3);
Serial.print(",");
Serial.print(suara);
Serial.print(",");
Serial.print(api);
Serial.print(",");
Serial.print(hujan);
Serial.print(",");
Serial.print(pir);
Serial.println("#");
delay(1000);
}
void inputpasswd(){
lcd.setCursor(0,0);
lcd.print("INPUT PASSWD");
customKey = customKeypad.getKey();
switch(customKey)
{
case '0' ... '9': // This keeps collecting the first value until a operator is pressed "+-*/"
lcd.setCursor(0,1);
first = first * 10 + (customKey - '0');
lcd.print(first);
break;
case 'C':
if(first == 1234){
lcd.clear();
lcd.setCursor(0,1);
lcd.print("BENAR");
mp3_play(1); //play music file 0001.mp3
delay(10000);
mp3_stop();
digitalWrite(relaykipas1,LOW);
digitalWrite(relaykipas2,LOW);
lcd.clear();
return;
}
first = 0;
lcd.clear();
break;
}
inputpasswd();
}
void inputkartu(void){
lcd.setCursor(0,0);
lcd.print("DEKATKAN KARTU");
uint8_t success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
// Wait for an ISO14443A type cards (Mifare, etc.). When one is found
// 'uid' will be populated with the UID, and uidLength will indicate
// if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
if (success) {
lcd.clear();
// Display some basic information about the card
//Serial.println("Found an ISO14443A card");
//Serial.print(" UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
//Serial.print(" UID Value: ");
//nfc.PrintHex(uid, uidLength);
if (uidLength == 4)
{
// We probably have a Mifare Classic card ...
uint32_t cardid = uid[0];
cardid <<= 8;
cardid |= uid[1];
cardid <<= 8;
cardid |= uid[2];
cardid <<= 8;
cardid |= uid[3];
//Serial.print("Seems to be a Mifare Classic card #");
//Serial.println(cardid); //3495259931
lcd.setCursor(0,0);
lcd.print(cardid);
delay(2000);
if(cardid == 3495259931){
lcd.clear();
lcd.setCursor(0,1);
lcd.print("BENAR");
digitalWrite(ledm,LOW);
digitalWrite(ledk,LOW);
digitalWrite(ledh,HIGH);
digitalWrite(buzzer,HIGH);
delay(100);
digitalWrite(buzzer,LOW);
delay(100);
digitalWrite(buzzer,HIGH);
delay(100);
digitalWrite(buzzer,LOW);
delay(2000);
lcd.clear();
return;
}
else{
digitalWrite(ledm,HIGH);
digitalWrite(ledk,LOW);
digitalWrite(ledh,LOW);
digitalWrite(buzzer,HIGH);
delay(100);
digitalWrite(buzzer,LOW);
delay(100);
digitalWrite(buzzer,HIGH);
delay(100);
digitalWrite(buzzer,LOW);
delay(100);
digitalWrite(buzzer,HIGH);
delay(100);
digitalWrite(buzzer,LOW);
digitalWrite(ledm,LOW);
digitalWrite(ledk,HIGH);
digitalWrite(ledh,LOW);
delay(2000);
}
//Serial.println("");
}
}
inputkartu();
}
c. Program NodeMCU ESP8266
d. VIDEO HASILNYA
Pasien Monitor (Suhu Tubuh, Bpm, SpO2) Server Thingspeak
Pasien Monitor (Suhu Tubuh, Bpm, SpO2) Server Thingspeak
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengukur suhu tubuh dan Bpm - SpO2 dengan menggunakan nodemcu esp8266, data yang didapat lalu dikirimkan ke server Thingspeak. untuk lebih jelasnya berikut adalah komponen dan programnya
a. Komponen
b. Program Arduino IDE
#include <Wire.h>
#include <ESP8266WiFi.h>
#include "ThingSpeak.h"
#include <LiquidCrystal_I2C.h>
#include <Adafruit_MLX90614.h>
#include <MAX30100_PulseOximeter.h>
#define REPORTING_PERIOD_MS 5000
#include "MAX30100.h" //library sensor
LiquidCrystal_I2C lcd(0x27,16,2); //library lcd
MAX30100* pulseOxymeter; //library
int cacah; //membuat variabel
int spo;
float bpm;
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
float TargetC;
int dataadc;
int suhunya;
int bpmku;
int counter;
PulseOximeter pox;
uint32_t tsLastReport = 0;
String hrData = "";
void onBeatDetected()
{
// Serial.println("Beat!");
}
int pinreset = D6;
WiFiClient client;
// ThingSpeak Settings
String apiKey = "QWERTY123456HJK7";
const char *ssid = "wifihpku";
const char *pass = "123456789";
const char* server = "api.thingspeak.com";
const char* resource = "/update?api_key=";
void setup() {
Wire.begin();
mlx.begin();
Serial.begin(9600);
lcd.begin();
lcd.clear();
pinMode(pinreset,OUTPUT);
digitalWrite(pinreset,HIGH);
//setting ke online
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED){\
delay(200);
Serial.println(".");
}
Serial.println("");
Serial.println("WiFi connected");
//Serial.print("Initializing pulse oximeter..");
if (!pox.begin()) {
//Serial.println("FAILED");
for(;;);
} else {
//Serial.println("SUCCESS");
}
pox.setIRLedCurrent(MAX30100_LED_CURR_11MA);
pox.setOnBeatDetectedCallback(onBeatDetected);
}
void loop(){
pox.update();
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
bpm = pox.getHeartRate();
spo = pox.getSpO2();
bpmku = bpm;
lcd.setCursor(0,1);
lcd.print("B/S:");
lcd.print(pox.getHeartRate());
lcd.print("/");
lcd.print(pox.getSpO2());
lcd.print(" ");
tsLastReport = millis();
}
mlx.begin();
TargetC = mlx.readObjectTempC();
suhunya = TargetC;
lcd.setCursor(0,0);
lcd.print("T: ");
lcd.print(suhunya);
lcd.print(" C ");
if((bpm > 75)&&(bpm < 110)&&(spo > 95)&&(spo < 100)&&(suhunya > 33)&&(suhunya < 40)){
if (client.connect(server,80)) // "184.106.153.149" or api.thingspeak.com
{
String postStr = apiKey;
postStr +="&field1=";
postStr += String(bpm);
postStr += "\r\n\r\n";
client.print(String("GET ") + resource + apiKey + "&field1=" + bpm + "&field2=" + spo + "&field3=" + suhunya + " HTTP/1.1\r\n" + "Host: " + server + "\r\n" + "Connection: close\r\n\r\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.println(". Send to Thingspeak.");
}
client.stop();
Serial.println("Waiting...");
delay(10000);
}
}
c.VIDEO HASILNYA
Deteksi Warna RGB TCS3200 Nodemcu WIFI IP Local
#include <ESP8266WiFi.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // change your I2C ADDRESS HERE EXAMPLE 0x3F
const char *ssid = "TP-Link"; // Enter your WiFi name
const char *password = "123456789"; // Enter WiFi password
WiFiServer server(80);
const int s0 = D3;
const int s1 = D4;
const int s2 = D5;
const int s3 = D6;
const int out = D7;
int red = 0;
int green = 0;
int blue = 0;
int redcolor= 0;
int greencolor= 0;
int bluecolor= 0;
int yellowcolor= 0;
int color= 0;
void setup()
{
Serial.begin(9600);
lcd.begin();
lcd.clear();
lcd.noCursor();
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Start the server
server.begin();
Serial.println("Server started");
// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
pinMode(s0, OUTPUT);
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);
pinMode(out, INPUT);
digitalWrite(s0, HIGH);
digitalWrite(s1, HIGH);
}
void loop()
{
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}
// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
//count OUT, pRed, RED
red = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);
lcd.setCursor(0,0);
lcd.print("R:");
lcd.print(red);
lcd.print("");
digitalWrite(s3, HIGH);
//count OUT, pBLUE, BLUE
blue = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);
lcd.print("B:");
lcd.print(blue);
lcd.print("");
digitalWrite(s2, HIGH);
//count OUT, pGreen, GREEN
green = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);
lcd.print("G:");
lcd.print(green);
lcd.print(" ");
// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Refresh: 1");
client.println(""); // do not forget this one
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<center>");
client.println("<h1>");
client.println("DETEKSI WARNA");
client.println("</h1>");
client.println("<h3>");
client.println("R = ");
client.println(red);
client.println("<br>");
client.println("B = ");
client.println(blue);
client.println("<br>");
client.println("G = ");
client.println(green);
client.println("<br>");
client.println("</h3>");
client.println("</center>");
client.println("</html>");
delay(1);
Serial.println("Client disonnected");
Serial.println("");
delay(1000);
}