Tugas Mencatat Program Arduino

Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

TUGAS MENCATAT PROGRAM ARDUINO

KELAS XII TEI 2

PROGRGRAM KE-1

#define BLYNK_PRINT Serial

/* Fill in information from Blynk Device Info here */

#define BLYNK_TEMPLATE_ID "TMPL6XbwvirD9"


#define BLYNK_TEMPLATE_NAME "Pengendali Lampu"
#define BLYNK_AUTH_TOKEN "-
E0IvL91aotupLZAefcTP7JmrL5QrFnH"

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266_SSL.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 16, 2);

// Your WiFi credentials.


// Set password to "" for open networks.
char ssid[] = "ELIT";
char pass[] = "p4tk.BMTI";

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;
}

Serial.print("V0 button value is: "); // printing


value to serial monitor
Serial.println(pinValue);

}
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"

/* Comment this out to disable prints and save space


*/
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <LiquidCrystal_I2C.h>

// Your WiFi credentials.

// Set password to "" for open networks.


char ssid[] = "ELIT";
char pass[] = "p4tk.BMTI";
LiquidCrystal_I2C lcd (0x3f, 16, 2);

// This function will be called every time Slider


Widget
// in Blynk app writes values to the Virtual Pin V1
void setup()
{
// Debug console
Serial.begin(9600);
lcd.init();
lcd.backlight();
Serial.print("SMKN 1 CIKPUS ");
Serial.print("CONTROL 5 CHANNEL");
//delay(2000);
lcd.setCursor(0,0);
lcd.print("SMKN 1 CIKPUS");
lcd.setCursor(0,1);
lcd.print("CONTROL 5 CHANEL");
pinMode(0, OUTPUT); //LED RED D3
pinMode(2, OUTPUT); //LED GREEN D4
pinMode(12, OUTPUT); //LED BLUE D6
//pinMode(13, OUTPUT);
pinMode(3, OUTPUT); //RELAY 1 + BUZZER RX
pinMode(1, OUTPUT); //RELAY 2 TX
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
// You can also specify server:
//Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass,
"blynk.cloud", 80);
//Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass,
IPAddress(192,168,1,100), 8080);
}

//Serial.begin(9600);

BLYNK_WRITE(V0) // this command is listening when


something is written to V1
{
//Serial.begin(9600);
int pinValue1 = param.asInt(); // assigning incoming
value from pin V1 to a variable

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;

String ssid = "ELIT"; // REPLACE mySSID WITH YOUR


WIFI SSID
String pass = "p4tk.BMTI"; // REPLACE myPassword YOUR
WIFI PASSWORD, IF ANY
String token =
"6411664982:AAGUP0gLCJ2gI9U7WnJ1J1RYFIspY-n0XZw"; //
REPLACE myToken WITH YOUR TELEGRAM BOT TOKEN
int led = 14;
void setup() {
Serial.begin(9600);
Serial.println("Starting TelegramBot...");

myBot.wifiConnect(ssid, pass); // connect the


ESP8266 to the desired access point
myBot.setTelegramToken(token); // set the
telegram bot token

// check if all things are ok


if (myBot.testConnection())
Serial.println("\nConnection OK");
else
Serial.println("\nConnection NOT OK");

// set the pin connected to the LED to act as output


pin
pinMode(led, OUTPUT);

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);

// Check if any reads failed and exit early (to try


again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT
sensor!"));
return;
}

Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.println(F("°C "));

lcd.setCursor(2, 1); // Or setting the cursor in the


desired position.
lcd.print(t,1);
lcd.setCursor(11, 1); // Or setting the cursor in
the desired position.
lcd.print(h,1);

TBMessage msg;

// if there is an incoming message...


