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);
}
Kendali Kecepatan Motor AC Modul Dimmer Zero Crossing 4A Arduino
Kendali Kecepatan Motor AC Modul Dimmer Zero Crossing 4A Arduino
Monitor Kemiringan Menggunakan IP Local Sensor GY-521 (MPU-6050)
Monitor Kemiringan Menggunakan IP Local Sensor GY-521 (MPU-6050)
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengukur tingkat kemiringan suatu dataran atau benda dengan menggunakan sensor GY-521 / MPU-6050 dan mikrokontroller yang dipakai yaitu wemos D1 mini. alat ini bisa memonitor tingkat kemiringan dengan menggunakan IP Address local sehingga membutuhkan suatu router sebagai medianya pengiriman sinyalnya dikarenakan menggunakan wifi. untuk lebih jelasnya berikut adalah komponen dan kodingnya.
a. Komponen
b. Program Arduino IDE
#include<Wire.h>
#include <ESP8266WiFi.h>
#include <EEPROM.h>
const char *ssid = "TP-Link_65A4"; // Enter your WiFi name
const char *password = ""; // Enter WiFi password
//int ledPin = D0;
WiFiServer server(80);
//I2C Address for MPU6050
const int MPU=0x68; // Can be 0x69 if AD0 Pin is True (VCC)
//Variables for raw values from MPU ADC
int AcX,AcY,AcZ,GyX,GyY,GyZ;
int16_t Tmp;
int minVal=0;
int maxVal=65536; //2^16 levels from MPU6050 ADC
int offsetTemp = 35; // from MPU datasheet
int offsetTempLevels = 521; // from MPU datasheet
void setup() {
Serial.begin(9600); // Begin Serial communication
Wire.begin();
Wire.beginTransmission(MPU); // begin transmission with MPU address
Wire.write(0x6B);
//Start MPU-6050 sensor
Wire.write(0);
Wire.endTransmission(true);
delay(10);
// pinMode(ledPin, OUTPUT);
// digitalWrite(ledPin, LOW);
// 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("/");
}
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();
Wire.beginTransmission(MPU);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
//Get data from Sensor (14 consecutive bytes)
Wire.requestFrom(MPU,14,true);
//Read data byte by byte (16 bits is 8 bits | 8 bits)
//Each value is composed by 16 bits (2 bytes)
GyX=Wire.read()<<8|Wire.read(); //0x3B (GYRO_XOUT_H) & 0x3C (GYRO_XOUT_L)
GyY=Wire.read()<<8|Wire.read(); //0x3D (GYRO_YOUT_H) & 0x3E (GYRO_YOUT_L)
GyZ=Wire.read()<<8|Wire.read(); //0x3F (GYRO_ZOUT_H) & 0x40 (GYRO_ZOUT_L)
Tmp=Wire.read()<<8|Wire.read(); //0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
AcX=Wire.read()<<8|Wire.read(); //0x43 (ACCEL_XOUT_H) & 0x44 (ACCEL_XOUT_L)
AcY=Wire.read()<<8|Wire.read(); //0x45 (ACCEL_YOUT_H) & 0x46 (ACCEL_YOUT_L)
AcZ=Wire.read()<<8|Wire.read(); //0x47 (ACCEL_ZOUT_H) & 0x48 (ACCEL_ZOUT_L)
//Adapts to range from 0 to 2000 m/s^2
AcX = map(AcX,minVal,maxVal,2000,0);
AcY = map(AcY,minVal,maxVal,2000,0);
AcZ = map(AcZ,minVal,maxVal,2000,0);
//Adapts to range from -180º to 180º
int xAng = map(GyX,minVal,maxVal,180,-180);
int yAng = map(GyY,minVal,maxVal,180,-180);
int zAng = map(GyZ,minVal,maxVal,180,-180);
//Send X axis accelerometer value for serial monitor
Serial.print("AcX = "); Serial.print(AcX);
//Send Y axis accelerometer value for serial monitor
Serial.print(" | AcY = "); Serial.print(AcY);
//Send Z axis accelerometer value for serial monitor
Serial.print(" | AcZ = "); Serial.print(AcZ);
//Send Temperature value for serial
//Calculates the temperature given the datasheet values (ºC)
// 340 is the number of levels per ºC (from datasheet)
Serial.print(" | Tmp = "); Serial.print(float(Tmp + offsetTempLevels)/340 + offsetTemp);
//Send X axis gyroscope angle value for serial monitor
Serial.print(" | GyX = "); Serial.print(xAng);
//Send Y axis gyroscope angle value for serial monitor
Serial.print(" | GyY = "); Serial.print(yAng);
//Send Z axis gyroscope angle value for serial monitor
Serial.print(" | GyZ = "); Serial.println(zAng);
// 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("Monitoring Kemiringan");
client.println("</h1>");
client.println("<h3>");
client.println("X = ");
client.println(AcX);
client.println("<br>");
client.println("Y = ");
client.println(AcY);
client.println("<br>");
client.println("Z = ");
client.println(AcZ);
client.println("<br>");
client.println("</h3>");
client.println("<a href = \"/?lighton\"\"><input type = 'button' value = 'DATA LOGGER' ></a>");
client.println("<a href=" " download>");
client.println("</center>");
client.println("</html>");
delay(1);
Serial.println("Client disonnected");
Serial.println("");
delay(300);
}
c. VIDEO HASILNYA
Monitor DAYA (Arus Tegangan) AC dan DC Thingspeak + Monitor Android
a. Nodemcu ESP8266
b. Sensor INA219
c. Sensor PZEM-004T
d. Sensor DC Voltage
e. Aplikasi Android
Note: pada bagian LINK tuliskan seperti berikut ini dan sesuai dengan ID thingspeak dan ID Write apikey pada website / akun thingspeak Anda. yang berwarna merah adalah ID akun thingspeak dan warna biru adalah ID Write apikey.
https://api.thingspeak.com/channels/1223445/feeds/last.json?api_key=5TGHLW6HZUPQH2TF
f. Program Arduino IDE
#include <Wire.h>
#include <ThingSpeak.h>
#include <ESP8266WiFi.h>
#include <Adafruit_INA219.h>
#include <SoftwareSerial.h>
#include <PZEM004Tv30.h>
PZEM004Tv30 pzem(D7,D8); // D6, D5, (RX,TX) connect to TX,RX of PZEM
float busVoltage = 0;
float arusac = 0; // Measure in milli amps
float dayaac = 0;
float vac;
float arusdc;
float dayadc;
float vdc;
int adcteg;
float tegangan;
float voltage;
float current;
float power;
Adafruit_INA219 sensor219; // Declare and instance of INA219
WiFiClient client;
// ThingSpeak Settings
String apiKey = "5TGHLW6HZUPQH2TF";
const char *ssid = "hotspothpku";
const char *pass = "123456789";
const char* server = "api.thingspeak.com";
const char* resource = "/update?api_key=";
void setup() {
Serial.begin(9600);
sensor219.begin();
//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");
}
void loop() {
voltage = pzem.voltage();
current = pzem.current();
power = pzem.power();
sensor219.begin();
busVoltage = sensor219.getBusVoltage_V();
arusdc = sensor219.getCurrent_mA();
arusdc = arusdc /1000.0;
//dayadc = busVoltage * (arusdc/1000);
adcteg = analogRead(A0);
tegangan = (adcteg * (5.0 / 1023.0) * 4.8) - 2.58;
dayadc = tegangan * arusdc;
Serial.print("VoltageAC: "); Serial.print(voltage); Serial.println("V");
Serial.print("CurrentAC: "); Serial.print(current); Serial.println("A");
Serial.print("PowerAC: "); Serial.print(power); Serial.println("W");
Serial.print("busVoltage: "); Serial.print(busVoltage); Serial.println("V");
Serial.print("VoltageDC: "); Serial.print(tegangan); Serial.println("V");
Serial.print("CurrentDC: "); Serial.print(arusdc); Serial.println("mA");
Serial.print("PowerDC: "); Serial.print(dayadc); Serial.println("W");
if (client.connect(server,80)) // "184.106.153.149" or api.thingspeak.com
{
String postStr = apiKey;
postStr +="&field1=";
postStr += String(voltage);
postStr += "\r\n\r\n";
client.print(String("GET ") + resource + apiKey + "&field1=" + voltage + "&field2=" + current + "&field3=" + power + "&field4=" + tegangan + "&field5=" + arusdc + "&field6=" + dayadc + " 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...");
// thingspeak needs minimum 15 sec delay between updates, i've set it to 30 seconds
delay(10000);
}
g. VIDEO HASILNYA
Monitor Tegangan Arus AC Sensor PZEM-004T NODEMCU ESP8266
Monitor Tegangan Arus AC Sensor PZEM-004T NODEMCU ESP8266
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor tegangan dan arus AC menggunakan sensor PZEM-004T dengan Nodemcu ESP8266. alat ini bisa dikoneksikan ke internet (IOT) dengan menggunakan wifi. untuk lebih jelasnya berikut adalah koding dan komponennya.
a. Komponen
b. Cara Setting Nodemcu ESP8266
c. Program Arduino IDE
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
#include <PZEM004Tv30.h>
PZEM004Tv30 pzem(D7,D8); // D6, D5, (RX,TX) connect to TX,RX of PZEM
float voltage;
float current;
float power;
void setup() {
Serial.begin(9600);
}
void loop() {
voltage = pzem.voltage();
current = pzem.current();
power = pzem.power();
Serial.print("VoltageAC: "); Serial.print(voltage); Serial.println("V");
Serial.print("CurrentAC: "); Serial.print(current); Serial.println("A");
Serial.print("PowerAC: "); Serial.print(power); Serial.println("W");
delay(1000);
}
d. VIDEO HASILNYA
Monitor Suhu MLX90614 dan Jarak HC-SRF04 OLED Nodemcu ESP8266 Arduino
Monitor Suhu MLX90614 dan Jarak HC-SRF04 OLED Nodemcu ESP8266 Arduino
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa digunakan untuk monitoring suhu dan jarak dengan menggunakan sensor MLX90614 dan HC-SRF04 dengan interface menggunakan OLED display dan mikrokontroller menggunakan Nodemcu ESP8266. untuk lebih jelasnya berikut adalah komponen dan kodingnya.
a. Komponen
b. Program Arduino IDE
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <Adafruit_MLX90614.h>
#include "Wire.h"
#include "Adafruit_GFX.h"
#include "OakOLED.h"
#define trigPin D7 //pin trigger hcsrf04
#define echoPin D6 //pin echo
OakOLED oled;
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
long duration, distance;
float TargetC;
void setup()
{
Serial.begin(115200);
oled.begin();
oled.display();
mlx.begin();
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
mlx.begin();
TargetC = mlx.readObjectTempC();
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(1);
oled.setCursor(0, 0);
oled.print("Jarak: ");
oled.println(distance);
oled.setTextSize(1);
oled.setTextColor(1);
oled.setCursor(0, 16);
oled.print("Suhu: ");
oled.println(TargetC);
oled.display();
delay(200);
}
c. VIDEO HASILNYA
Pertamini Air Pembayaran Pakai Kode Token
Pertamini Air Pembayaran Pakai Kode Token
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang digunakan untuk mengisi air dengan menggunakan kode token, jadi alat ini seperti halnya pertamini yang mana bukan bensin yang dialirkan melainkan air sehingga client atau pembeli harus membeli kode token dulu seperti halnya listrik PLN yang menggunakan kode token. untuk lebih jelasnya berikut adalah koding dan skemanya.
a. Skema
b. Program Arduino IDE
#include <Wire.h>
#include <SPI.h>
#include <Keypad.h>
#include <LiquidCrystal_I2C.h> //i2C LCD Library
LiquidCrystal_I2C lcd(0x27, 16, 2); //library i2c lcd 16x2
int relay = 11;
char customKey;
const byte ROWS = 4;
const byte COLS = 4;
long passwd = 0;
long isiku;
long beli;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {3,4,5,6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7,8,9,10}; //connect to the column pinouts of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);
byte sensorInterrupt = 0; // 0 = digital pin 2
byte sensorPin = 2;
float calibrationFactor = 4.5;
volatile byte pulseCount;
unsigned int frac;
float flowRate;
unsigned int flowMilliLitres;
long totalMilliLitres;
long totalLitres;
unsigned long oldTime;
long dataku = 0;
unsigned long saldo;
int mark,mark1,mark2;
void setup()
{
pinMode(relay, OUTPUT);
digitalWrite(relay, HIGH);
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);
pulseCount = 0;
flowRate = 0.0;
flowMilliLitres = 0;
totalMilliLitres = 0;
oldTime = 0;
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
lcd.begin(); //set lcd i2c
lcd.noCursor(); //biar gak ada cursor di lcd
lcd.clear(); //clear lcd
Serial.begin(9600); // Initiate a serial communication
}
void loop()
{
lcd.setCursor(0,1);
lcd.print("Token: ");
lcd.print(saldo);
lcd.print(" L ");
if((millis() - oldTime) > 1000) // Only process counters once per second
{
detachInterrupt(sensorInterrupt);
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
oldTime = millis();
flowMilliLitres = (flowRate / 60) * 1000;
totalMilliLitres += flowMilliLitres;
totalLitres = totalMilliLitres / 1000;
frac = (flowRate - int(flowRate)) * 10;
// Print the cumulative total of litres flowed since starting
lcd.setCursor(0,0);
lcd.print("Pakai: "); // Output separator
lcd.print(totalLitres);
lcd.print(" L ");
pulseCount = 0;
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
if(totalLitres >= saldo){
digitalWrite(relay, HIGH); //off
saldo = 0;
}
if(totalLitres < saldo){
digitalWrite(relay, LOW); //on
}
}
customKey = customKeypad.getKey();
if(customKey == '*'){
lcd.clear();
delay(1000);
beli = 0;
pulseCount = 0;
flowRate = 0.0;
flowMilliLitres = 0;
totalMilliLitres = 0;
totalLitres = 0;
oldTime = 0;
token();
}
delay(200);
}
void token(){
lcd.setCursor(0,0);
lcd.print("Kode Token");
customKey = customKeypad.getKey();
if(customKey >= '0' && customKey <= '9')
{
beli = beli * 10 + (customKey - '0');
lcd.setCursor(0,1);
lcd.print(beli);
}
if(customKey == 'C'){
lcd.clear();
beli = 0;
}
if(customKey == '#'){
lcd.clear();
delay(1000);
if((beli == 12345)&&(mark == 0)){
saldo = 10;
mark = 1;
return;
}
if((beli == 12234)&&(mark1 == 0)){
saldo = 7;
mark1 = 1;
return;
}
if((beli == 54321)&&(mark2 == 0)){
saldo = 5;
mark2 = 1;
return;
}
beli = 0;
return;
}
token();
}
void pulseCounter()
{
pulseCount++;
}
c. VIDEO HASILNYA