Hello readers, hope you all are doing great. In this tutorial, we will discuss low power modes in ESP32, their purpose and their implementation to increase the battery life by reducing power consumption.
Where To Buy? | ||||
---|---|---|---|---|
No. | Components | Distributor | Link To Buy | |
1 | ESP32 | Amazon | Buy Now |
Fig.1
Along with multiple wireless and processing features, ESP32 also provides us with a power-saving feature by offering sleep modes. When you are powering the ESP32 module from the live supply using an adaptor or a USB cable, there is nothing to worry about power consumption. But when you are using a battery, as a power source to ESP32, you need to manage the power consumption for longer battery life.
When ESP32 is in sleep mode, a small amount of power is required to maintain the state of ESP32 in RAM (random access memory) and retain necessary data. Meanwhile, the power supply won’t be consumed by any unnecessary peripheral or inbuilt modules like Wi-Fi and Bluetooth.
ESP32 offers 5 power modes. Each mode is configurable and offers different power-saving capabilities:
Fig. 2
Fig 3
For a better understanding of low power modes in ESP32, we are going to implement deep sleep mode in esp32 and will also discuss how to wake up the device from deep sleep mode.
To implement deep sleep modes we are going to use another ESP32 feature that is Capacitive Touch Sensing pins. These pins can sense the presence of a body that holds an electric charge.
So we are going to use these touch-sensitive pins for waking up ESP32 from deep sleep mode using the Arduino IDE compiler.
In Arduino IDE examples are given for deep sleep mode with various wake-up methods.
#define Threshold 40 /* Greater the value, more the sensitivity */ RTC_DATA_ATTR int bootCount = 0; touch_pad_t touchPin; /* Method to print the reason by which ESP32 has been awaken from sleep */ void print_wakeup_reason(){ esp_sleep_wakeup_cause_t wakeup_reason; wakeup_reason = esp_sleep_get_wakeup_cause(); switch(wakeup_reason) { case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break; case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break; case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break; case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break; case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break; default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break; } } /* Method to print the touchpad by which ESP32 has been awaken from sleep */ void print_wakeup_touchpad(){ touchPin = esp_sleep_get_touchpad_wakeup_status(); switch(touchPin) { case 0 : Serial.println("Touch detected on GPIO 4"); break; case 1 : Serial.println("Touch detected on GPIO 0"); break; case 2 : Serial.println("Touch detected on GPIO 2"); break; case 3 : Serial.println("Touch detected on GPIO 15"); break; case 4 : Serial.println("Touch detected on GPIO 13"); break; case 5 : Serial.println("Touch detected on GPIO 12"); break; case 6 : Serial.println("Touch detected on GPIO 14"); break; case 7 : Serial.println("Touch detected on GPIO 27"); break; case 8 : Serial.println("Touch detected on GPIO 33"); break; case 9 : Serial.println("Touch detected on GPIO 32"); break; default : Serial.println("Wakeup not by touchpad"); break; } } void callback(){ //placeholder callback function } void setup(){ Serial.begin(115200); delay(1000); //Take some time to open up the Serial Monitor //Increment boot number and print it every reboot ++bootCount; Serial.println("Boot number: " + String(bootCount)); //Print the wakeup reason for ESP32 and touchpad too print_wakeup_reason(); print_wakeup_touchpad(); //Setup interrupt on Touch Pad 3 (GPIO15) touchAttachInterrupt(T3, callback, Threshold); //Configure Touchpad as wakeup source esp_sleep_enable_touchpad_wakeup(); //Go to sleep now Serial.println("Going to sleep now"); esp_deep_sleep_start(); Serial.println("This will never be printed"); } void loop(){ //This will never be reached }
Fig 12
Fig. 13 waking up esp32 using capacitive sensitive GPIO pin
We have attached a screenshot from the serial monitor for reference.Fig. 14
#define uS_TO_S_FACTOR 1000000ULL /* Conversion factor for micro seconds to seconds */ #define TIME_TO_SLEEP 5 /* Time ESP32 will go to sleep (in seconds) */ RTC_DATA_ATTR int bootCount = 0; /* Method to print the reason by which ESP32 has been awaken from sleep */ void print_wakeup_reason(){ esp_sleep_wakeup_cause_t wakeup_reason; wakeup_reason = esp_sleep_get_wakeup_cause(); switch(wakeup_reason) { case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break; case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break; case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break; case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break; case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break; default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break; } } void setup(){ Serial.begin(115200); delay(1000); //Take some time to open up the Serial Monitor //Increment boot number and print it every reboot ++bootCount; Serial.println("Boot number: " + String(bootCount)); //Print the wakeup reason for ESP32 print_wakeup_reason(); /* First we configure the wake up source We set our ESP32 to wake up every 5 seconds */ esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); Serial.println("Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) + " Seconds"); /* Next we decide what all peripherals to shut down/keep on By default, ESP32 will automatically power down the peripherals not needed by the wakeup source, but if you want to be a poweruser this is for you. Read in detail at the API docs http://esp-idf.readthedocs.io/en/latest/api-reference/system/deep_sleep.html Left the line commented as an example of how to configure peripherals. The line below turns off all RTC peripherals in deep sleep. */ //esp_deep_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF); //Serial.println("Configured all RTC Peripherals to be powered down in sleep"); /* Now that we have setup a wake cause and if needed setup the peripherals state in deep sleep, we can now start going to deep sleep. In the case that no wake up sources were provided but deep sleep was started, it will sleep forever unless hardware reset occurs. */ Serial.println("Going to sleep now"); Serial.flush(); esp_deep_sleep_start(); Serial.println("This will never be printed"); } void loop(){ //This is not going to be called }
Fig 15
Fig. 16
Fig. 17
Fig. 18
Fig. 19
Fig 20
This concludes the tutorial. I hope you found this useful, and I hope to see you soon for the new ESP32 tutorial.
Hello readers, I hope you all are doing great. Welcome to the 3rd Lecture of Section 2 in the ESP32 Programming Series. In this tutorial, we are going to discuss another important feature of ESP32 i.e. PWM(Pulse Width Modulation).
Pulse Width Modulation is a technique to reduce the voltage by pulsating it. In today's lecture, we will first understand the basic concept of PWM, and after that will design two projects to fully grasp it. In the first project, we will control the brightness of an LED, while in the second one, we will control the speed of a DC Motor.
Before going forward, let's first have a look at the PWM working:
Where To Buy? | ||||
---|---|---|---|---|
No. | Components | Distributor | Link To Buy | |
1 | ESP32 | Amazon | Buy Now |
PWM is used to control the power delivered to the load by pulsating the ON-Time of the voltage pulse, without causing any power loss. Let's understand the PWM concept with the help of below image:
Suppose a DC Motor runs at 200RPM over 5V. Now, if we want to reduce its speed to 100 RPM, we need to reduce its input voltage to 2.5V(approx). So, either we can replace the 5V battery with a 2.5V Battery or use a PWM circuit to reduce the voltage level from 5V to 2.5V. In this specific case, the PWM pulse will be ON for 50% of the time and get OFF for the remaining 50% of the time.
The behavior of the PWM signal is determined by the following factors:
As you can see in the below figure, we have taken two signals for a duration of 1 second. The first signal completes 10 Cycles in 1 second, so we can say it has a frequency of 10Hz, while the second one has a frequency of 5Hz as it completes 5 cycles in 1 second. So, I hope now it's clear that the number of cycles per second is the frequency of a signal.
Duty Cycle is the ratio of ON time(when the signal is high) to the total time taken to complete the cycle. The duty cycle is represented in the form of a percentage (%) or ratio. Let's understand the PWM Duty Cycle with the help of below image:
The resolution of a PWM signal defines the number of steps it can have from zero power to full power. The resolution of the PWM signal is configurable for example, the ESP32 module has a 1-16 bit resolution, which means we can configure maximum a of 65536 (2^16) steps from zero to full power.
In the ESP WROOM-32 module, there are 16 PWM channels. All the channels are divided into two groups containing 8 channels in each group. The resolution can be programmed between 1 to 16 bits and frequency also depends upon the programmed resolution of the PWM signal.
Now
For the demonstration of PWM in ESP32 we are going to explain two examples:
We are using Arduino IDE to compile and upload the code into the ESP WROOM-32 board.
// Global variable declaration to set PWM properties
const int ledChannel = 0; // select channel 0
const int resolution = 8; //8-bit resolutin i.e., 0-255
const int frequency = 5000; // set frequency in Hz
int dutyCycle = 0;
void setup()
{
Serial.begin(115200);
ledcSetup(ledChannel, frequency, resolution); // configure LED PWM functionalities
ledcAttachPin(LED_BUILTIN, ledChannel); // attach the channel to the GPIO to be controlled
}
void loop()
{
while(dutyCycle <200)
{
ledcWrite(ledChannel, dutyCycle++); // changing the LED brightness with PWM
Serial.print(" duty Cycle ++ :");
Serial.println(dutyCycle); // display the duty cycle on serial monitor
delay(5);
}
while(dutyCycle>0)
{
ledcWrite(ledChannel, dutyCycle--); // changing the LED brightness with PWM
Serial.print(" duty Cycle -- :");
Serial.println(dutyCycle); // display the duty cycle on serial monitor
delay(5);
}
}
// Global variable declaration to set PWM properties
const int ledChannel = 0; // select channel 0
const int resolution = 8; //8-bit resolutin i.e., 0-255
const int frequency = 5000; // set frequency in Hz
int dutyCycle = 0;
Serial.begin(115200);
ledcSetup(ledChannel, frequency, resolution); // configure LED PWM functionalities
ledcAttachPin(LED_BUILTIN, ledChannel); // attach the channel to the GPIO to be controlled
while(dutyCycle <200)
{
ledcWrite(ledChannel, dutyCycle++); // changing the LED brightness with PWM
Serial.print(" duty Cycle ++ :");
Serial.println(dutyCycle); // display the duty cycle on serial monitor
delay(5);
}
while(dutyCycle>0)
{
ledcWrite(ledChannel, dutyCycle--); // changing the LED brightness with PWM
Serial.print(" duty Cycle -- :");
Serial.println(dutyCycle); // display the duty cycle on serial monitor
delay(5);
}
Fig. 9 Serial plotter PWM output
Fig. 10
In this example, we are going to implement PWM using ESP WROOM-32 to control the speed of a DC motor.
The speed of the DC motor depends upon the input power supply. So, by varying the power input we can also vary (increase or decrease) the speed of DC motor.
Hardware components required:
L298N motor driver: A motor driver is used between the ESP32 board and DC motor to resolve the power compatibility issues.
Both the ESP32 board and DC motor operate at different power ratings due to which you can not connect the two devices directly. So a motor driver is used to receive a low power input from the ESP32 board and drive/run DC motor at slightly high power.
L298N can drive a DC motor that operated between 5 to 35 voltage range and maximum current of 2A.
There are various DC motor drivers available in the market for example L293D, DRV8833, MAX14870 single brushed motor driver etc. You can choose the driver of your choice depending upon the application and power ratings.
Fig. 11
FIG. 12 IC L298N pin-out
IN_1 | IN_2 | Rotation |
HIGH | LOW | DC motor rotates in a clockwise direction |
LOW | HIGH | The motor rotates in an anti-clockwise direction |
LOW | LOW | Motor STOP |
HIGH | HIGH | Motor STOP |
Table 1
//configure GPIO pins to connect motor driver
int enable1Pin = 14;
int M_Pin1 = 26;
int M_Pin2 = 27;
// Setting PWM properties
const int freq = 10000;
const int pwmChannel = 0;
const int resolution = 8;
int dutyCycle = 150;
void setup()
{
Serial.begin(115200);
// sets the pins as outputs:
pinMode(M_Pin1, OUTPUT);
pinMode(M_Pin2, OUTPUT);
pinMode(enable1Pin, OUTPUT);
//Configure LED PWM functionalities
ledcSetup(pwmChannel, freq, resolution);
// attach the channel to the GPIO to be controlled
ledcAttachPin(enable1Pin, pwmChannel);
Serial.print("Testing DC Motor...");
}
void loop()
{
// Move the DC motor in anti-clockwise direction at maximum speed
Serial.println("Moving reverse");
digitalWrite(M_Pin1, LOW);
digitalWrite(M_Pin2, HIGH);
delay(500);
// Move DC motor forward with increasing speed
Serial.println("Moving Forward");
digitalWrite(M_Pin1, HIGH);
digitalWrite(M_Pin2, LOW);
//----while loop----
while (dutyCycle <= 255)
{
ledcWrite(pwmChannel, dutyCycle);
Serial.print("Speed increasing with duty cycle: ");
Serial.println(dutyCycle);
dutyCycle = dutyCycle +5;
delay(100);
}
while (dutyCycle >150)
{
ledcWrite(pwmChannel, dutyCycle);
Serial.print("Speed decreasing with duty cycle: ");
Serial.println(dutyCycle);
dutyCycle = dutyCycle -5;
delay(100);
}
// _____Stop the DC motor
Serial.println("STOP DC motor");
digitalWrite(M_Pin1, LOW);
digitalWrite(M_Pin2, LOW);
delay(500);
}
//configure GPIO pins to connect motor driver
int enable1Pin = 14;
int M_Pin1 = 26;
int M_Pin2 = 27;
// Setting PWM properties
const int freq = 10000;
const int pwmChannel = 0;
const int resolution = 8;
int dutyCycle = 150;
Serial.begin(115200);
// sets the pins as outputs:
pinMode(M_Pin1, OUTPUT);
pinMode(M_Pin2, OUTPUT);
pinMode(enable1Pin, OUTPUT);
//Configure LED PWM functionalities
ledcSetup(pwmChannel, freq, resolution);
// attach the channel to the GPIO to be controlled
ledcAttachPin(enable1Pin, pwmChannel);
Fig. 20
Fig. 21 Increasing speed
Fig. 22 Reducing speed
Fig. 23 STOP DC motor
Fig. 24 PWM output on serial monitor
Fig. 25 PWM output on Serial Plotter
This concludes the tutorial. I hope you found this useful, and I hope to see you soon for the new ESP32 tutorial.The nearshoring phenomenon is a global economic trend that has been going on for decades. The phenomenon is defined as moving a company’s operations to a country that is in close proximity to the company’s home base.
Nearshoring offers many benefits in terms of cost savings, but it also has many drawbacks. It can have a negative effect on wages for local workers, and it can also have an impact on the environment if the process involves bringing in outsourced goods from overseas.
To conclude, nearshoring often benefits both companies and consumers who are looking for affordable goods at low prices. However, it can have a negative effect on wages and local jobs in the long run.
It's a great way for companies with smaller budgets to have more resources for other aspects of their business. However, it isn't without its challenges. For starters, a company will need someone on-shore to manage the team abroad and provide direction on how things should be done. In addition, there are cultural differences that may need to be addressed - such as different time zones or mores that may not line up with American values.
Nearshoring is becoming more popular because of the benefits it offers for both the outsourcing company and the nearshore company.
Nearshore outsourcing provides cost savings to companies that are looking to outsource their work. It offers lower overall risk than offshore outsourcing through the protection of intellectual property and by having better communications with the workforce.
While offshoring has been around for decades, nearshoring started gaining popularity in recent years due to its relative proximity to home markets, enabling companies to make quick decisions about products, services, marketing approaches, etc., which can be challenging when you are thousands of miles away. Nearshoring is appealing because it provides cost savings and lower risk than offshoring.
Nearshoring is a strategic sourcing technique that can be used to lower the cost of labor. It is also helpful in reducing the production lead time by enabling production capacity to be shared among different regions while centralizing key functions.
Nearshoring allows companies to take advantage of low-cost labor without having to relocate their manufacturing facilities. Through nearshoring, companies are able to maintain control over design and marketing while lowering production costs through outsourcing manufacturing processes abroad for example in China or India.
There are many countries in the world that offer a nearshore workforce and they differ in terms of their cost and quality. Some countries like India and China, with low labor costs and large populations, are popular outsourcing destinations. Other countries such as Indonesia and Malaysia, offer higher quality work based on their educational system. Nearshoring in Europe is also becoming more and more popular because of the low costs and good quality of the work.
There are many factors to take into account when outsourcing business processes or operations to a country. The type of work you need to be done will determine the country you choose for your operations, but there is one key factor that is often overlooked: the availability of human capital. Countries vary in terms of how educated their population is and what languages they speak, which can give an edge when it comes to choosing a country for your overseas operations.
The most prominent disadvantage is that organizations will lose vital skills and know-how when they outsource their projects. They may also lack the flexibility in decision-making for both short and long-term goals due to limitations on management decisions brought about by working with a third-party company. Organizations will also have a difficult time transferring any of their employees to different locations if they decide they want them closer to home in order for them to take care of family issues or have more opportunities for growth.
A good security system includes an alarm, immobilizer, and battery backup if you lose power to your car for any reason. It should have a remote lock/unlock capability which can be helpful if someone finds or steals your keys. You can even get systems these days that notify you on your phone if someone is trying to start your car.
The system should also have a GPS vehicle tracking device if your car is stolen. The police can track the car down and return it to you. The GPS device should enable you to monitor your car and what routes they have taken. Some of these devices will even allow you to set up alerts if the vehicle has been moved at any time during its idle state, which is excellent for catching thieves in action and alerting authorities immediately.
An added benefit of using a GPS tracking service is protecting your car from being towed. If thieves tow your vehicle, you can log into the service and search to see where it has been taken so that you know who stole it and call authorities immediately.
An excellent security system needs to be fitted with an alarm that will go off when someone unauthorized tries to open the car. The louder and more intrusive the alarm, the better. This way, the car's owner will be notified of a possible theft attempt and take precautions. You need to choose an alarm that alerts you when the car is being tampered with and one that can be activated remotely.
One way to prevent your car from being stolen is to install a steering lock. This will make it difficult for thieves to drive off with the car. There are a few different types of steering locks available on the market. A popular type is the club lock, which wraps around the steering wheel and prevents it from being turned.
Another option is to install a car alarm with a steering lock feature. This will sound an alarm if someone tries to move the car. Some cars come with a built-in steering lock that is activated when turned off.
If your car doesn't have a built-in steering lock, you can buy an aftermarket one to use. Whichever option you choose, make sure to properly secure the steering lock so that it cannot be easily removed. Another option is to use a wheel clamp. This will immobilize the car and make it difficult for thieves to steal.
Both of these solutions are a great deterrent against car theft and will help to protect your vehicle. Be sure to use them if you are concerned about your car being stolen.
This may seem like a no-brainer, but many people forget to do this essential step. Make it a habit to always lock your car doors and windows when you're not in it. This will make it more difficult for thieves to access your vehicle. If you're not in a hurry, you can also roll up your windows all the way and shut the doors.
If someone stops next to your car asking for help or directions, don't get out. Stay in your car and keep the doors locked. This allows criminals to unlock it from outside of the vehicle. Many times they will open already unlocked cars with this tactic.
The simplest thing you can do to keep your car from being stolen is always to lock your doors after getting out or entering the vehicle. This is especially important if you habit leaving your car running when you run into the store.
If you park your car in a well-lit area, it will be less likely to be targeted by thieves. Try to avoid parking in isolated or dark areas whenever possible. If you have a garage, use it.
If you have to park on the street, try finding a well-lit spot near other cars. This will make your vehicle less of a target for thieves. In a public parking lot, always park in an area close to the entrance and visible.
If you park under a tree, try to avoid parking near an overhanging branch that thieves could use as leverage for opening your car door or climbing inside. If possible, choose brightly lit areas with surveillance cameras nearby so the footage can be used to identify thieves in case they steal your vehicle.
When looking at potential spots to park, always be aware of your surroundings and look for any suspicious activity. If you see anything that makes you uncomfortable, find another spot to park in.
One of the best ways to prevent your car from being stolen is to not leave any valuables in it. If you have expensive items in your car, it will be more likely for thieves to target your vehicle. So, always make sure to take your belongings with you when you exit your car.
If you have to leave something in your car, try to keep it out of sight. You can put it in the trunk or under the seats. If you need to put things in the trunk or in the backseat, make sure to lock them up so that thieves can't get to them. You should also do this before you reach the parking lot so that thieves can't see what you're doing.
Remember, the best way to prevent your car from being stolen is by taking precautions and being vigilant about your surroundings. You can make it much more difficult for thieves to get their hands on your vehicle by following these tips.