TTT Microcontroller(s?)

Anything electric, AC or DC

Re: TTT Microcontroller(s?) -- project description

Postby capnTelescope » Mon Aug 31, 2015 11:30 am

First things first.

Dale, I completely respect your point of view. Camping is a chance to get away from it all, drink in the view, see nature up close, enjoy quiet and solitude, or sit around a campfire and have a great conversation with your camping buddies. We build our trailers to do all these things and have shelter from the storm, to get away from the drudgery of pitching a tent, the discomfort of sleeping on the ground, or to take a rest from the road. I get it.

For some of us, building our trailers turn into a hobby. It's a chance to develop new skills, make something according to our ability, and as a reflection of ourselves. Minimalist or maximalist. Simplicity or pushing the envelope. It's all good.

My first words in this thread sum it all up. "Because we can."

Good roads and happy camping! :beer:
I'll burn that bridge when I come to it.

Brad
ImageImageImage

Building the Bed & Breakfast
User avatar
capnTelescope
Lifetime member
 
Posts: 1218
Images: 368
Joined: Sun Jun 27, 2004 3:44 pm
Location: Round Rock, TX

Re: TTT Microcontroller(s?) -- project description

Postby capnTelescope » Mon Aug 31, 2015 11:57 am

Thanks for stopping by, Gerry.

GerryS wrote:Might be interesting to see if you could use Zigby and an Arduino shield.

We'll get there eventually. In the meantime, I'd be interested in your ideas on what might be done thru Zigby. You might have thought of something the rest of us haven't.

GerryS wrote:Watch your parasitic load.

Yup. I already have some of that in my USB charging port. Something south of 20mA. Note to self: figger out how to reduce that when not actually charging something.

GerryS wrote:I did a quick search, but don't see any low voltage switches :(.

Check this out: SainSmart 8-Channel Relay Module. It's not an Arduino shield, but it's definitely compatible.
I'll burn that bridge when I come to it.

Brad
ImageImageImage

Building the Bed & Breakfast
User avatar
capnTelescope
Lifetime member
 
Posts: 1218
Images: 368
Joined: Sun Jun 27, 2004 3:44 pm
Location: Round Rock, TX

Re: TTT Microcontroller(s?) -- project description

Postby troubleScottie » Mon Aug 31, 2015 9:53 pm

Continuing your train of thought -- right now you have 1 switch for whatever. Obviously one could extend this to 2 switches for a particular function. For instance, I like the idea of having a porch light switch inside both doors -- so entering either side one can get to the light(s). Not much an extension.

I want to be able to turn on the water heater when the galley is open or closed. And the same for the water pump. And not necessarily both at the same time. So the current design needs two spdt switches plus other wiring for each device.

I also want to be able to have some items one even while towing eg the frig. Also having a 10 amp utility light powered without getting inside would be nice. It would be nice to ensure everything else is powered off.



I was thinking about the switch... So your current design has all the wiring coming to a common spot.

One idea is a very old idea of peeking/poking at memory latch. Poking (applying voltage) at the latch causes it to change state. One does not need to constantly apply voltage -- just momentarily. Using a momentary on switch, you cause the latch to switch state. On again, the latch switches state again.

The micro processing could inspect the latch (peek) say every 100th a second and set a relay appropriately. The best time might bit faster or slower. I forget what is optimal for humans to perceive change. Or the latch could directly control the relay !??

This would give you -- on then off then on then off etc. The switch is never in any state, only the latch.

You could even have the latch go to some preferred state when the power is off or initialize when the microcomputer states up. Code would allow you to configure which switch controls which device and what the initial state of each powered device is.

The next level is to make a more complex latch cycle -- 3 or more states.

So for the porch lights:
state one: both off
state two: both on
state three: right on, left off
state four: left on, right off

The neat thing is if you had two switches, pressing either one in any order advances the cycle position.

How to wire this? I do not know. I am reasonably sure this would work.


=========== one internet search latter =================

Possible solution: $10 on ebay. There are other similar ones. This has both the latch and the relay, so not too terrible....

Latching Relay Board Description
Latching (bistable) relay is a special kind of relay. These are also called "impulse", "keep" or "stay" relays. When the current is switched off, the relay remains in its last state. While a conventional relay uses power continuously when its internal switch is to be closed (relay coil energized), a latching relay require only a brief voltage pulse to change state. The relay will maintain its state when the power supply removed.

A brief (<1s) pulse to Set will close AC terminals, BC will be open
A brief (<1s) pulse to Reset will close BC terminals, AC will be open

No power needs to be supplied to maintain its state, ideal for battery applications
High quality terminal blocks
12V operating voltage
dimension: 77x30mm (PCB size)
Set/Reset signal levels:
Low level: 0-0.7V
High level: >2V
Michael Krolewski
Scottish Terrier Fancier
troubleScottie
Donating Member
 
Posts: 358
Images: 16
Joined: Sat Apr 11, 2015 5:02 am
Location: Seattle, WA
Top

Re: TTT Microcontroller(s?) -- First working code

Postby capnTelescope » Mon Aug 31, 2015 11:05 pm

Progress!

I spent today straightening out a mess, getting reacquainted with the Arduino IDE, being reminded why I always resisted learning the C language and making some actual progress.

It's been a while since I did what little work I've done with the Arduino. I had 2 old versions of the IDE on my computer, and couldn't keep things straight. A little backing up directories, uninstalling the old and in with the latest, and things started humming.

With that out of the way, I could work on the 3-switch porch light issue. This meant coming up with a software equivalent of this circuit using the Arduino and the existing SPST switches.:
Image

