Project 2 : Simple Input / Ouput using ESP32 , LED , and Push-Button

Hello Guys ✋, welcome back to my blogspot. So on this adventure, I will create a simple ESP 32👾 project. What I'm going to do is create a simple input/output using an LED light and a Push-button. The simple mechanism looks like this. When we press the push button 🔘, what happens is the LED light 💡will light up. Meanwhile, when we release the push button 🔘, what happens is the LED light will turn off 💡. easy isn't it 😏? Come on, for that, without lingering any longer, let's make it right away!


👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇👇


🔩 SET UP 🔩 :

-.1 Pcs of ESP32 



- 3 Pcs of 5 mm LED




- 4 Pcs of 330 ohm resistor 





- 1 Pcs of Tactile push-button




- 4 Pcs of 10k ohm resistor




- 1 Pcs of Breadboard



- 7 Pcs of jumper wires Male to Male


- 1 Pcs of Micro USB Cable 





** Next is that we will form a circuit on the breadboard like the schematic diagram below 👇 **







SET UP CODE : 

1.Open your Arduino IDE and adopt this code 

/*
  Button

  Turns on and off a light emitting diode(LED) connected to digital pin 5,
  when pressing a pushbutton attached to pin 4.
*/

// constants won't change. They're used here to set pin numbers:
const int buttonPin = 4;  // the number of the pushbutton pin
const int ledPinGreen = 5;    // the number of the LED pin
const int ledPinBlue = 18;    // the number of the LED pin
const int ledPinYellow = 19;    // the number of the LED pin

// variables will change:
int buttonState = 0;  // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPinGreen, OUTPUT);
  pinMode(ledPinBlue, OUTPUT);
  pinMode(ledPinYellow, OUTPUT);

  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == LOW) {
    // turn LED on:
    digitalWrite(ledPinGreen, HIGH);
    delay(500);
    digitalWrite(ledPinGreen, LOW);
    digitalWrite(ledPinBlue, HIGH);
    delay(500);
    digitalWrite(ledPinBlue, LOW);
    digitalWrite(ledPinYellow, HIGH);
    delay(500);
    digitalWrite(ledPinYellow, LOW);
  } else {
    // turn LED off:
    digitalWrite(ledPinGreen, LOW);
    digitalWrite(ledPinBlue, LOW);
    digitalWrite(ledPinYellow, LOW);
  }
}

2. Connect your ESP32 to your laptop or computer using micro usb cable . Then Go to Tools → Board , and select the type of board you are using. In this case, I use the ESP 32 Dev Module.



3.Go to Tools  Port and select the COM port the ESP32 is connected to. In this project, I use port COM3.




4.Click verify button and wait a few seconds




5.Click upload button and wait a few seconds



6. The circuit can already be used after the code has been compiled. Press the push button and watch the light turn on; as soon as you release the push button, the light will turn off. For more details, you can see the video below.




Yeay, the project has been successfully executed!!!






Comments

Popular posts from this blog

Project 7 : Connecting ESP32 and our smartphone with bluetooth connection