Tugas Mencatat Program Arduino
Tugas Mencatat Program Arduino
Tugas Mencatat Program Arduino
PROGRGRAM KE-1
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266_SSL.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 16, 2);
void setup()
{
// Debug console
Serial.begin(9600);
lcd.begin();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("HELLO");
pinMode(0,OUTPUT);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}
BLYNK_WRITE(V0) // this command is listening when
something is written to V1
{
int pinValue = param.asInt(); // assigning incoming
value from pin V1 to a variable
if (pinValue == 1){
digitalWrite(0, HIGH);
lcd.clear();
lcd.setCursor(4,0);
lcd.print("LED GREEN");
Serial.print("LED GREEN");
// do something when button is pressed;
} else if (pinValue == 0) {
digitalWrite(0, LOW);
lcd.clear();
lcd.setCursor(2,1);
lcd.print("SMKN 1 CIKPUS");
// do something when button is released;
}
}
void loop()
{
Blynk.run();
}
PROGRGRAM KE-2
#define BLYNK_TEMPLATE_ID "TMPL6UzR-lEYE"
#define BLYNK_TEMPLATE_NAME "kontrol 6 chanel via
BLYNK"
#define BLYNK_AUTH_TOKEN
"GbSbZlQx0kqwvJN0gRMFbiTsHJ3F96fY"
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <LiquidCrystal_I2C.h>
//Serial.begin(9600);
if (pinValue1 == 1){
digitalWrite(0, HIGH);
Serial.println("LED RED");
lcd.clear();
lcd.setCursor(4,0);
lcd.print("LED RED");
// do something when button is pressed;
} else if (pinValue1 == 0) {
digitalWrite(0, LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("SMKN 1 CIKPUS");
lcd.setCursor(0,1);
lcd.print("CONTROL 5 CHANEL");
// do something when button is released;
}
}
BLYNK_WRITE(V2) // this command is listening when
something is written to V1
{
int pinValue2 = param.asInt(); // assigning incoming
value from pin V1 to a variable
if (pinValue2 == 1){
digitalWrite(2, HIGH);
Serial.println("LED GREEN");
lcd.clear();
lcd.setCursor(4,0);
lcd.print("LED GREEN");
// do something when button is pressed;
} else if (pinValue2 == 0) {
digitalWrite(2, LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("SMKN 1 CIKPUS");
lcd.setCursor(0,1);
lcd.print("CONTROL 5 CHANEL");
// do something when button is released;
}
}
BLYNK_WRITE(V12) // this command is listening when
something is written to V1
{
int pinValue3 = param.asInt(); // assigning incoming
value from pin V1 to a variable
if (pinValue3 == 1){
digitalWrite(12, HIGH);
Serial.println("LED BLUE");
lcd.clear();
lcd.setCursor(4,0);
lcd.print("LED BLUE");
// do something when button is pressed;
} else if (pinValue3 == 0) {
digitalWrite(12, LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("SMKN 1 CIKPUS");
lcd.setCursor(0,1);
lcd.print("CONTROL 5 CHANEL");
// do something when button is released;
}
}
BLYNK_WRITE(V3) // this command is listening when
something is written to V1
{
int pinValue4 = param.asInt(); // assigning incoming
value from pin V1 to a variable
if (pinValue4 == 1){
digitalWrite(3, HIGH);
Serial.println("BUZZER+RELAY 1");
lcd.clear();
lcd.setCursor(4,0);
lcd.print("BUZZER");
lcd.setCursor(4,1);
lcd.print("RELAY 1");
// do something when button is pressed;
} else if (pinValue4 == 0) {
digitalWrite(3, LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("SMKN 1 CIKPUS");
lcd.setCursor(0,1);
lcd.print("CONTROL 5 CHANEL");
// do something when button is released;
}
}
BLYNK_WRITE(V1) // this command is listening when
something is written to V1
{
int pinValue5 = param.asInt(); // assigning incoming
value from pin V1 to a variable
if (pinValue5 == 1){
digitalWrite(1, HIGH);
Serial.println("RELAY 1");
lcd.clear();
lcd.setCursor(4,0);
lcd.print("RELAY 2");
// do something when button is pressed;
} else if (pinValue5 == 0) {
digitalWrite(1, LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("SMKN 1 CIKPUS");
lcd.setCursor(0,1);
lcd.print("CONTROL 5 CHANEL");
// do something when button is released;
}
}
void loop()
{
Blynk.run();
PROGRGRAM KE-3
#include "DHT.h"
#define DHTPIN 2 // Digital pin connected to the
DHT sensor
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
#include <LCD_I2C.h>
LCD_I2C lcd(0x3F, 16, 2);
#include "CTBot.h"
CTBot myBot;
Serial.println(F("DHTxx test!"));
dht.begin();
lcd.begin();
lcd.backlight();
lcd.setCursor(1, 0); // Or setting the cursor in the
desired position.
lcd.print("Monitor T & RH");
lcd.setCursor(0, 1); // Or setting the cursor in the
desired position.
lcd.print("T:");
lcd.setCursor(6, 1); // Or setting the cursor in the
desired position.
lcd.print("'C");
lcd.setCursor(9, 1); // Or setting the cursor in the
desired position.
lcd.print("H:");
lcd.setCursor(15, 1); // Or setting the cursor in
the desired position.
lcd.print('%');
}
void loop() {
delay(1000);
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit =
true)
float f = dht.readTemperature(true);
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.println(F("°C "));
TBMessage msg;
if (msg.text.equalsIgnoreCase("On"))
{ // if the received message is "LIGHT
ON"...
digitalWrite(led,
HIGH); // turn on the
LED (inverted logic!)
myBot.sendMessage(msg.sender.id, "Kondisi AC
ON"); // notify the sender
String t;
t = (String) "Suhu saat ini: "+
dht.readTemperature();
myBot.sendMessage(msg.sender.id,t);
}
else if (msg.text.equalsIgnoreCase("Off"))
{ // if the received message is "LIGHT OFF"...
digitalWrite(led,
LOW); // turn off the led
(inverted logic!)
myBot.sendMessage(msg.sender.id, "Kondisi AC
OFF"); // notify the sender
String t;
t = (String) "Suhu saat ini: "+
dht.readTemperature();
myBot.sendMessage(msg.sender.id,t);
}
else
{ /
/ otherwise...
// generate the message for the sender
String reply;
reply = (String)"Coba " + msg.sender.username +
(String)" ketikkan perintah On atau Off.";
myBot.sendMessage(msg.sender.id,
reply); // and send it
}
}
}
PROGRGRAM KE-4
#include <LiquidCrystal.h>
#include <Wire.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp8266.h>
#include <LiquidCrystal_I2C.h>
//#include <BlynkTimer.h> // Added BlynkTimer library
BlynkTimer timer;
//#define trig 13
//#define echo 12
const int trig = D5;
const int echo = D6;
int MaxLevel = 18;
void setup() {
Serial.begin(9600);
lcd.init(); // Initialize the LCD with correct
column and row count6
lcd.backlight();
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
Serial.print("LCD 1");
lcd.setCursor(3, 0); //Set cursor to first column
of first row
lcd.print("SMKN 3 BATAM");
Serial.print("LCD 2");
delay(1000);
lcd.clear();
lcd.setCursor(3, 0);
lcd.print("Water level");
lcd.setCursor(3, 1);
lcd.print("Monitoring");
delay(5000);
lcd.clear();
void loop() {
Blynk.run();
timer.run(); // Run the BlynkTimer
delay(1000);
}
void ultrasonic() {
digitalWrite(trig, LOW);
delayMicroseconds(4);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
long t = pulseIn(echo, HIGH);
int distance = t / 29 / 2;
lcd.setCursor(0, 0);
lcd.print("Level :");
PROGRGRAM KE-5
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3f,16,2);
//inisialisasi bylnk
#define BLYNK_TEMPLATE_ID "TMPL67u0ubWAl"
#define BLYNK_TEMPLATE_NAME "A0"
#define BLYNK_AUTH_TOKEN
"jN86dQjFczv4IJuxP3Gi6_FnqK1xRVQO"
void setup(){
// Debug console
Serial.begin(115200);
pinMode(A0, INPUT);
//pinMode(5, OUTPUT);
//pinMode(4, OUTPUT);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
lcd.setCursor(0,0);
lcd.print("READ SENS");
delay(2000);
}
void loop() {
// put your main code here, to run repeatedly:
int sensorValue = analogRead(A0); // Read from pin
A0
Serial.print("Data sensor pot : ");
Serial.println(sensorValue);
delay(500);
lcd.setCursor(0,1);
lcd.print(sensorValue);
lcd.print(" ");
lcd.print("DEC ");
if(sensorValue<=350){
lcd.setCursor(12,1);
lcd.print("LOW ");
digitalWrite(1, LOW);
digitalWrite(3, HIGH);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
}
if(sensorValue>=751){
lcd.setCursor(12,1);
lcd.print("HIGHT");
digitalWrite(1, HIGH);
digitalWrite(3, LOW);
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
}
{
Blynk.run();
}
}
PROGRGRAM KE-6
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#define BOTtoken
"6351851377:AAF_9_KLI9S3VMG32QhF52mfuvTXVy-ANtg" //
token botfather
#define CHAT_ID "6945267419" // idBOTT telegram
X509List cert(TELEGRAM_CERTIFICATE_ROOT);
WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);
#define TRIGPIN 14 //D4
#define ECHOPIN 12 //D3
#define jendela 16//D0
int BUZZ = 15;
int LED1 = 03;
int LED2 = 01;
void setup()
{
Serial.begin(115200);
configTime(0, 0, "pool.ntp.org");
client.setTrustAnchors(&cert);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
int a = 0;
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
a++;
}
pinMode(ECHOPIN, INPUT);
pinMode(TRIGPIN, OUTPUT);
pinMode(BUZZ, OUTPUT);
pinMode(LED1 , OUTPUT);
pinMode(LED2 , OUTPUT);
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
bot.sendMessage(CHAT_ID, "Wifi Connected!", "");
bot.sendMessage(CHAT_ID, "System has Started!!",
"");
}
void loop()
{
}
if((jarak > 0 )&&(jarak <10)){
digitalWrite(BUZZ, HIGH);
digitalWrite(LED1, HIGH);
digitalWrite(LED2, LOW);
bot.sendMessage(CHAT_ID, "PERHATIAN ADA YANG
MASUK..!!", "");
}
{
while (digitalRead(jendela)==LOW)
{ digitalWrite(BUZZ, HIGH);
digitalWrite(LED2, LOW);
bot.sendMessage(CHAT_ID, "WASPADA JENDELA
TERBUKA ADA MALING MASUK..!!", "");
delay(90000);}
}
if (digitalRead(jendela)==HIGH)
{ digitalWrite(BUZZ, LOW);
digitalWrite(LED1, LOW);
//bot.sendMessage(CHAT_ID, "WASPADA JENDELA
TERBUKA..!!", "");
}