Silícios LabPCBWay
Published © GPL3+

World's Smallest Arduino Applied in a System to Save Energy

You'll learn how to create a logic to turn off the system when it is not being used for a certain time.

BeginnerFull instructions provided1 hour1,116
World's Smallest Arduino Applied in a System to Save Energy

Things used in this project

Hardware components

PCBWay Custom PCB
PCBWay Custom PCB
×1
Nokia 5110 - UTSOURCE
×1
ATTO: The World's Smallest Arduino
×1
Push Button - UTSOURCE
×1
1kR Resistor - UTSOURCE
×1
Wire Jumpers - UTSOURCE
×1
Arduino UNO - UTSOURCE
×1
330R Resistor - UTSOURCE
×1
LED 5mm - UTSOURCE
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Code of the Project

Arduino
#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()   
{
  //Serial.begin(9600);
  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);
}

Credits

Silícios Lab

Silícios Lab

60 projects • 149 followers
Hello, I'm Diego Moreira, founder of the Silícios LAB and I love program microcontrollers and works with electronic projects.
PCBWay

PCBWay

63 projects • 116 followers
We are a pcb prototype and assembly manufacturer to help creators build projects. As low as $5/10pcs and 3 days delivery time.

Comments