My first effort worked just fine... for having the light OFF, but ON didn't work at all. I'm halfway there already! :roll: Actually, I can't tell for sure if it's a circuit problem or software, because neither has been tested successfully. Now I needed some debugging output from a device with no screen or other human interface device. Hitting the books, I found there is serial output to the Arduino Serial Monitor which is on your PC screen, slick as whale snot. Here's where I was reminded of my aversion to the C language. Did you know that there is an important difference between "serial" and "Serial"?* One works and one doesn't. (see below if you don't get it)

Once I got past that, things started coming together. I got ON working with one switch. After that, it was easy to get to 3 switches, and it works! All it needs now is some circuitry to handle a 2-3 watt LED load.
Image

Here's a quick video showing the circuit in action:


Just for the record, I've written more code in the last 3 days than in the past ten years. It felt good to do it again. Part of me wants everything to work on the first try, and part of me secretly enjoys the hunt for a software/circuit problem. Speaking of code, I'll show the code in the next post.
Open the pod bay door, Hal! :beer:
* In the C language, capitalization matters. It's all about the capital "S". :oops:
Last edited by capnTelescope on Tue Sep 01, 2015 12:42 am, edited 1 time in total.
I'll burn that bridge when I come to it.

Brad
ImageImageImage

Building the Bed & Breakfast
User avatar
capnTelescope
Lifetime member
 
Posts: 1218
Images: 368
Joined: Sun Jun 27, 2004 3:44 pm
Location: Round Rock, TX
Top

Re: TTT Microcontroller(s?) -- First working code

Postby capnTelescope » Mon Aug 31, 2015 11:11 pm

Here's the code that did that.

Code: Select all
// define pins
//inputs
int porchLightSwitch1 = 23; //cabin right
int porchLightSwitch2 = 25; //cabin left
int porchLightSwitch3 = 27; //galley

//pwm outputs
int porchLight = 2;

// system variables
//saved sensor states
int porchLightSwitch1State_old = 0; //cabin right
int porchLightSwitch2State_old = 0; //cabin left
int porchLightSwitch3State_old = 0; //galley

// fresh sensor states
int porchLightSwitch1State = 0; //cabin right
int porchLightSwitch2State = 0; //cabin left
int porchLightSwitch3State = 0; //galley

//percent Brightness = 0 - 100
int porchLightBrightness = 0;

// begin time of ON state (milliseconds). Rolls over to zero in 55 days
unsigned long porchLightTimeOn = 0;

// elapsed time in ON state (seconds)
unsigned long porchLightElapsedTimeOn = 0;

// other
int batteryChargePercent = 100;
const int batteryAmpHourCapacity = 100;


void setup() {
  Serial.begin(9600);
  // init pins
  pinMode(porchLightSwitch1, INPUT);
  pinMode(porchLightSwitch2, INPUT);
  pinMode(porchLightSwitch3, INPUT);
  pinMode(porchLight, OUTPUT);

  // get actual switch states
  porchLightSwitch1State_old = digitalRead(porchLightSwitch1); //cabin right
  porchLightSwitch2State_old = digitalRead(porchLightSwitch2); //cabin left
  porchLightSwitch3State_old = digitalRead(porchLightSwitch3); //galley
  Serial.print("!");
}

void loop() {
  //Serial.print(".");
  //get battery info
  //getBatteryInfo();
  //service porch Light
  servicePorchLight();

}

void servicePorchLight() {
  // get sensor switch(es) status
  //Serial.print("+");
  porchLightSwitch1State = digitalRead(porchLightSwitch1); //cabin right
  porchLightSwitch2State = digitalRead(porchLightSwitch2); //cabin left
  porchLightSwitch3State = digitalRead(porchLightSwitch3); //galley
  //Serial.println(porchLightSwitch1State);

  // determine if any switch status has changed
  //  if (porchLightSwitch1State == porchLightSwitch1State_old )
  if (porchLightSwitch1State == porchLightSwitch1State_old &&
      porchLightSwitch2State == porchLightSwitch2State_old &&
      porchLightSwitch3State == porchLightSwitch3State_old)
  {
    // nothing changed
    //Serial.println("nothing changed");
    if (porchLightBrightness > 0)
    {
      // porch Light was on
      // update elapsed Time On
      porchLightElapsedTimeOn = millis() - porchLightTimeOn;
    }
  }
  else
  {
    // switch state changed. Which? Don't care.
    // update switchState_old
    // Serial.println("CHANGED");
    porchLightSwitch1State_old = porchLightSwitch1State;
    porchLightSwitch2State_old = porchLightSwitch2State;
    porchLightSwitch3State_old = porchLightSwitch3State;

    if (porchLightBrightness == 0)
    {
      // porch Light was off, turn on
      Serial.println("On");
      porchLightBrightness = 100;
      digitalWrite(porchLight, HIGH);
      porchLightTimeOn = millis();
      porchLightElapsedTimeOn = 0;
    }
    else
    {
      // porch Light was on, turn off
      Serial.println("off");
      porchLightBrightness = 0;
      digitalWrite(porchLight, LOW);
      porchLightTimeOn = 0;
      porchLightElapsedTimeOn = 0;
    }
  }
  // deal with battery SOC issues
}




I'd never used the code tag before. That's kinda cool.
I'll burn that bridge when I come to it.

Brad
ImageImageImage

Building the Bed & Breakfast
User avatar
capnTelescope
Lifetime member
 
Posts: 1218
Images: 368
Joined: Sun Jun 27, 2004 3:44 pm
Location: Round Rock, TX
Top

Re: TTT Microcontroller(s?) -- First working code

Postby Breytie » Wed Sep 02, 2015 9:11 am

Love the work!
I qualified as an electronic tech in 1984 on valves, discrete components built my own APPLE II rip-off from scratch.
Programmed MCS51 in assembler, even wrote a realtime OS in 4k eprom.
Last year sold my whole lab as I lost interest in the new way of doing electronics.
BUT I am watching with great interest.
How about a "All secure and ready to travel" check and a "something just opened while in motion" alarm using the door, window and hatch switches?
Activate the first test when charge power from the TV is applied (engine started, ready to roll) and the alarm if anything changes thereafter.

Keep it up and don't let the magic smoke out!

Andre
Experience is learning from your own mistakes
Here I make mine in public: My build
Breytie
Teardrop Master
 
Posts: 209
Images: 36
Joined: Sun Sep 04, 2011 4:21 pm
Top

Re: TTT Microcontroller(s?) -- First working code

Postby WoodSmith » Wed Sep 02, 2015 9:23 am

It seems like using momentary switches would be easier. All switches that control a given load would go to the same input. When the input changes (goes low when switch is closed) that controlled load toggles (or advances to the next) state. Assume standard debounce rules and so on...
Glen Smith
Build Journal
WoodSmith
Donating Member
 
Posts: 213
Images: 40
Joined: Tue Mar 29, 2005 11:07 pm
Location: RTP NC
Top

Re: TTT Microcontroller(s?) -- First working code

Postby capnTelescope » Wed Sep 02, 2015 10:35 am

Hey, Andre, thanks for your comments. It's good to have you aboard.

@TroubleScottie, Your last post showed up while I was composing the post that followed yours. I think it would answer many of your questions, but ask again if it didn't.

Breytie wrote:How about a "All secure and ready to travel" check and a "something just opened while in motion" alarm using the door, window and hatch switches?

Yes. I'd thought of that, too, but didn't remember to write it down.

Breytie wrote:Activate the first test when charge power from the TV is applied (engine started, ready to roll) and the alarm if anything changes thereafter.

I did provide myself with a signal wire to do just that. One thing that would do is just turn everything off. I don't need to be going down the road with my porch light on. :D That actually happened on my first time out. Had to re-arrange the wiring.

WoodSmith wrote:It seems like using momentary switches would be easier.

Probably so, except I already have the SPST switches in place. Also, I looked for suitable push button switches, and couldn't find any I liked. Touch sensors would be the cat's pajamas. :o

Breytie wrote:... discrete components built my own APPLE II rip-off from scratch.

That's one-up on me. I did build my first computer (SWTPC 6800) from a kit, soldering everything.

As a point of general interest, here's my Charging While Towing setup. It's different.

I've been working on getting a good framework together for the "final" product. I want the software to be data driven, rather than hard coding. Challenging to set up, but easy to maintain.

Thanks for stopping by! :beer:
I'll burn that bridge when I come to it.

Brad
ImageImageImage

Building the Bed & Breakfast
User avatar
capnTelescope
Lifetime member
 
Posts: 1218
Images: 368
Joined: Sun Jun 27, 2004 3:44 pm
Location: Round Rock, TX
Top

Re: TTT Microcontroller(s?) -- First working code

Postby tony.latham » Thu Sep 03, 2015 6:16 pm

Bro:

Controller? :thinking:

Hey, the wife does a lot of that stuff, but she claims I'm the camp control freak or at least she swears I do that kinda stuff. But I don't, I swear.

You're not gonna be adding anymore wires, is ya? :thinking: :pictures:

Tony
User avatar
tony.latham
Gold Donating Member
 
Posts: 6880
Images: 17
Joined: Mon Jul 08, 2013 4:03 pm
Location: Middle of Idaho on the edge of nowhere
Top

Re: TTT Microcontroller(s?) -- First working code

Postby capnTelescope » Thu Sep 03, 2015 11:30 pm

Bro,

That's what wives tend to do. S'truth. :thumbsup:

I have enough wires in there for now. Unless someone thinks up something I just gotta have, won't need any more. :D Just moving a few around.

OK, just a few little wires, maybe.
I'll burn that bridge when I come to it.

Brad
ImageImageImage

Building the Bed & Breakfast
User avatar
capnTelescope
Lifetime member
 
Posts: 1218
Images: 368
Joined: Sun Jun 27, 2004 3:44 pm
Location: Round Rock, TX
Top

Re: TTT Microcontroller(s?) -- First working code

Postby Madmike8 » Fri Sep 04, 2015 5:42 pm

Connect a esp8266 wifi module and gps. When it detects an open wifi network it joins it and sends an email with a GPS log. Useful incase your tear is stolen, or just keeping up with your trip. Solar and battery would be helpful too.
It's not about the Destination, It's all about the Ride!
Madmike8
Teardrop Advisor
 
Posts: 50
Joined: Wed Aug 29, 2012 10:17 pm
Top

Re: TTT Microcontroller(s?) -- First working code

Postby capnTelescope » Fri Sep 04, 2015 7:28 pm

Hi, MadMike, good to hear from you.

Thanks for the input. That helps clarify for me how the GPS-wifi thing would work. :thinking: Very interesting. We'll get some of the other things out of the way before I tackle that one. Have you done something like this before? I know how to log on to Gmail and send/receive mail from the keyboard, but I'm not sure if I could//how I would automate that process. Anyone here done that?

FWIW, I've been doing some research into how much things cost. GPS starts at about $40. So does WIFI.

I also ordered some IRF520 power MOSFETs for turning the lighting on/off. And a motor control kit from Jameco. It's to slow down my FanFan. The duino can do that without breaking a sweat. Then, given a remote or something, I'll also be able to reverse the FanFan and have like a ceiling fan! 8)

