In many systems, we work on battery power or directly connected to electricity. And one of the major important factors that we must take into consideration is the reduction of energy consumption.
Increasingly, several companies/people are concerned about reducing consumption. The purpose of this is to improve the energy efficiency of the devices and the power grid.
Therefore, through these criteria, we developed a system to assist in reducing power consumption and shutting down parts of a microcontroller system with Arduino.
This system is useful for reducing power consumption and keeping most devices off while the system is not in use during a certain time.
In this project, you'll learn to use the Atto: World's Smallest Arduino to make this project.
The case you need to know the ATTO Board you can access the full article and to know all features: Know the ATTO Board.
Development ProjectThrough the need to reduce energy consumption. Increasingly, we need to create devices that have good energy efficiency.
Therefore, this project is intended to shut down certain loads on a system when the device is not being manipulated for more than 10 seconds.
The following is the code in Figure 1. The Nokia 5110 LCD was used to display the object count value detected by a sensor. The sensor is represented by the button.
In this circuit, we use a Red LED to signal the load to be turned off.
This LED will always be off when the system is not detecting new objects for more than 10 seconds.
For you to understand all the logic of this project, we'll teach through the code presented below.
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
Adafruit_PCD8544 display = Adafruit_PCD8544(3, 9, 6, 12, 4);
// pin 3 - Serial clock out (SCLK)
// pin 9 - Serial data out (DIN)
// pin 6 - Data/Command select (D/C)
// pin 12 - LCD chip select (CS/CE)
// pin 4 - LCD reset (RST)
bool state = 0, previous_state = 0, TurnOffDevice = 0;
byte quantity = 0, count = 0;
long int actual_time = 0, last_time = 0;
void TurnOffDevices();
void TurnOnDevices();
void setup()
{
display.begin();
display.setContrast(50);
pinMode(5, OUTPUT);
pinMode(14, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, INPUT);
pinMode(13, OUTPUT);
digitalWrite(5, HIGH);
digitalWrite(14, HIGH);
digitalWrite(10, HIGH);
digitalWrite(13, HIGH);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println(" Quantity");
display.setTextSize(2);
display.setCursor(35,10);
display.println(count);
display.display();
}
void loop()
{
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println(" Quantity");
actual_time = millis();
bool sensor = digitalRead(11);
delay(50);
if(previous_state == 0 && sensor == 1)
{
TurnOnDevices();
display.setTextSize(2);
display.setCursor(35,10);
count++;
display.println(count);
previous_state = 1;
display.display();
last_time = actual_time;
}
if((previous_state == 1 && sensor == 0))
{
previous_state = 0;
last_time = actual_time;
}
if((actual_time - last_time) > 10000 && previous_state == 0 && sensor == 0)
{
TurnOffDevices();
last_time = actual_time;
display.clearDisplay();
display.display();
}
}
void TurnOnDevices()
{
digitalWrite(14, HIGH);
}
void TurnOffDevices()
{
digitalWrite(14, LOW);
}
Initially, the Nokia 5110 Display libraries were declared, the variables and the connection pins between the ATTO board and the Display were defined.
Finally, prototypes of the functions to turn the devices on and off were declared, as is shown below.
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
Adafruit_PCD8544 display = Adafruit_PCD8544(3, 9, 6, 12, 4);
// pin 3 - Serial clock out (SCLK)
// pin 9 - Serial data out (DIN)
// pin 6 - Data/Command select (D/C)
// pin 12 - LCD chip select (CS/CE)
// pin 4 - LCD reset (RST)
bool state = 0, previous_state = 0, TurnOffDevice = 0;
byte quantity = 0, count = 0;
long int actual_time = 0, last_time = 0;
void TurnOffDevices();
void TurnOnDevices();
In the void setup function, we initialize the display and set its contrast to 50%. Then we set pins 5, 10 and 13 to turn off the RGB LED of the ATTO Board.
And finally, we set the button pin (pin 11) as input and the load pin (LED) as output.
void setup()
{
display.begin();
display.setContrast(50);
pinMode(5, OUTPUT);
pinMode(14, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, INPUT);
pinMode(13, OUTPUT);
digitalWrite(5, HIGH);
digitalWrite(14, HIGH);
digitalWrite(10, HIGH);
digitalWrite(13, HIGH);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println(" Quantity");
display.setTextSize(2);
display.setCursor(35,10);
display.println(count);
display.display();
}
In the void loop function, we cleared the display screen and presented the message Quantity and the object count value below, as shown in Figure 2.
We then begin the time monitoring process to find out if the device should can to turn off certain loads. For this, we use the millis function.
void loop()
{
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(BLACK);
display.setCursor(0,0);
display.println(" Quantity");
actual_time = millis();
bool sensor = digitalRead(11);
delay(50);
Note that the actual_time = millis () command; will return the current runtime value.
After this, digital pin 11 is read and stored in the sensor variable.
With the value of the sensor variable, the system will check the conditions to determine which actions to perform.
In the first condition, the system checks whether the previous value of the sensor variable was 0 and its current value is 1.
if(previous_state == 0 && sensor == 1)
{
TurnOnDevices();
display.setTextSize(2);
display.setCursor(35,10);
count++;
display.println(count);
previous_state = 1;
display.display();
last_time = actual_time;
}
If true, the system executes the TurnOnDevice function to activate the devices, increments the count value and displays its value on the user screen.
Soon after, it assigns 1 to the previous_state variable to signal that the previous sensor state is equal to 1.
Finally, it assigns the current_time value to last_time to indicate the last time value.
The next condition will check if the sensor previous state is 1 and the current sensor value is 0.
If this condition is true, the value of the previous_state variable will be 0. This is to signal that the sensor previous state has been set to 0 and the system may enter again in the first condition of the program if it was true.
Finally, we assign the current_time value to last_time to update the last time value.
Now we have the third and last condition of the program. It will be responsible for carrying out the load deactivation process when the sensor is not detecting objects for 10 seconds or more.
if((actual_time - last_time) > 10000 && previous_state == 0 && sensor == 0)
{
TurnOffDevices();
last_time = actual_time;
display.clearDisplay();
display.display();
}
Note that the condition will only be true when it meets the following criteria.
- The sensor must not be detecting any objects. Consequently, its value will be 0.
- The value of the previous_state variable must be 0, to indicate that previously the sensor was in an off state.
- The time difference between the current millis function read time and the previously stored time when the system was running must be 10000 ms.
This value is equivalent to 10 seconds. Therefore, assuming this condition is true, the system will perform the TurnOffDevices function to turn off the LED or other devices, as is shown in Figure 3. Hereafter, will update the value of the last_time variable and clear the Nokia display screen.
And the cycle repeats until the user presses the button again and the system turns on the load and increments the count as discussed in the first condition of the program.
Now, see how it is simple to implement this project and to turn on or off other loads. You can change the TurnOnDevices and TurnOffDevices functions and insert other pins to activate and deactivate other loads.
void TurnOnDevices()
{
digitalWrite(14, HIGH);
}
void TurnOffDevices()
{
digitalWrite(14, LOW);
}
These two functions are declared at the end of the code.
ConclusionThis project can be used for different purposes and especially when we want to use time as a parameter in our projects.
In this project, we use only one sensor/button, but you can expand this logic to more buttons/sensors in your system.
This way, when one or more buttons/sensors are not being manipulated or detecting anything, the system will turn off certain loads for the purpose of saving energy.
AcknowledgmentThe Silícios Lab thanks to the nionics.com to offer two ATTO boards for us.
Thanks to the PCBWay for support the our YouTube Channel and produce and assembly PCBs with better quality.
The Silícios Lab thanks UTSOURCE to offer the electronic components.
Comments