Assalamu‘alaikum wr. wb.
Hello guys, Kembali lagi bersama Inzaghi's Blog! Jika sebelumnya sudah pernah membahas tentang Modul Dasar Arduino, sekarang waktunya melakukan Implementasi Program Aplikasi Arduino Sederhana menggunakan Tinkercad dan ESP32 melalui Arduino IDE.
TUTORIAL CARA MENGGUNAKAN TINKERCAD
Pertama, merilah kita buka Situs Tinkercad di sini (Tinkercad.com), dan klik "Log in".
Kemudian, Masuklah menggunakan Akun Google. Setelah itu, pilihlah "Personal Accounts" untuk memilih Akun Pribadi.
Setelah itu, isilah Data Pribadi seperti Negara dan Tanggal Lahir, dan klik "Next".
Selanjutnya, klik "Continue" untuk Syarat dan Ketentuan dari Autodesk.
Anda sudah masuk ke Tampilan Dashboard dari Tinkercad. Jika ingin membuat Rangkaian Arduino, silakan klik "Create your First Circuit Design" pada Circuits.
MEMBUAT RANGKAIAN DAN KODE ARDUINO DENGAN MENGGUNAKAN TINKERCAD
Sumber Tutorial Lainnya (ESP32) : ESP32io.com
Dan inilah beberapa Project Arduino Uno yang telah kami buat di Tinkercad :
1. Arduino Dasar
1. Hello World
Kode :
void setup() {// put your setup code here, to run once:Serial.begin(9600);Serial.println("Hello World!");}void loop() {// put your main code here, to run repeatedly:}
Gambar :
2. On/Off Command (Serial Monitor)
Kode :
void setup() {Serial.begin(9600);pinMode(LED_BUILTIN, OUTPUT); // set the digital pin as output:}void loop() {if(Serial.available()) // if there is data comming{String command = Serial.readStringUntil('\n'); // read string until meet newline characterif(command == "ON"){digitalWrite(LED_BUILTIN, HIGH); // turn on commandSerial.println("Turned ON"); // send action to Serial Monitor}else if(command == "OFF"){digitalWrite(LED_BUILTIN, LOW); // turn off commandSerial.println("Turned OFF"); // send action to Serial Monitor}}}
Gambar :
3. Analog Waves (Serial Plotter)
Kode :
void setup() {Serial.begin(9600);}void loop() {int y1 = analogRead(A0);Serial.println(y1);delay(100);}
Gambar :
2. Lampu LED
1. LED Dasar Tanpa Breadboard (Blinking LED Without Breadboard)
Gambar :
Kode :
// C++ code//void setup(){pinMode(9, OUTPUT);}void loop(){digitalWrite(9, HIGH);delay(1000); // Wait for 1000 millisecond(s)digitalWrite(9, LOW);delay(1000); // Wait for 1000 millisecond(s)}
2. LED Dasar dengan Breadboard (Blinking LED with Breadboard)
Gambar :
Kode :
int LED = 2;void setup(){pinMode(LED, OUTPUT);}void loop(){digitalWrite(LED, HIGH);delay(1000); // Wait for 1000 millisecond(s)digitalWrite(LED, LOW);delay(1000); // Wait for 1000 millisecond(s)}
Kode :
// constants won't change:const int LED_PIN = 4; // the number of the LED pinconst int BUTTON_PIN = 8; // the number of the button pinconst long BLINK_INTERVAL = 1000; // interval at which to blink LED (milliseconds)// Variables will change:int ledState = LOW; // ledState used to set the LEDint previousButtonState = LOW; // will store last time button was updatedunsigned long previousMillis = 0; // will store last time LED was updatedvoid setup() {Serial.begin(9600);// set the digital pin as output:pinMode(LED_PIN, OUTPUT);// set the digital pin as an input:pinMode(BUTTON_PIN, INPUT);}void loop() {unsigned long currentMillis = millis();if (currentMillis - previousMillis >= BLINK_INTERVAL) {// if the LED is off turn it on and vice-versa:ledState = (ledState == LOW) ? HIGH : LOW;// set the LED with the ledState of the variable:digitalWrite(LED_PIN, ledState);// save the last time you blinked the LEDpreviousMillis = currentMillis;}// check button state's changeint currentButtonState = digitalRead(BUTTON_PIN);if(currentButtonState != previousButtonState) {// print out the state of the button:Serial.println(currentButtonState);// save the last state of buttonpreviousButtonState = currentButtonState;}}
Kode :
const int LED_PIN = 3; // the number of the LED pinconst int BUTTON_PIN = 6; // the number of the button pinconst long BLINK_INTERVAL = 1000; // interval at which to blink LED (milliseconds)// Variables will change:int ledState = LOW; // ledState used to set the LEDint previousButtonState = LOW; // will store last time button was updatedunsigned long previousMillis = 0; // will store last time LED was updatedvoid setup() {Serial.begin(9600);// set the digital pin as output:pinMode(LED_PIN, OUTPUT);// set the digital pin as an input:pinMode(BUTTON_PIN, INPUT);}void loop() {// check to see if it's time to blink the LED; that is, if the difference// between the current time and last time you blinked the LED is bigger than// the interval at which you want to blink the LED.unsigned long currentMillis = millis();if (currentMillis - previousMillis >= BLINK_INTERVAL) {// if the LED is off turn it on and vice-versa:ledState = (ledState == LOW) ? HIGH : LOW;// set the LED with the ledState of the variable:digitalWrite(LED_PIN, ledState);// save the last time you blinked the LEDpreviousMillis = currentMillis;}// check button state's changeint currentButtonState = digitalRead(BUTTON_PIN);if(currentButtonState != previousButtonState) {// print out the state of the button:Serial.println(currentButtonState);// save the last state of buttonpreviousButtonState = currentButtonState;}// DO OTHER WORKS HERE}
5. LED Lampu Ganda
Kode :
int redLED = 3;int yellowLED = 5;int greenLED = 8;void setup(){pinMode(redLED, OUTPUT);pinMode(yellowLED, OUTPUT);pinMode(greenLED, OUTPUT);}void loop(){digitalWrite(redLED, HIGH);digitalWrite(yellowLED, LOW);digitalWrite(greenLED, LOW);delay(1000); // Wait for 1000 millisecond(s)digitalWrite(redLED, LOW);digitalWrite(yellowLED, HIGH);digitalWrite(greenLED, LOW);delay(1000); // Wait for 1000 millisecond(s)digitalWrite(redLED, LOW);digitalWrite(yellowLED, LOW);digitalWrite(greenLED, HIGH);delay(1000); // Wait for 1000 millisecond(s)}
3. Lampu LED RGB
Gambar :
Kode :
const int PIN_RED = 5;const int PIN_GREEN = 6;const int PIN_BLUE = 7;void setup() {pinMode(PIN_RED, OUTPUT);pinMode(PIN_GREEN, OUTPUT);pinMode(PIN_BLUE, OUTPUT);}void loop() {// color code #00C9CC (R = 0, G = 201, B = 204)analogWrite(PIN_RED, 0);analogWrite(PIN_GREEN, 201);analogWrite(PIN_BLUE, 204);delay(1000); // keep the color 1 second// color code #F7788A (R = 247, G = 120, B = 138)analogWrite(PIN_RED, 247);analogWrite(PIN_GREEN, 120);analogWrite(PIN_BLUE, 138);delay(1000); // keep the color 1 second// color code #34A853 (R = 52, G = 168, B = 83)analogWrite(PIN_RED, 52);analogWrite(PIN_GREEN, 168);analogWrite(PIN_BLUE, 83);delay(1000); // keep the color 1 second}
4. Potentiometer
1. Potentiometer dengan LED
Kode :
const int POTENTIOMETER_PIN = A0; // Arduino pin connected to Potentiometer pinconst int LED_PIN = 2; // Arduino pin connected to LED's pinconst float VOLTAGE_THRESHOLD = 2.5; // Voltagesvoid setup() {pinMode(LED_PIN, OUTPUT); // set arduino pin to output mode}void loop() {int analogValue = analogRead(POTENTIOMETER_PIN); // read the input on analog pinfloat voltage = floatMap(analogValue, 0, 1023, 0, 5); // Rescale to potentiometer's voltageif(voltage > VOLTAGE_THRESHOLD)digitalWrite(LED_PIN, HIGH); // turn on LEDelsedigitalWrite(LED_PIN, LOW); // turn off LED}float floatMap(float x, float in_min, float in_max, float out_min, float out_max) {return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;}
2. Potentiometer dengan Servo Motor
Kode :
#include <Servo.h>// constants won't changeconst int POTENTIOMETER_PIN = A0; // Arduino pin connected to Potentiometer pinconst int SERVO_PIN = 8; // Arduino pin connected to Servo Motor's pinconst int ANALOG_THRESHOLD = 500;Servo servo; // create servo object to control a servovoid setup() {servo.attach(SERVO_PIN); // attaches the servo on pin 9 to the servo objectservo.write(0);}void loop() {int analogValue = analogRead(POTENTIOMETER_PIN); // read the input on analog pinif(analogValue > ANALOG_THRESHOLD)servo.write(90); // rotate servo motor to 90 degreeelseservo.write(0); // rotate servo motor to 0 degree}
5. Sensor Ultrasonik
1. Sensor Ultrasonik dengan LED
Kode :
const int TRIG_PIN = 6; // Arduino pin connected to Ultrasonic Sensor's TRIG pinconst int ECHO_PIN = 5; // Arduino pin connected to Ultrasonic Sensor's ECHO pinconst int LED_PIN = 4; // Arduino pin connected to LED's pinconst int DISTANCE_THRESHOLD = 100; // centimeters// variables will change:float duration_us, distance_cm;void setup() {Serial.begin (9600); // initialize serial portpinMode(TRIG_PIN, OUTPUT); // set arduino pin to output modepinMode(ECHO_PIN, INPUT); // set arduino pin to input modepinMode(LED_PIN, OUTPUT); // set arduino pin to output mode}void loop() {// generate 10-microsecond pulse to TRIG pindigitalWrite(TRIG_PIN, HIGH);delayMicroseconds(10);digitalWrite(TRIG_PIN, LOW);// measure duration of pulse from ECHO pinduration_us = pulseIn(ECHO_PIN, HIGH);// calculate the distancedistance_cm = 0.017 * duration_us;if(distance_cm < DISTANCE_THRESHOLD)digitalWrite(LED_PIN, HIGH); // turn on LEDelsedigitalWrite(LED_PIN, LOW); // turn off LED// print the value to Serial MonitorSerial.print("distance: ");Serial.print(distance_cm);Serial.println(" cm");delay(500);}
2. Sensor Ultrasonik dengan Servo Motor
Kode :
#include <Servo.h>// constants won't changeconst int TRIG_PIN = 2; // Arduino pin connected to Ultrasonic Sensor's TRIG pinconst int ECHO_PIN = 3; // Arduino pin connected to Ultrasonic Sensor's ECHO pinconst int SERVO_PIN = 1; // Arduino pin connected to Servo Motor's pinconst int DISTANCE_THRESHOLD = 100; // centimetersServo servo; // create servo object to control a servo// variables will change:float duration_us, distance_cm;void setup() {Serial.begin (9600); // initialize serial portpinMode(TRIG_PIN, OUTPUT); // set arduino pin to output modepinMode(ECHO_PIN, INPUT); // set arduino pin to input modeservo.attach(SERVO_PIN); // attaches the servo on pin 9 to the servo objectservo.write(0);}void loop() {// generate 10-microsecond pulse to TRIG pindigitalWrite(TRIG_PIN, HIGH);delayMicroseconds(10);digitalWrite(TRIG_PIN, LOW);// measure duration of pulse from ECHO pinduration_us = pulseIn(ECHO_PIN, HIGH);// calculate the distancedistance_cm = 0.017 * duration_us;if(distance_cm < DISTANCE_THRESHOLD)servo.write(90); // rotate servo motor to 90 degreeelseservo.write(0); // rotate servo motor to 0 degree// print the value to Serial MonitorSerial.print("distance: ");Serial.print(distance_cm);Serial.println(" cm");delay(500);}
6. Photoresistor (Sensor Cahaya)
1. Sensor Cahaya Polos
Kode :
void setup() {// initialize serial communication at 9600 bits per second:Serial.begin(9600);}void loop() {// reads the input on analog pin A0 (value between 0 and 1023)int analogValue = analogRead(A0);Serial.print("Analog reading: ");Serial.print(analogValue); // the raw analog reading// We'll have a few threshholds, qualitatively determinedif (analogValue < 10) {Serial.println(" - Dark");} else if (analogValue < 200) {Serial.println(" - Dim");} else if (analogValue < 500) {Serial.println(" - Light");} else if (analogValue < 800) {Serial.println(" - Bright");} else {Serial.println(" - Very bright");}delay(500);}
2. Sensor Cahaya dengan LED
Keterangan :
- 220 Ω Resistor (Lampu LED)
- 10 kΩ Resistor (Sensor Cahaya Photoresistor)
Kode :
const int LIGHT_SENSOR_PIN = A5; // Arduino pin connected to light sensor's pinconst int LED_PIN = 1; // Arduino pin connected to LED's pinconst int ANALOG_THRESHOLD = 500;int analogValue;void setup() {pinMode(LED_PIN, OUTPUT); // set arduino pin to output mode}void loop() {analogValue = analogRead(LIGHT_SENSOR_PIN); // read the input on analog pinif(analogValue > ANALOG_THRESHOLD)digitalWrite(LED_PIN, HIGH); // turn on LEDelsedigitalWrite(LED_PIN, LOW); // turn off LED}
7. PIR Sensor (Sensor Gerak / Motion Sensor)
1. PIR Sensor dengan LED
Kode :
const int PIR_SENSOR_PIN = 10; // Arduino pin connected to the OUTPUT pin of motion sensorconst int LED_PIN = 4; // Arduino pin connected to LED's pinint motionStateCurrent = LOW; // current state of motion sensor's pinint motionStatePrevious = LOW; // previous state of motion sensor's pinvoid setup() {Serial.begin(9600); // initialize serialpinMode(PIR_SENSOR_PIN, INPUT); // set arduino pin to input modepinMode(LED_PIN, OUTPUT); // set arduino pin to output mode}void loop() {motionStatePrevious = motionStateCurrent; // store old statemotionStateCurrent = digitalRead(PIR_SENSOR_PIN); // read new stateif (motionStatePrevious == LOW && motionStateCurrent == HIGH) { // pin state change: LOW -> HIGHSerial.println("Motion detected!");digitalWrite(LED_PIN, HIGH); // turn on}else if (motionStatePrevious == HIGH && motionStateCurrent == LOW) { // pin state change: HIGH -> LOWSerial.println("Motion stopped!");digitalWrite(LED_PIN, LOW); // turn off}}
2. PIR Sensor dengan Servo Motor
Kode :
#include <Servo.h>// constants won't changeconst int PIR_SENSOR_PIN = 7; // Arduino pin connected to motion sensor's pinconst int SERVO_PIN = 6; // Arduino pin connected to servo motor's pinServo servo; // create servo object to control a servo// variables will change:int angle = 0; // the current angle of servo motorint lastMotionState; // the previous state of motion sensorint currentMotionState; // the current state of motion sensorvoid setup() {Serial.begin(9600); // initialize serialpinMode(PIR_SENSOR_PIN, INPUT); // set arduino pin to input modeservo.attach(SERVO_PIN); // attaches the servo on pin 9 to the servo objectservo.write(angle);currentMotionState = digitalRead(PIR_SENSOR_PIN);}void loop() {lastMotionState = currentMotionState; // save the last statecurrentMotionState = digitalRead(PIR_SENSOR_PIN); // read new stateif (currentMotionState == LOW && lastMotionState == HIGH) { // pin state change: LOW -> HIGHSerial.println("Motion detected!");servo.write(90);}else if (currentMotionState == HIGH && lastMotionState == LOW) { // pin state change: HIGH -> LOWSerial.println("Motion stopped!");servo.write(0);}}
8. Sensor-sensor
1. Sensor Suhu LM35
Kode :
#define ADC_VREF_mV 5000.0 // in millivolt#define ADC_RESOLUTION 1024.0#define PIN_LM35 A1void setup() {Serial.begin(9600);}void loop() {// get the ADC value from the temperature sensorint adcVal = analogRead(PIN_LM35);// convert the ADC value to voltage in millivoltfloat milliVolt = adcVal * (ADC_VREF_mV / ADC_RESOLUTION);// convert the voltage to the temperature in Celsiusfloat tempC = milliVolt / 10;// convert the Celsius to Fahrenheitfloat tempF = tempC * 9 / 5 + 32;// print the temperature in the Serial Monitor:Serial.print("Temperature: ");Serial.print(tempC); // print the temperature in CelsiusSerial.print("°C");Serial.print(" ~ "); // separator between Celsius and FahrenheitSerial.print(tempF); // print the temperature in FahrenheitSerial.println("°F");delay(1000);}
2. Sensor Gaya (Force Sensor)
Kode :
#define FORCE_SENSOR_PIN A4 // the FSR and 10K pulldown are connected to A0void setup() {Serial.begin(9600);}void loop() {int analogReading = analogRead(FORCE_SENSOR_PIN);Serial.print("Force sensor reading = ");Serial.print(analogReading); // print the raw analog readingif (analogReading < 10) // from 0 to 9Serial.println(" -> no pressure");else if (analogReading < 200) // from 10 to 199Serial.println(" -> light touch");else if (analogReading < 500) // from 200 to 499Serial.println(" -> light squeeze");else if (analogReading < 800) // from 500 to 799Serial.println(" -> medium squeeze");else // from 800 to 1023Serial.println(" -> big squeeze");delay(1000);}
3. Sensor Kelembaban Tanah (Soil Moisture Sensor)
Kode :
#define AOUT_PIN A0 // Arduino pin that connects to AOUT pin of moisture sensor#define THRESHOLD 100 // CHANGE YOUR THRESHOLD HEREvoid setup() {Serial.begin(9600);}void loop() {int value = analogRead(AOUT_PIN); // read the analog value from sensorSerial.print("Moisture: ");Serial.println(value);delay(500);if (value < THRESHOLD) {Serial.print("The soil is DRY (");}else {Serial.print("The soil is WET (");}Serial.print(value);Serial.println(")");delay(500);}
9. LCD Display
1. LCD Display
Kode :
#include <LiquidCrystal.h>// LCD pins <--> Arduino pinsconst int RS = 11, EN = 12, D4 = 2, D5 = 3, D6 = 4, D7 = 5;LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);void setup(){lcd.begin(16, 2); // set up number of columns and rows}void loop(){lcd.setCursor(0, 0); // move cursor to (0, 0)lcd.print("Inzaghi's Blog"); // print message at (0, 0)lcd.setCursor(2, 1); // move cursor to (2, 1)lcd.print("Inzaghi.com"); // print message at (2, 1)}
2. LCD Sensor Temperatur LM35 dengan Potentiometer
Kode :
#include <LiquidCrystal.h>// LCD pins <--> Arduino pinsconst int RS = 11, EN = 12, D4 = 2, D5 = 3, D6 = 4, D7 = 5;LiquidCrystal lcd(RS, EN, D4, D5, D6, D7);int sensorpin = A0;void setup(){lcd.begin(16, 2); // set up number of columns and rowslcd.setCursor(0, 0); // move cursor to (0, 0)lcd.print("Arduino"); // print message at (0, 0)lcd.setCursor(2, 1); // move cursor to (2, 1)lcd.print("Welcome"); // print message at (2, 1)}void loop(){int analogin = analogRead(sensorpin);float voltage = analogin*5.0/1024;float temp = (voltage - 0.5)*100;lcd.clear();lcd.setCursor(0, 0); // move cursor to (0, 0)lcd.print("Suhu in C"); // print message at (0, 0)lcd.setCursor(2, 1); // move cursor to (2, 1)lcd.print(temp); // print message at (2, 1)delay(1000);}
10. Piezo Buzzer
1. Piezo Buzzer dengan Tombol (Piezo Buzzer with Button)
Kode :
const int BUTTON_PIN = 7; // Arduino pin connected to button's pinconst int BUZZER_PIN = 2; // Arduino pin connected to Buzzer's pinvoid setup() {Serial.begin(9600); // initialize serialpinMode(BUTTON_PIN, INPUT_PULLUP); // set arduino pin to input pull-up modepinMode(BUZZER_PIN, OUTPUT); // set arduino pin to output mode}void loop() {int buttonState = digitalRead(BUTTON_PIN); // read new stateif (buttonState == LOW) {Serial.println("The button is being pressed");digitalWrite(BUZZER_PIN, HIGH); // turn on}elseif (buttonState == HIGH) {Serial.println("The button is unpressed");digitalWrite(BUZZER_PIN, LOW); // turn off}}
2. Piezo Buzzer dengan Potentiometer (Piezo Buzzer with Potentiometer)
Kode :
const int POTENTIOMETER_PIN = A1; // Arduino pin connected to Potentiometer pinconst int BUZZER_PIN = 2; // Arduino pin connected to Buzzer's pinconst int ANALOG_THRESHOLD = 500;void setup() {pinMode(BUZZER_PIN, OUTPUT); // set arduino pin to output mode}void loop() {int analogValue = analogRead(POTENTIOMETER_PIN); // read the input on analog pinif(analogValue > ANALOG_THRESHOLD)digitalWrite(BUZZER_PIN, HIGH); // turn on Piezo BuzzerelsedigitalWrite(BUZZER_PIN, LOW); // turn off Piezo Buzzer}
3. Piezo Buzzer dengan Sensor Ultrasonik (Piezo Buzzer with Ultrasonic Sensor)
Kode :
const int POTENTIOMETER_PIN = A1; // Arduino pin connected to Potentiometer pinconst int BUZZER_PIN = 2; // Arduino pin connected to Buzzer's pinconst int ANALOG_THRESHOLD = 500;void setup() {pinMode(BUZZER_PIN, OUTPUT); // set arduino pin to output mode}void loop() {int analogValue = analogRead(POTENTIOMETER_PIN); // read the input on analog pinif(analogValue > ANALOG_THRESHOLD)digitalWrite(BUZZER_PIN, HIGH); // turn on Piezo BuzzerelsedigitalWrite(BUZZER_PIN, LOW); // turn off Piezo Buzzer}
ESP32 Pinout :
ESP8266 Pinout :
Dan masih banyak lagi Proyek-proyek Arduino lainnya yang bisa kamu coba dengan menggunakan Tinkercad.
MEMBUAT RANGKAIAN DAN KODE ARDUINO SEDERHANA MENGGUNAKAN ARDUINO IDE
Sumber Tutorial (Referensi) : Enbriandika.blogspot.com, Rsetiawan.com, dan Iotles.com (LED Arduino)
1. Lampu LED
Alat dan Bahan :
- ESP32, ESP8266, Arduino Uno, dll. (Pilih salah satunya)
- Lampu LED
- Resistor 330 Ohm (Masing-masing 1 Buah untuk 1 Lampu)
- Kabel Jumper (Female dan Male)
1. Lampu LED Tunggal (1 LED)
void setup() {// menginisialisasi pin digital GIOP18 sebagai output.pinMode(18, OUTPUT);Serial.begin(9600);}// fungsi loop berjalan berulang-ulang selamanyavoid loop() {digitalWrite(18, HIGH); // nyalakan LEDSerial.println("Lampu ON");delay(500); // tunggu 500 milidetikdigitalWrite(18, LOW); // matikan LEDSerial.println("Lampu OFF");delay(500); // tunggu 500 milidetik}
Output :
2. Lampu LED Ganda (2 LED)
int led1 = 18;int led2 = 19;void setup() {pinMode(led1, OUTPUT);pinMode(led2, OUTPUT);}void loop() {digitalWrite(led1, HIGH);digitalWrite(led2, LOW);delay(1000); // Wait for 1000 millisecond(s)digitalWrite(led1, LOW);digitalWrite(led2, HIGH);delay(1000); // Wait for 1000 millisecond(s)}
Output :
2. Lampu LED RGB
Alat dan Bahan :
- ESP32, ESP8266, Arduino Uno, dll. (Pilih salah satunya)
- Lampu LED RGB
- Resistor 330 Ohm (Minimal 3 untuk 1 Lampu)
- Kabel Jumper (Female dan Male)
#define PIN_RED 35#define PIN_GREEN 32#define PIN_BLUE 33void setup() {pinMode(PIN_RED, OUTPUT);pinMode(PIN_GREEN, OUTPUT);pinMode(PIN_BLUE, OUTPUT);}void loop() {// color code #00C9CC (R = 0, G = 201, B = 204)analogWrite(PIN_RED, 0);analogWrite(PIN_GREEN, 201);analogWrite(PIN_BLUE, 204);delay(1000); // keep the color 1 second// color code #F73D8A (R = 247, G = 61, B = 138)analogWrite(PIN_RED, 247);analogWrite(PIN_GREEN, 61);analogWrite(PIN_BLUE, 138);delay(1000); // keep the color 1 second// color code #34A853 (R = 52, G = 168, B = 83)analogWrite(PIN_RED, 52);analogWrite(PIN_GREEN, 168);analogWrite(PIN_BLUE, 83);delay(1000); // keep the color 1 second}
Output :
1. Sensor Ultrasonik
Alat dan Bahan :
- ESP32, ESP8266, Arduino Uno, dll. (Pilih salah satunya)
- Sensor Ultrasonik
- Resistor 330 Ohm
- Kabel Jumper (Female dan Male)
int led1 = 18;int led2 = 19;void setup() {pinMode(led1, OUTPUT);pinMode(led2, OUTPUT);}void loop() {digitalWrite(led1, HIGH);digitalWrite(led2, LOW);delay(1000); // Wait for 1000 millisecond(s)digitalWrite(led1, LOW);digitalWrite(led2, HIGH);delay(1000); // Wait for 1000 millisecond(s)}
Output :
2. PIR Sensor dengan LED
Alat dan Bahan :
- ESP32, ESP8266, Arduino Uno, dll. (Pilih salah satunya)
- Sensor Gerak (PIR Sensor)
- Resistor 330 Ohm
- Kabel Jumper (Female dan Male)
int pirSensor = 18;int ledPin = 19;void setup() {pinMode(pirSensor, INPUT);pinMode(ledPin, OUTPUT);Serial.begin(9600);}void loop() {int pirpin = digitalRead(pirSensor);int sensorValue = digitalRead(pirSensor);if(pirpin == HIGH) {digitalWrite(ledPin, HIGH);} else {digitalWrite(ledPin, LOW);}}
Output :
Untuk melihat Artikel tentang Modul Arduino, silakan lihat di sini.
Semoga saja Artikel ini sangat bermanfaat bagi para IT Pemula. Selain menggunakan ESP32, kalian juga bisa menggunakan ESP8266 atau Arduino (Uno, Nano, Mega, dll) untuk Mikrokontroler yang digunakan dalam Praktikum ini. Mohon maaf apabila ada kesalahan dalam penulisan Kode. Terima Kasih 😄😘👌👍 :)
Wassalamu‘alaikum wr. wb.