element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Blog Netduino Controlled Power Outlet
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: oneleggedredcow
  • Date Created: 19 Oct 2012 11:44 PM Date Created
  • Views 560 views
  • Likes 2 likes
  • Comments 0 comments
  • members_featured_project
  • arduino
Related
Recommended

Netduino Controlled Power Outlet

oneleggedredcow
oneleggedredcow
19 Oct 2012

Introduction

Earlier, I saw the post about the BrewPi and I got excited.  I mean really excited.  After reading up on it, I decided that I wanted to give it a shot and build one.  However, there was at least one thing that I wanted to change.  I didn’t want to crack open the fridge and start messing with the circuits inside.  That’s when I came across a blog post describing how to hack a wireless power switch and control it with an arduino.  This sounded much simpler and safer.  Also, I added a light sensor to the netduino in order to detect whether or not the power was on.

Hacking the Remote Control

To modify the remote control, I followed the steps listed here.  Here’s the circuit to build:

image

Here are the connections to the remote control:

image

Additional details can be found in the original blog post

Writing the Code

The code is fairly straight forward.  We are going to write an event handler so that when the button on the netduino is pressed, our code gets called.  To do this, we declare the button to be an InterruptPort:

 

InterruptPort button = new InterruptPort(Pins.ONBOARD_SW1, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);

 

Then we add an event handler to the OnInterrupt event:

 

button.OnInterrupt += new NativeEventHandler(button_OnInterrupt);

 

To start out, we are just going to toggle the state of the onboard LED:

 

private static bool isLedOn = false;

private static OutputPort led = new OutputPort(Pins.ONBOARD_LED, isLedOn);

private static OutputPort d0 = new OutputPort(Pins.GPIO_PIN_D0, false);

 

static void button_OnInterrupt(uint port, uint data, DateTime time)

{

  if (data == 0)

  {

    isLedOn = !isLedOn;

    led.Write(isLedOn);

  }

}

 

Now, if we push the button, the LED should turn on, and if we push the button again, the LED should turn off.

 

Our ultimate goal is to turn on/off the remote power supply, so inside the if statement, we will add the following code:

 

d0.Write(true);

Thread.Sleep(100);

d0.Write(false);

 

What this does is that it turns on the d0 (digital 0) output port, sleeps for 100 milliseconds (0.1 seconds), and then turns off the d0 output port.  This is equivalent to pushing the button on the remote control, holding it down for a fraction of a second and then letting it go.

Adding a Sensor to Detect When the Power Is On

If you read a couple of follow up posts to the blog that this is based on, the author ended up ditching the power switches used in this blog for different model so that they could be more certain whether or not the power was on.  Another option is to add a light sensor and detect whether or not the light on the front of the power switch is on.  This short video shows the light turning on when the switch is turned off:

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

So, by placing a sensor next to the light, we can determine whether or not the light sensor is on.  The circuit for the light sensor is a really easy one, and looks like this:

 

image

 

All that is left is some code to read the sensor and write out the value to the screen:

 

AnalogInput a0 = new AnalogInput(Pins.GPIO_PIN_A0);

 

while (true)

{

  int val = a0.Read();

  Debug.Print(val.ToString());

  Thread.Sleep(100);

}

 

By doing this, we can then tell whether or not the light is on, which in turn lets us know whether or not the power is on.

 

Here’s a video demonstration of the project:

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Conclusion

In this project, I hacked into a power switch remote controller in order to control it with a netduino, and implemented a light sensor to make sure that the command that I sent to the power switch was correctly received and executed.  Hopefully, I’ll be able to build upon this and hook it up to a fridge!

 

See Also

Netduino Tic Tac Toe

Attachments:
RemotePower.zip
  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube