Show Posts
Pages: [1] 2
1  Topics / Home Automation and Networked Objects / Re: need guidance on setting up on: April 08, 2014, 05:39:06 pm
I can help you with some things:

Quote
-This app communicates to the arduino via home Wifi network.

You might want to see https://www.spark.io/, or maybe some wifi shields https://www.sparkfun.com/products/11287

Quote
-Perform basic operations like switching ON/OFF lights, fans, door locks, open/close curtains, garage door, etc..

For appliances switching please study relays or triacs. Can't help you on door locking, motor driven appliances

Quote
-Control the A/C, basic controls like temperature(+/-), fan speed(+/-).

As for the A/C, you need a logic analyser, or a osciloscope, or a IR sensor to crack the IR remote code
this is good => https://learn.adafruit.com/ir-sensor/overview
and this is great => http://hackaday.com/2013/09/27/learn-to-translate-ir-codes-and-retransmit-using-arduino/

Cant help much with the rest though. Havent got much experience with them
2  Topics / Home Automation and Networked Objects / Re: HA Architecture on: April 08, 2014, 05:28:40 pm
I'm interested in your approach to automate a previously wired home. Would you mind explaining more?

Quote
...tiny arduino-based PLC next to each light switch, with a relay next to it.
PLC stands for powerline comm? Or to programmable logic controller?
Please describe this arduino module more

Quote
  About 10cm of DIN rail, screwed to a rafter and professionally+legally wired up to the existing fittings with mains-legal (C-tick/CE) relays.
This DIN rail is separated from the one that already existed in your house? Since you say professionally, I'll consider you had some electrical company wire for you, right?
Also, if something is C-tick/CE ... they're like approved by a major company/government to personal/comercial use? I'm from Brazil, you see.

Quote
The PLCs are all chained together with a multidrop serial bus (probably CAN, maybe RS-485) that carries control and DC power for the PLCs.  There's also a linux single board computer hanging off the serial bus
By chained together do you mean tons of cables? How are you handling cable mess?
Can you help me making a multidrop serial bus? Really interested in your ideas
3  Topics / Home Automation and Networked Objects / Re: HA Architecture on: April 03, 2014, 05:42:54 pm
I'm putting them up myself, so it's cheaper $40 -> $25 (less if CC3000 is the free sample version from TI)

Oh, they are that cheap? Where do you get them?
You need lots of modules/shields (and money) to put up a zigbee powered system online.
Arduino + Xbee Shield + Xbee, isnt it?
It's like you buy your own router to make them comm on it.
Or I'm doing it the wrong way? Is there another way to comm over zigbee that doesnt use arduino?

The Spark core is a arduino with the price of a arduino, but with internet connection. Plus you can get to program it remotely, no additional setup.
With a wifi connection, I can use the previously existing wifi router.

Anyway. Sorry to sing too much of it's praises but it's just that I really like the Spark Core.

And regardless of the noise I wanted to DIY power line communications, do you have any hints, tips, tricks?
4  Topics / Home Automation and Networked Objects / Re: HA Architecture on: April 03, 2014, 11:44:01 am
Thanks for the long and very enlightening reply. Do hou have any idea on how those digitalStrom bricks get so tiny?
I would consider PLC if it was this size (very easy to install), neverminding the noise. I wanted to do a proff of concept on the physical size of those RX and TX PLC modules. Needed some real life IC examples, can you guys help me?

Since I'm going to work with Spark - it has wireless internet connection -, expanding is a no-brainer. Besides, zigbees are pretty much expensive.
5  Topics / Home Automation and Networked Objects / Re: Plugging arduino to wall switch on: March 29, 2014, 09:33:46 pm
Thanks for all the feedback!

It was a anoying lock from

Code:
//vw_wait_rx(); // wait until rx receives a message (NO! this locks the arduino, so no more loop iterations)
!!!

It was making me crazy! Anyways, it's now working. Thanks a lot! No! I'm being serious, you saved me from hours of 'debugging'.

The arduino pullup is not enought though... Going to isolate it well, as you advised
The 300ms delay is so I cause no radio frequency interference in other devices - this device is working in half-duplex, so I must listen, stop, send, listen.
6  Topics / Home Automation and Networked Objects / Re: Plugging arduino to wall switch on: March 29, 2014, 07:14:41 am
Thanks. The input is working now.

Need to make the output work now...

Code:
RelayDevice relays[RELAY_COUNT] =
{RelayDevice(5, RFCode('A', 'a', 'B', 'b'), 2, true),
RelayDevice(6, RFCode('C', 'c', 'D', 'd'), 3, true)};
isn't working.

i don't think this kind of initialization is really storaging the instance of ButtonDebounce on _toggle_switch...

Constructor
Code:
RelayDevice::RelayDevice(int p, RFCode code, int b, bool inv) : pin(p), _toggle_switch(b, inv) {
    pinMode(pin, OUTPUT);
    digitalWrite(pin, LOW);
    _code = code;
    state = false;
}
Class
Code:
class RelayDevice {
public:
    RelayDevice(int p, RFCode code, int b, bool inv=true);
    boolean getState();
    RFCode getRFCode();
    void switchState();
    boolean poll();
    ButtonDebounce _toggle_switch;

private:
    int pin;
    RFCode _code;
    bool state;
};
7  Topics / Home Automation and Networked Objects / Re: Plugging arduino to wall switch on: March 28, 2014, 09:00:43 pm
Okay, I'm trying to poll it from the RelayDevice class itself but I'm not getting the hang of this operator.

Code:
RelayDevice::RelayDevice(int p, RFCode code, int b, bool inv) : pin(p), _toggle_switch(b, inv) {
    pinMode(pin, OUTPUT);
    digitalWrite(pin, LOW);
    _code = code;
    state = false;
}
ButtonDebounce &RelayDevice::getSwitch() {
    return _toggle_switch;
}
boolean RelayDevice::getState() {
    return state;
}
RFCode RelayDevice::getRFCode() {
    return _code;
}
void RelayDevice::switchState() {
    state = !state;
    digitalWrite(pin, state);
}
boolean RelayDevice::poll() {
    _toggle_switch.scan();
    if (_toggle_switch.hadPress()) {
        switchState();
        return true;
    }
    return false;
}

I'm trying to
Code:
for(int i = 0; i < RELAY_COUNT; i++){
                if (relays[i].poll()) {
Serial.print("switched");
delay(300); // delay to avoid interference
feedbackStateMessage(i); // feedback to the mainframe
                }
}

but I dont think I've initialized ButtonDebounce, since output wont work...
Going to test it separately
edit: mistake I made
edit2: tested only the output and it's not working out... the output changes only when I change the state of the switch twice with this code

Code:
boolean state = false;
ButtonDebounce button1(2, true);
void setup()
{
pinMode(5, OUTPUT);
}

void loop()
{
  button1.scan();
  if (button1.hadPress()) {
      digitalWrite(5, state);
          state = !state;

  }
8  Using Arduino / Programming Questions / Re: Passing object as param on: March 28, 2014, 01:37:14 pm
Sorry. Here
9  Using Arduino / Programming Questions / Re: Passing object as param on: March 28, 2014, 09:46:36 am
thanks, didnt know you could attach files here.

Anyways, I've done some C++ research and come up with this.

@RelayDevice.cpp
Code:
RelayDevice::RelayDevice(int p, RFCode code, int b, bool inv) : pin(p), _toggle_switch(b, inv) {
Just wanted to know how to proceed correctly. Need one instance of ButtonDebounce and one of RFCode inside RelayDevice.
@recv_on_dig11_rev7_standalone.ino
Code:
/** Dont construct things inside constructors */
RelayDevice relays[RELAY_COUNT] =
{RelayDevice(5, RFCode('A', 'a', 'B', 'b'), 2, true),
RelayDevice(6, RFCode('C', 'c', 'D', 'd'), 3, true)/*,
RelayDevice(7, ButtonDebounce(12, true), RFCode('E', 'e', 'F', 'f')),
RelayDevice(8, ButtonDebounce(13, true), RFCode('G', 'g', 'F', 'f'))*/};
10  Topics / Home Automation and Networked Objects / Re: Plugging arduino to wall switch on: March 28, 2014, 09:42:11 am
Quote
Just put a switch between the pin and ground.

Yes sir.

Thanks for the OOP design advice, I don't know why I didn't think of this approach before.
The following code is from the new main. Still needs some working, but it's getting shape

Code:
#include <VirtualWire.h>
#include <RFCode.h>
#include <Debounce.h>
#include <RelayDevice.h>


int switchPin = 0;
char msg[1]; // for sending messages
const int RELAY_COUNT = 2;
const int RX_MODULE_PIN = 11;
const int TX_MODULE_PIN = 4;

/** Dont construct things inside constructors - RFCode part is working, strangely*/
RelayDevice relays[RELAY_COUNT] =
{RelayDevice(5, RFCode('A', 'a', 'B', 'b'), 2, true),
RelayDevice(6, RFCode('C', 'c', 'D', 'd'), 3, true)/*,
RelayDevice(7, ButtonDebounce(12, true), RFCode('E', 'e', 'F', 'f')),
RelayDevice(8, ButtonDebounce(13, true), RFCode('G', 'g', 'F', 'f'))*/};

void setup()
{
/** Initializing wireless communications */
vw_setup(2000);                   // Bits per sec
vw_set_ptt_inverted(true);        // Required for DR3100
vw_set_rx_pin(RX_MODULE_PIN);
vw_set_tx_pin(TX_MODULE_PIN);
vw_rx_start();
}

void loop()
{
for(int i = 0; i < RELAY_COUNT; i++){
relays[i].getSwitch().scan();

if(relays[i].getSwitch().hadPress()){ // look for switch events
relays[i].switchState(); // switch states

delay(300); // delay to avoid interference
feedbackStateMessage(i); // feedback to the mainframe
}
}

if (wasMessageReceived()) {
relays[switchPin].switchState();
}
}

boolean wasMessageReceived()
{
uint8_t buf[VW_MAX_MESSAGE_LEN] = "";
uint8_t buflen = VW_MAX_MESSAGE_LEN;

if (vw_get_message(buf, &buflen)) { // if received message
for(int i = 0; i < RELAY_COUNT; i++) {
switchPin = i;
boolean rightString = true;
if (strlen((char*)buf) == 1) { //one char to id message
if (relays[i].getState() && (uint8_t)relays[i].getRFCode().getOffCode() != buf[0]) { // ON and code is not OFF
rightString = false;
} else if ((uint8_t)relays[i].getRFCode().getOnCode() != buf[0]) { // OFF and code is not ON
rightString = false;
}
}
if (rightString) { // if it checked all letters and it's ok
return true;
}
} // iterates through all relays
} // if message received
return false;
}

void feedbackStateMessage(int i)
{
vw_rx_stop(); // stop listening so that it can send messages

if (relays[i].getState()) { // feedbacks that the appliance is on HIGH
msg[0] = relays[i].getRFCode().getFeedbackOnCode();
} else {  // feedbacks that the appliance is on LOW
msg[0] = relays[i].getRFCode().getFeedbackOffCode();
}
vw_send((uint8_t *)msg, strlen(msg)); // send the message
vw_wait_tx(); // wait until all message is gone

vw_rx_start(); // start listening so that it can receive messages
vw_wait_rx(); // wait until rx receives a message
}
The code for the RelayDevice is the following
Code:
#include "Arduino.h"
#include <RFCode.h>
#include <Debounce.h>
#include "RelayDevice.h"

RelayDevice::RelayDevice(int p, RFCode code, int b, bool inv) : pin(p), _toggle_switch(b, inv) {
    pinMode(pin, OUTPUT);
    digitalWrite(pin, LOW);
    _code = code;
    state = false;
}
ButtonDebounce RelayDevice::getSwitch() {
    return _toggle_switch;
}
boolean RelayDevice::getState() {
    return state;
}
RFCode RelayDevice::getRFCode() {
    return _code;
}
void RelayDevice::switchState() {
    Serial.print("SwitchME");
    state = !state;
    digitalWrite(pin, state);
}
Today I'm going to test it. Was having some Java programmer issues: not being able to pass objects as parameters (not using pointers) is troublesome.

Thanks for the constant feedback. I'm working with a prototype, so not going to mains until everything is robust.
Wanted to try some other solutions on how to switch AC appliances, and RF is not working out for me - sure it's cheap - but since I'm going to have lots of IoT appliances, the noise/interference will destroy me.
11  Using Arduino / Programming Questions / Passing object as param on: March 27, 2014, 07:39:55 pm
Need to create a RelayDevice that has a ButtonDebounce inside it as variable
HEADER
Code:
class RelayDevice {
public:
    RelayDevice(int p, ButtonDebounce *toggle_switch);
    ButtonDebounce* getSwitch();

private:
    int _p;
    ButtonDebounce *_toggle_switch;
};
CPP file
Code:
RelayDevice::RelayDevice(int p, ButtonDebounce *toggle_switch) {
    _p = p;
    pinMode(p, INPUT);
    digitalWrite(p, LOW);
    _toggle_switch = toggle_switch;
}
ButtonDebounce* RelayDevice::getSwitch() {
    return _toggle_switch;
}
HEADER
Code:
class ButtonDebounce {
public:

    ButtonDebounce(char p, bool inv=true);
    ButtonDebounce() {};

    /// inspect pin
    void scan();

    /// return current pin state
    bool getCurrentState() const;

    /// return true ONCE for each keydown
    bool hadPress();

private:
    char pin;
    bool state, event, invert;
    unsigned long changedat;

    // 20 ms must elapse since keyup before a new keydown will register
    static const unsigned long TIMEOUT=20000;
};
CPP file
Code:
ButtonDebounce::ButtonDebounce(char p, bool inv) : pin(p), invert(inv)
{
    pinMode(pin, INPUT);
    digitalWrite(pin, 1);
    state=false;
    event=false;
    changedat=0;
}

void ButtonDebounce::scan()
{
    bool newstate=digitalRead(pin) ^ invert;

    if(newstate != state){
        unsigned long now=micros();

        // changed after long-enough time
        if(now - changedat > TIMEOUT){
            changedat=now;
            state=newstate;
            if(state)
                event=true;
        }
    }
}

bool ButtonDebounce::getCurrentState() const
{
    Serial.print("\nMY pin is:'");
    Serial.print(pin);
    Serial.print("'");
    return state;
}

bool ButtonDebounce::hadPress()
{
    bool res=event;
    event=false;
    return res;
}

But when I instanciate it like this and try to access getCurrentState

Code:
ButtonDebounce button1(2, true);
RelayDevice relay(5, &button1);
relay.getSwitch()->getCurrentState();

prints nothing -> what am I doing wrong?
12  Topics / Home Automation and Networked Objects / Re: Plugging arduino to wall switch on: March 26, 2014, 07:03:18 am
Thank you very much for the elegant and fast answer.

Yesterday I was a little bit busy so I had to rush to make that fritzing. Cant make it work though: I'm wiring like this, but it doesn't seem like it is working. As for the resistor, I'm using a 1k Ohm. Should I change it? The power led flickers a little bit when trying to push the switch.

Quote
When you say "wall switch", is it going to be in a wall?  Is it going to be a significant distance from your arduino, or will the arduino be right behind the switch?  If there is more than a couple of metres of cable then you need to worry about noise being induced in the long cable, and protecting the Arduino's input pins.  Have a look into opto-isolation, for example.  Clearly you don't want to be doing the noise+safety analysis at this point, so keep your switch cable to under a metre and well away from power lines.
I think I'm working pretty much close to power lines, so I'll have a look into opto-isolation, thanks.
Also, I'm going to change from relays to triacs: they dont make that click noise and can dimmer.

Quote
edited to add: your wall switch should in no way ever be connected to the mains if it is also connected to the arduino.  Don't go near mains power unless you are qualified to do so because it is illegal+deadly.
Thank you for the warning: the arduino is plugged only to the switch, and the power lines are connected to the relay.


Code:
#define NDEV 4
int pins[NDEV] = {5, 6, 7, 8};
boolean on[NDEV] = {false, false, false, false};
int switchPin = 0;
int led_iterator;

/**
 * Debouncing of a single button to generate keypress events.
 */
class ButtonDebounce {
public:

    ButtonDebounce(char p, bool inv=true);

    /// inspect pin
    void scan();

    /// return current pin state
    bool getCurrentState() const;

    /// return true ONCE for each keydown
    bool hadPress();

private:
    char pin;
    bool state, event, invert;
    unsigned long changedat;

    // 20 ms must elapse since keyup before a new keydown will register
    static const unsigned long TIMEOUT=20000;
};

ButtonDebounce::ButtonDebounce(char p, bool inv) : pin(p), invert(inv)
{
    pinMode(pin, INPUT);
    digitalWrite(pin, 1);
    state=false;
    event=false;
    changedat=0;
}

void ButtonDebounce::scan()
{
    bool newstate=digitalRead(pin) ^ invert;

    if(newstate != state){
        unsigned long now=micros();

        // changed after long-enough time
        if(now - changedat > TIMEOUT){
            changedat=now;
            state=newstate;
            if(state)
                event=true;
        }
    }
}

bool ButtonDebounce::getCurrentState() const
{
    return state;
}

bool ButtonDebounce::hadPress()
{
    bool res=event;
    event=false;
    return res;
}

/// four input switches with debouncing, inverted inputs
const int SWITCH_COUNT=2;
ButtonDebounce switches[SWITCH_COUNT]={ ButtonDebounce(2, true), ButtonDebounce(3, true) };

void setup()
{
    // multiple outputs - iterates through all NDEVices
    for(led_iterator = 0; led_iterator < NDEV; led_iterator++) {
      pinMode(pins[led_iterator], INPUT);
      digitalWrite(pins[switchPin], LOW);
    }
}

void loop()
{
if (wasSwitchToggled()) {
switchRelayState(true);
}
}

void switchRelayState(boolean localTrigger)
{
    if (on[switchPin]) {
      digitalWrite(pins[switchPin], LOW);
      on[switchPin] = false;
    } else {
      digitalWrite(pins[switchPin], HIGH);
      on[switchPin] = true;
    }
   
    if (localTrigger) {
      delay(300); // delay to avoid interference
      sendStateMessage(on[switchPin]); // feedback to the mainframe
    }
}

boolean wasSwitchToggled()
{
  for(int i=0;i<SWITCH_COUNT;++i){
    switches[i].scan();
    switchPin = i;
   
    if(switches[i].getCurrentState()){
      // switch toggled
      return true;
    }

  }
  return false;
}
13  Topics / Home Automation and Networked Objects / Plugging arduino to wall switch on: March 25, 2014, 07:58:27 pm
I wanted to use the existing wall switch to arduino as an input. I've got two switches and I just dont know how to code nor wire everything up. Suggestions? Here's what I tried.



And the code:

Code:
#define NSWITCHES 2

int switch_iterator;
int switches[NSWITCHES] = {2,3};
int readingSwitch[NSWITCHES];
int previousSwitch[NSWITCHES];
int switchPin = 0;

void setup()
{
    Serial.begin(9600);
    for (switch_iterator = 0; switch_iterator < NSWITCHES; switch_iterator++) {
      pinMode(switches[switch_iterator], INPUT);
      previousSwitch[switch_iterator] = digitalRead(switches[switch_iterator]);
    }

}

void loop()
{
if (wasSwitchToggled()) {
Serial.print(switchPin);
}
}

boolean wasSwitchToggled() { 
        boolean toggled = false;
        for (switch_iterator = 0; switch_iterator < NSWITCHES; switch_iterator++) {
                switchPin = switch_iterator;
                readingSwitch[switch_iterator] = digitalRead(switches[switch_iterator]);
               
                if (readingSwitch[switch_iterator] != previousSwitch[switch_iterator]) {
                  toggled = true;
                }
 
                previousSwitch[switch_iterator] = readingSwitch[switch_iterator];
        }
return toggled;
}
14  Topics / Home Automation and Networked Objects / Re: HA Architecture on: March 13, 2014, 04:51:02 pm
I have no real problem with the comm between appliances, I just wanted to know how modded your house would get by implementing. Assuming I can interface them with each other and the central core,
how would the wiring be done? I'd like to have a uC attached to each light switch so I can feedback states. Did you understand me well?
15  Topics / Home Automation and Networked Objects / HA Architecture on: March 13, 2014, 11:47:33 am
hey guys, could you help me with this?


In a simple example, we have this house. It has only one room: inside it, it has four switches (in each wall) for two lights.
How do you work the architecture of the HA system in this room?
You can use one microcontroller for each switch and light/appliance, but it would cost too much. Alternatively, you could wire everything towards a single microcontroller, positioned in a convenient location. Nobody likes wires though.

What to do in this case? I know that this is a general example, and for each situation a different approach would be used - but anywhow I need some directions on how to start.

For my HA system I'm going to use some Spark Cores. I'm trying to use powerline communications (different implementation of x10 - diy) as a solution, but it seems it is just full of noises and no one recommends.
Pages: [1] 2