Exciting new code in the next post. :beer:
I'll burn that bridge when I come to it.

Brad
ImageImageImage

Building the Bed & Breakfast
User avatar
capnTelescope
Lifetime member
 
Posts: 1218
Images: 368
Joined: Sun Jun 27, 2004 3:44 pm
Location: Round Rock, TX
Top

Re: TTT Microcontroller(s?) -- Dimming the lights

Postby capnTelescope » Fri Sep 04, 2015 7:37 pm

As promised in the last post, there's new code to show off. :)

I've rewritten and enhanced the light switch sketch that I showed you before. I rewrote the code so I can handle similar devices using arrays, rather than writing a function for each individual device. The second thing I did is add code so that things can shut off or lights can dim after a set time.Without having to modify a lot of code, I can add other new devices by changing some data, instead of modifying code. We programmers (when I was a programmer) called this a data-driven program. In the code below, the data happens at the top of the listing before the setup() function.

In the loop() function, the program reads all the switch states, then processes each switched load item, one at a time.

The time-based powering down is what's called "Load Shedding." As in "my dog is shedding his winter coat." NOT as in putting into the shed in my backyard. "The dog was naughty, so I shedded him as punishment." I plan to refine this further when I have developed the ability to read the battery's state of charge.

Oh, yeah, almost forgot. Dimming the lights is done using PWM. Look for the analogWrite() calls. It's analogWrite( pin#, %on), where %on is completely on at 255, zero is off, and half on is 127.