if (CTBotMessageText == myBot.getNewMessage(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

#define BLYNK_TEMPLATE_ID "TMPL65Gxy-rMp"


#define BLYNK_TEMPLATE_NAME "WATER LEVEL monitoring"
#define BLYNK_AUTH_TOKEN
"uPJqHbh6R6DA3DndIycblP1YjqfBMPWE"

#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

LiquidCrystal_I2C lcd(0x3f, 16, 2);

char auth[] = BLYNK_AUTH_TOKEN; // Enter your Blynk


authentication token
char ssid[] = "Agust"; // Enter your WiFi SSID
char pass[] = "janeerye82"; // Enter your WiFi
password

BlynkTimer timer;
//#define trig 13
//#define echo 12
const int trig = D5;
const int echo = D6;
int MaxLevel = 18;

int Level1 = (MaxLevel * 75) / 100;


int Level2 = (MaxLevel * 65) / 100;
int Level3 = (MaxLevel * 55) / 100;
int Level4 = (MaxLevel * 45) / 100;
int Level5 = (MaxLevel * 35) / 100;

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();

// Call the functions


timer.setInterval(100L, ultrasonic);
}

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;

int blynkDistance = (distance - MaxLevel) * -1;


if (distance <= MaxLevel) {
Blynk.virtualWrite(V0, blynkDistance);
Serial.print("Distance: ");
Serial.print(blynkDistance);
Serial.println(" cm");
} else {
Blynk.virtualWrite(V0, 0);
}

lcd.setCursor(0, 0);
lcd.print("Level :");

if (Level1 <= distance) {


lcd.setCursor(8, 0); // Corrected column position
lcd.print("Very Low");
} else if (Level2 <= distance && Level1 > distance)
{
lcd.setCursor(8, 0); // Corrected column position
lcd.print("Low");
lcd.print(" ");
} else if (Level3 <= distance && Level2 > distance)
{
lcd.setCursor(8, 0); // Corrected column position
lcd.print("Medium");
lcd.print(" ");
} else if (Level4 <= distance && Level3 > distance)
{
lcd.setCursor(8, 0); // Corrected column position
lcd.print("High");
lcd.print(" ");
} else if (Level5 >= distance) {
lcd.setCursor(8, 0); // Corrected column position
lcd.print("Full");
lcd.print(" ");
}
}

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"

// Comment this out to disable prints and save space


*/
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// Your WiFi credentials.


// Set password to "" for open networks.
char ssid[] = "realme C17";
char pass[] = "hnr111111";

void setup(){
// Debug console
Serial.begin(115200);
pinMode(A0, INPUT);
//pinMode(5, OUTPUT);
//pinMode(4, OUTPUT);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);

// put your setup code here, to run once:


Serial.begin(9600);
lcd.init(); // initialisasi the
lcd
lcd.backlight(); // initialisasi
backlight LCD
pinMode(1,OUTPUT); // pin 1 sebagai
output BUZZER R
pinMode(3,OUTPUT); // pin 2 sebagai
output LED R
pinMode(12,OUTPUT); // pin 2 sebagai
output LED G
pinMode(13,OUTPUT); // pin 2 sebagai
output LED B
lcd.setCursor(0,0); // sett cursor word
kolom 0 baris 0
lcd.print("Hello, P4TK BMTI"); // tampil
lcd.setCursor(2,1); // sett cursor word
kolom 2 baris 1
lcd.print("LCD ESP8266");
delay(2000);
lcd.clear();

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>351 && sensorValue<750){


lcd.setCursor(12,1);
lcd.print("MIDD");
digitalWrite(1, LOW);
digitalWrite(3, LOW);
digitalWrite(12, HIGH);
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;

const char* ssid = "iman.";// nama ssid


const char* password = "imankasep"; // ssid Password

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()
{

long durasi, jarak;


digitalWrite(TRIGPIN, LOW);
delayMicroseconds(8);
digitalWrite(TRIGPIN, HIGH);
delayMicroseconds(8);
digitalWrite(TRIGPIN, LOW);
delayMicroseconds(8);
durasi = pulseIn(ECHOPIN,HIGH);
jarak = (durasi/2)/29.1;

if(jarak >= 10){


digitalWrite(BUZZ, LOW);
digitalWrite(LED1, LOW);
digitalWrite(LED2, HIGH);

}
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..!!", "");
}

You might also like