0% found this document useful (0 votes)
5 views

Coding

The document contains Arduino coding examples for different types of LED and switch circuits: 1. The first example shows code to activate an LED light using a digital write function. 2. A second example uses a digital switch input to control an LED output. 3. Further examples demonstrate coding for manually and automatically running multiple LED lights in sequences using delay functions and for loops. 4. The final section provides code for controlling an LED using a Blynk IoT app and ESP8266 WiFi module.

Uploaded by

68-Jovan Arya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Coding

The document contains Arduino coding examples for different types of LED and switch circuits: 1. The first example shows code to activate an LED light using a digital write function. 2. A second example uses a digital switch input to control an LED output. 3. Further examples demonstrate coding for manually and automatically running multiple LED lights in sequences using delay functions and for loops. 4. The final section provides code for controlling an LED using a Blynk IoT app and ESP8266 WiFi module.

Uploaded by

68-Jovan Arya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Coding:

1. Aktifkan Lampu

void setup() {
pinMode(D0, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(D0, LOW);
}

2. Saklar Digital

void setup() {
// put your setup code here, to run once:
pinMode(D4, INPUT);
pinMode(D1, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:

if (digitalRead(D4) == HIGH)
digitalWrite(D1, HIGH);
else
digitalWrite(D1, LOW);
}

########################################################
//koding dua lampu menyala

void setup() {
// put your setup code here, to run once:
pinMode(D4, INPUT);
pinMode(D0, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:

if (digitalRead(D4) == HIGH)
{ digitalWrite(D0, HIGH);
digitalWrite(D1, LOW);
digitalWrite(D2, HIGH);
}
else
{ digitalWrite(D0, LOW);
digitalWrite(D1, HIGH);
digitalWrite(D2, LOW);
}
}

3. Running Led

##################################################
//tema satu secara manual

void setup()
{
pinMode(D0,OUTPUT);
pinMode(D1,OUTPUT);
pinMode(D2,OUTPUT);
}

void loop()
{
digitalWrite(D0, HIGH);
digitalWrite(D1, LOW);
digitalWrite(D2, LOW);
delay(500);

digitalWrite(D0, LOW);
digitalWrite(D1, HIGH);
digitalWrite(D2, LOW);
delay(500);

digitalWrite(D0, LOW);
digitalWrite(D1, LOW);
digitalWrite(D2, HIGH);
delay(500);

}
##################################################
//tema dua secara kondisi

void setup()
{
pinMode(0,OUTPUT);
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
}

void loop()
{
int i;
int d;

d=500;

for(i=0; i<=2; i++)


{
digitalWrite(i,HIGH);
delay(d);
digitalWrite(i,LOW);
delay(d);
}
}

##################################################
//tema dua secara kondisi

void setup()
{
pinMode(0,OUTPUT);
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
}

void loop()
{
int i;
int d;

d=500;

for(i=2; i>=0; i--)


{
digitalWrite(i,HIGH);
delay(d);
digitalWrite(i,LOW);
delay(d);
}
}

##################################################
//tema dua secara kondisi

void setup()
{
pinMode(0,OUTPUT);
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
}

void loop()
{
int i;
int d;

d=500;

for(i=0; i<=2; i++)


{
digitalWrite(i,HIGH);
delay(d);
digitalWrite(i,LOW);
delay(d);
}

for(i=2; i>=0; i--)


{
digitalWrite(i,HIGH);
delay(d);
digitalWrite(i,LOW);
delay(d);
}
}

4. Saklar IoT Blynk


#define BLYNK_TEMPLATE_ID "TMPLFNU-zq3y"
#define BLYNK_TEMPLATE_NAME "Lampu Internet"
#define BLYNK_AUTH_TOKEN "4PTJqu_fy8H_2SeyP5VRh06_3f_Jff7x"
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SoftwareSerial.h>
char auth[] = BLYNK_AUTH_TOKEN;
// Ganti dengan WiFi dan Password anda
char ssid[] = "Laboratorium Elektro";
char pass[] = "elektrounipa";

SoftwareSerial EspSerial(3, 2); // RX, TX


ESP8266 wifi(&EspSerial);
//========
BLYNK_WRITE(V0)
{
int value1 = param.asInt();
digitalWrite(D0,value1);
}

void setup(){
pinMode(D0,OUTPUT);

Serial.begin(9600);
EspSerial.begin(9600);
delay(10);
Blynk.begin(auth, ssid, pass);
delay(200);
}
void loop(){
Blynk.run();
}

You might also like