Here's the code, so far:

Code: Select all
// define pins
/* switched loads
 *  0 = porch light
 *  1 = cabin light
 *  2 = galley work light
 *  3 = galley red light
 *  4 = running lights
 *  5 = backup lights
 *  6 = water pump
 ******  7 = USB charging port
 */

/* switch assignmenbts
 * 0 = porch cabin left
 * 1 = porch cabin right
 * 2 = porch galley
 * 3 = cabin left
 * 4 = cabin right
 * 5 = galley work
 * 6 = galley red
 * 7 = backup lights
 * 8 = running lights
 * 9 = water pump
 */
#define DEFswitchCount 10
#define DEFswitchedLoadCount 7


int switchCount = DEFswitchCount;
int switchPin[DEFswitchCount] = {23, 25, 27, 29, 31, 33, 35, 37, 39, 41};
int switchCountByLoad[DEFswitchedLoadCount] = {3, 2, 1, 1, 1, 1, 1};
// multiplr switches per load
int switch1PinIndex[DEFswitchedLoadCount] = {1, 4, 6, 7, 8, 9, 10};
int switch2PinIndex[DEFswitchedLoadCount] = {2, 5, 0, 0, 0, 0, 0};
int switch3PinIndex[DEFswitchedLoadCount] = {3, 0, 0, 0, 0, 0, 0};

// Switch properties
// New/old switch on-off states
int switchNewState[DEFswitchCount] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
int switchOldState[DEFswitchCount] = {0, 0, 0, 0, 0, 0, 0, 0, 0};

// ***** loads *****
int switchedLoadCount = DEFswitchedLoadCount;
int loadPin[DEFswitchedLoadCount] = {2, 3, 4, 5, 6, 7, 8};

// PercentOn at load shedding level
int loadPercentOn[DEFswitchedLoadCount] = {0, 0, 0, 0, 0, 0, 0}; // percent on now
// power level to run at by shedding level, 255 = 100%
int loadPercentOn1[DEFswitchedLoadCount] = {255, 255, 255, 127, 255, 255, 255}; // percent on to use at shed level 1.
int loadPercentOn2[DEFswitchedLoadCount] = {127, 127, 127, 127, 127, 127, 0}; // shed level 2
int loadPercentOn3[DEFswitchedLoadCount] = {32, 63, 63, 63, 63, 63, 0}; // shed level 3

unsigned long loadTimeOn[DEFswitchedLoadCount] = {0, 0, 0, 0, 0, 0, 0}; // device turned on at millis()
unsigned long loadElapsedTimeOn[DEFswitchedLoadCount] = {0, 0, 0, 0, 0, 0}; //calculated ET
int loadShedLevel[DEFswitchedLoadCount] = {1, 1, 1, 1, 1, 1, 1}; // current load shed level by load

// time at shedding level, millis
unsigned long loadShedTimeLevel1[DEFswitchedLoadCount] = {5000, 5000, 5000, 5000, 5000, 5000, 300000};
unsigned long loadShedTimeLevel2[DEFswitchedLoadCount] = {5000, 5000, 5000, 5000, 5000, 5000, 0};
unsigned long loadShedTimeLevel3[DEFswitchedLoadCount] = {5000, 5000, 5000, 5000, 5000, 5000, 0};


//======================================================================
void setup() {
  Serial.begin(9600);
  // init sensor switch assignments
  for (int i = 0; i < switchCount; i++) {
    pinMode( switchPin[i], INPUT);
  }
  // init load output pin assignments
  for (int i = 0; i < switchedLoadCount; i++) {
    pinMode( loadPin[i], OUTPUT);
  }
  // init switch states
  // this allows any switch configuration at startup and everything's off
  for ( int i = 0; i < switchCount; i++) {
    switchOldState[i] = digitalRead(switchPin[i]);
    switchNewState[i] = switchOldState[i];
  }
  // init battery info
  // init real time clock
}

//=====================================================================
void loop() {
  //Serial.write("!");
  // read status of all switches
  for ( int i = 0; i < switchCount; i++) {
    switchNewState[i] = digitalRead(switchPin[i]);
  }
  // service Loads with physical switches
  serviceSwitchedLoads();
}
//=====================================================================

void serviceSwitchedLoads() {
  //Serial.print(".");
  int switchIndex1;
  int switchIndex2;
  int switchIndex3;

  for ( int i = 0; i < switchedLoadCount; i++) {

    switch (switchCountByLoad[i]) {
      case 3:
        // load has 3 switches, get them
        //Serial.println("Case 3");
        switchIndex1 = switch1PinIndex[i];
        switchIndex2 = switch2PinIndex[i];
        switchIndex3 = switch3PinIndex[i];
        //        Serial.print(switchIndex1);
        //        Serial.print(switchIndex2);
        //        Serial.print(switchIndex3);

        //compare olds & news
        if (switchOldState[switchIndex1] == switchNewState[switchIndex1] &&
            switchOldState[switchIndex2] == switchNewState[switchIndex2] &&
            switchOldState[switchIndex3] == switchNewState[switchIndex3])
        {
          // no change, continue
          //Serial.println("no change");
          updateElapsedTime(i);
        }
        else
        {
          // switch state changed. Which? Don't care.
          // update switchState_old
          //Serial.println("change");
          switchOldState[switchIndex1] = switchNewState[switchIndex1];
          switchOldState[switchIndex2] = switchNewState[switchIndex2];
          switchOldState[switchIndex3] = switchNewState[switchIndex3];

          //----------------------
          if (loadPercentOn[i] > 0)
          {
            // load was on, turn off
            turnOffLoad(i);
          }
          else
          {
            // was off, turn on
            turnOnLoad(i);
          }
        }
        //Serial.print(switchOldState[switchIndex1]);
        //Serial.print(switchOldState[switchIndex2]);
        //Serial.println(switchOldState[switchIndex3]);
        //===============================
        break;
      case 2:
        // load has 2 switches
        //Serial.println("Case 2");
        break;
      case 1:
        // load has only one switch
        //Serial.println("Case 1");
        break;
      default:
        // error
        Serial.println("***ERROR*** Switch Case #1 defaulted in serviceSwitchedLoads.");
        break;
    }
    //delay(1000);

  }
}

void updateElapsedTime(int j)
{ if (loadPercentOn[j] > 0) {
    // load is on
    loadElapsedTimeOn[j] = millis() - loadTimeOn[j];
    Serial.print("ET: ");
    Serial.println(loadElapsedTimeOn[j]);
    setLoadShedLevel(j);
  }
}

void setLoadShedLevel(int k)
{
  if (loadShedLevel[k] == 3 && loadShedTimeLevel1[k] + loadShedTimeLevel2[k] + loadShedTimeLevel3[k] < loadElapsedTimeOn[k])
  {
    Serial.print("level 3 exhausted, time to turn off");
    turnOffLoad(k);
  }
  else if (loadShedLevel[k] == 2 && loadShedTimeLevel1[k] + loadShedTimeLevel2[k] < loadElapsedTimeOn[k])
  {
    Serial.println("level 2 exhausted, go to L3");
    loadShedLevel[k] = 3;
    analogWrite(loadPin[k], loadPercentOn3[k]);
  }
  else if (loadShedLevel[k] == 1 && loadShedTimeLevel1[k] < loadElapsedTimeOn[k])
  {
    Serial.println("level 1 exhausted, go to L2");
    loadShedLevel[k] = 2;
    analogWrite(loadPin[k], loadPercentOn2[k]);
  }
  else
  {
    // nothing to do
  }
}



void turnOffLoad(int j) {
  //Serial.println("turn off ");
  //delay(2000);
  loadPercentOn[j] = 0;
  analogWrite(loadPin[j], 0);
  loadTimeOn[j] = 0;
  loadElapsedTimeOn[j] = 0;
  loadShedLevel[j] = 1;

}

void turnOnLoad(int j) {
  //Serial.println("was off");
  loadPercentOn[j] = loadPercentOn1[j];
  digitalWrite(loadPin[j], loadPercentOn[j]);
  loadTimeOn[j] = millis();
  loadElapsedTimeOn[j] = 0;

}



Battery Monitoring
One of the things I need help finding is a way to measure current that the Arduino can read. Ideally from +/- 10 amps with resolution of 10 to 20 milliamps or better. Without having to design and build from scratch. Without spending gobs of money.

Such may not exist, If not, I can give up the fine resolution If I can find a way to monitor about 0-2 amps on an individual circuit. What I'm thinking about here is my USB charger, It drains roughly 20mA all the time, unless it's charging something, then it's more.

I might just go K.I.S.S. and get some 0.1 ohm resistors. Keeps the arithmetic easier.

Here's a quick vid of the time-based dimming. Full, half and 1/8 bright for 5 seconds each, then off. Watch the shiny red thing.


Thanks for stopping by. :beer:
I'll burn that bridge when I come to it.

Brad
ImageImageImage

Building the Bed & Breakfast
User avatar
capnTelescope
Lifetime member
 
Posts: 1218
Images: 368
Joined: Sun Jun 27, 2004 3:44 pm
Location: Round Rock, TX
Top

Re: TTT Microcontroller(s?) -- Dimming the lights

Postby troubleScottie » Sat Sep 05, 2015 9:11 pm

I did a lot of reading and saw there is the ability to make the switching process interrupt driven. That is to say, you can have the Arduino sleep -- using almost no power -- then when a switch is pressed, it generates an interrupt that wakes the Arduino and immediately checks which switch or switches were pressed.

Good advice here:

http://electronics.stackexchange.com/qu ... tton-input ( read Dan's response near the end )


It should work for toggle switch and push button and momentary switches. Each type is done slightly differently.

Again the bistable latch -relay/momentary switch is optimal for lowest power consumption. The latch - relay can be triggered with 3.3/5V. The switches are 3.3/5 V. The devices run on 12V or AC. Actually you might have to have a relay : the devices all need a higher voltage than the Arduino can handle.

The latch-relay is about $5 per device ( multiple switches could drive a device ). If your intention was to have master switches for every device anyway (my current design), given cost of switches and possible indicator lights and mounting brackets, the cost might be a wash.

If you are building with lots of switch and devices, you might need an IO expansion shield to allow for more IO pins. You would want ones that can be configured with pull up or down resisters and interrupts.



In thinking this design though, there are some really nice advantages.

(1) Each device/socket would be directly activated by a relay driven by the Arduino. This means every device could be selectively powered rather than having either everything on all the time or having to select multiple switches to turn on/off specific devices. You can wire everything separately eg home run for each reading lamp, dc outlet, etc and decide at the relay which devices share or do not share power. Nice if a particular outlet is really power hungry or one develops a short -- you can re-direct without having to rewire. A single switch can turn on multiple devices.

(2) No need for a big switch panel for master switches in the cabin, just the Arduino 3-4 inch touch screen and the big relatively speaking but hidden Arduino IO panel. ( Did I say add a touch screen?)

(3) One could remove some switches completely as the Arduino would be a switch panel. One might want a specific switch in the galley for water pump and heater, but no need for any additional switches in the cabin. Porch and cabin light switch would be good at the cabin doors -- but no need for switches for any other devices.

(4) Simpler switches. Since the Arduino is making the decisions and completing the circuit, no need for double throw switches or complex wiring patterns. One only needs low voltage momentary on switches. Home run connection to the switch and device means no solder connections to fail.

(5) One could build themed connection pools eg

* turn on/off the galley [lighting, dc power, AC power]
* power on/off all cabin lighting
* turn on external power outlets (DC and AC)
* turn on just external AC power
* power savings mode
* towing with or without frig
* power on/off everything
* shower with city water [heater only]
* turn on running lights/reverse lights (make flashers run?)
* charging stations [ cabin DC ]
* display switch for every device
* (too many???)

A single press and many devices are powered. Obviously devices could be in multiple connection pools. You could even disable switches eg power saving mode would not allow the water pump to be turned on. There is more programming for tracking which themed connection pools are active eg selecting tow mode would turn off almost all the devices and other connections pools OR turning off the heater would disable the shower mode. Adding or removing devices to the pools is easy.

(6) Adding more devices only requires open IO pins and connection to the device. No need to run additional wires for more switches.

(7) Mechanism for tracking/displaying what is powered without a continuous power draw ie LED indicators. Maybe a wifi connection to your phone???

(8) You have the controller to do other things -- power monitoring, GPS, alarms, backup camera, etc.

PS: I found a continuous liquid level indicator which could interface to the Arduino for cheap (<$50) compared to the $300 versions for RVs.
Michael Krolewski
Scottish Terrier Fancier
troubleScottie
Donating Member
 
Posts: 358
Images: 16
Joined: Sat Apr 11, 2015 5:02 am
Location: Seattle, WA
Top

Re: TTT Microcontroller(s?) -- Dimming the lights

Postby capnTelescope » Sun Sep 06, 2015 12:51 am

Hi, Michael.

Interesting info in the stackExchange forum. Thanks for the link. This got me off reading about how to put the duino to sleep and wake it up again. I will want to do that eventually. Actually, I think that just by getting the duino into the trailer and getting the lighting under control, I can "reduce my light bill" by about half.

With the 100Watt-hour battery, I know I have plenty of power for two nights camping without moving. I haven't stretched past that because there's been no way to know the SOC. Just reducing the power the lighting uses will be a much bigger saving than getting the processor to snooze. Should get another night or two. That's going to be plenty.

I want to have the core part of the system installed and working by mid-late October, so I can take it to LCG. This project can run as long as we can all stand it, but the core functionality needs to get in there soon-ish. Fortunately, software is easy to change, and the driver board I have in mind would probably work without needing modification, since it will be taking care of outputs.

You've got some good ideas. Keep them coming. Maybe I can even inspire you to prototype your ideas and prove them out. ;) I'm just doing what I know will work, and I don't know all that much. :NC
I'll burn that bridge when I come to it.

Brad
ImageImageImage

Building the Bed & Breakfast
User avatar
capnTelescope
Lifetime member
 
Posts: 1218
Images: 368
Joined: Sun Jun 27, 2004 3:44 pm
Location: Round Rock, TX
Top

PreviousNext

Return to Electrical Secrets

Who is online

Users browsing this forum: No registered users and 10 guests