Project 5 : Display & PWM

👋👋👋 Hey everyone, and welcome back to my blog. In this project, we will experiment with the LCD and the ESP32 module. Also we will make PWM project using LED , Tactile Button , and ESP32  Because the project will be easier to complete this time.... let's get started straight now.



💣💣💣💣💣💣💣💣💣💣💣💣💣💣💣💣💣💣💣💣💣💣💣💣💣💣💣💣💣💣

🔌SET UP🔌

1. 1 Pcs of ESP32


2.  4 Pcs of Female to Female Cable Jumper



3. 1 Pcs of Micro USB cable


4.1 Pcs of LCD i2c 16 x 2

5. 3 Pcs of 5 mm LED




6. 4 Pcs of 330 ohm resistor 





7. 1 Pcs of Tactile push-button



8. 1 Pcs of Breadboard


9. 6 Pcs of jumper wires Male to Female



Experiment with ESP32 external display 

There are many things that we can print onto the LCD screen, but in this project we will try to make a clock that displays the date and time according to our respective timezones, in this project we use the UTC + 7 timezone.

👣 STEP BY STEP 👣

1.Set up the sensor circuit as illustrated in Figure .






2. Then open your arduino IDE and install the LiquidCrystal_I2C Library . Go to the tools tab > libraries manager and search with the keyword liquidcrystal . Then install the liquidcrystal i2c library by frank de brabander.






3.Adopt the code that I have modified below and make sure your device is connectef to the internet.

/*******************************************************************/
#include <WiFi.h>
#include "time.h"
#include "sntp.h"
#include "LiquidCrystal_I2C.h"

LiquidCrystal_I2C lcd(0x27 , 16 , 2);
const char* ssid       = "Enter your Wifi Name";
const char* password   = "Enter your Password Wifi";

const char* ntpServer = "pool.ntp.org";
const char* ntperver2 = "time.nist.gov";

//Set up time according to your timezone
const long  gmtOffset_sec = 3600 * 7; 
const int   daylightOffset_sec = 3600;

void printLocalTime()
{
  struct tm timeinfo;
  if(!getLocalTime(&timeinfo)){
    Serial.println("Failed to obtain time");
    return;
  }
  Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
  lcd.clear();

//Output The date in the top of LCD
  lcd.setCursor(0,0);

//Formatting output date
  lcd.print(&timeinfo,"%B %d %Y");

//Output the clock in the bottom of LCD
  lcd.setCursor(0,1);

//Formatting output data
  lcd.print(&timeinfo, "%H:%M:%S");

}

void setup()
{
  Serial.begin(115200);
  lcd.init();

// Make the output readable
  lcd.backlight();
  //connect to WiFi
  Serial.printf("Connecting to %s ", ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
  }
  Serial.println(" CONNECTED");
  
  //init and get the time
  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
  printLocalTime();

  //disconnect WiFi as it's no longer needed
  WiFi.disconnect(true);
  WiFi.mode(WIFI_OFF);
}

void loop()
{
  delay(1000);
  printLocalTime();
}

/*******************************************************************/

5. Click the Upload button and wait a few seconds for the words "Done Uploaded" to display. 



6.Pay attention to your LCD screen and observe whether the time shown on your LCD is the same as your current real time



PWM PROJECT 

"this project works to make the lights turn on and off with the addition of a brightness level transition. The way it works is quite simple, that is, when you press the push button, the light will turn on and then turn off with a certain period and with a brightness level that increases and decreases gradually."

👣 STEP BY STEP 👣

1.form a circuit on the breadboard like the schematic diagram below 👇 



2.Open your Arduino IDE and adopt this code 

// the number of the LED pin
const int ledPin = 16;  // 16 corresponds to GPIO16
const int ledPin2 = 17; // 17 corresponds to GPIO17
const int ledPin3 = 5;  // 5 corresponds to GPIO5
// this will assign the name PushButton to pin numer 15
const int PushButton = 15;
// setting PWM properties
const int freq = 5000;
const int ledChannel = 0;
const int resolution = 8;
 
void setup(){
  // configure LED PWM functionalitites
  ledcSetup(ledChannel, freq, resolution);
 
  // attach the channel to the GPIO to be controlled
  ledcAttachPin(ledPin, ledChannel);
  ledcAttachPin(ledPin2, ledChannel);
  ledcAttachPin(ledPin3, ledChannel);
  pinMode(PushButton, INPUT);
}
 
void loop(){
  int Push_button_state = digitalRead(PushButton);
  // increase the LED brightness
  if ( Push_button_state == HIGH )
{for(int dutyCycle = 0; dutyCycle <= 255; dutyCycle++){  
    // changing the LED brightness with PWM
    ledcWrite(ledChannel, dutyCycle);
    delay(15);
  }

  // decrease the LED brightness
  for(int dutyCycle = 255; dutyCycle >= 0; dutyCycle--){
    // changing the LED brightness with PWM
    ledcWrite(ledChannel, dutyCycle);  
    delay(15);
  }
}
else{
  digitalWrite(ledPin, LOW);
  digitalWrite(ledPin2, LOW);
  digitalWrite(ledPin3, LOW);  
}
 
}

3. 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.





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



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 gradually; as soon as you release the push button, the light will turn off gradually. For more details, you can see the video below.



🎉🥳Hooray, we've finished the Display & PWM Project 🎉



                    😄See you in my next blog with ESP32.👋 Bye Bye !



Comments

Popular posts from this blog

Project 7 : Connecting ESP32 and our smartphone with bluetooth connection