DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report

Saving Electricity by Automating What Uses It

See a quick example that can be expanded on to use a motion sensor and a quick bit of code that turns on and off electrical devices based on movement.

Sulthony H user avatar by
Sulthony H
·
Nov. 30, 16 · Tutorial
Like (6)
Save
Tweet
Share
3.34K Views

Join the DZone community and get the full member experience.

Join For Free

Our daily activity relies on electricity to power lights, appliances, and the rest of our electronic devices. More electricity usage means more expense. Smart strategies can help us save electricity. It is not only saving a lot of money, but also helping stop global warming.

One of the strategies is to use electricity only as necessary. Restroom lights, alley/staircase lights, or meeting room air conditioners are some examples that usually unnecessarily turned on. Mostly, people do not care about that. They leave the room without turning off the lights or air conditioner.

The Solution Concept

In order to save electricity, we can automate the usage with a simple logic: turn on the lights only if there is a person there. If anyone leaves the room, then turn off the lights automatically. To avoid an incorrect decision, set a certain range of time tolerance. Hold a few minutes before turning off the light, in case the person who leaves the room comes back after just a moment.

Image title

This simple logic can be implemented with a cheap PIR Motion Sensor. That's a passive infrared sensor that detects and sends a signal when it captures any movement. The signal will be received by NodeMCU/Arduino for the next step. If no movement is detected, then NodeMCU will count the timer. Once the time tolerance is exceeded, then the system will send a signal to turn off the electrical connections.

Another important component is a Relay module. That's an electromagnetic switch that can be controlled by sending an electronic signal. This module is responsible for opening or closing the electrical connection based on the signal from the system. This module will act as a mediator between the high voltage devices and the microcontroller.

The Proof of Concept

To proof this concept, we can develop a simple project simulation to turn on/off an LED light. Basically, we can use an AC lamp with a direct electricity connection. But with safety in mind, we use a DC connection. The main purpose of this practice is turning on/off a device by using a Relay module.

Image title

The project can be started with this code snippet:

void loop() {
  statePir = digitalRead(pinPir);

  if (statePir == HIGH) {
    digitalWrite(pinRelay, LOW);
    timer = 0;

    Serial.println("motion detected - turn on");
  } else if (timer > 10000) {
    digitalWrite(pinRelay, HIGH);

    Serial.println("turn off");
  }

  Serial.print("timer: ");
  Serial.println(timer);

  timer += 100;

  delay(100);
}

The PIR Motion Sensor is responsible for capturing any movement and sending a signal to turn on the light. The Relay module receives the signal and closes the electrical connection. It turns the light on. Once the light is turned on, the timer will be reset to zero.

As long as no motion is detected, the system will count the timer. Image title

Later, when motion is detected, the system then sends a signal to turn on the device and reset the timer.

Image title

If no motion is detected within a certain range of time, the system then sends a signal to turn off the device.

Image title

That's that! With some hardware and a bit of code, you've bene able to create a connected motion sensor to save electricity.

Light (web browser) Signal Connection (dance) Concept (generic programming) AIR (program) Reset (computing) Moment Snippet (programming)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • 4 Best dApp Frameworks for First-Time Ethereum Developers
  • What “The Rings of Power” Taught Me About a Career in Tech
  • Browser Engines: The Crux of Cross-Browser Compatibility
  • How Agile Architecture Spikes Are Used in Shift-Left BDD

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: