Float sensors, 1 relay and 12v 2a valve.

Can anyone out there suggest what the smallest micro controller I can use to accomplish the below?

I've built a dual water level relay system using two "ZP4510 Liquid Water Level Sensor Vertical Float Switches" (one on the bottom of my reservoir and one made height's adjustable at the top) that triggers the on / off state of a single relay. From the relay (NC of course), I turn on/off (open/close) a 3/4" electric water valve supplying water to said reservoir. This allows my reservoir to now be smart and not just turn itself off from filling once reached desired fill point (something a float arm could do), but now will also wait to start filling itself up with fresh water till all the water is all used up. GREAT!

However, I'm using an extra ArduinoMega 2560 I had laying around to get this prototype up and going, and now I would like to shrink this guy down. I understand the idea of "if it aint broken don't fix it", but everyone knows using a 2650 for this is like using a nuke on an ant hill.

The application is not too complex, seems to require only a few pins, and you have already got a working prototype.
I guess that it is not going to be a battery optimised application.
My suggestion would probably be a Nano which you can program/power directly through the usb connection.
Post your code and you may get other suggestions.

Doh, guess the code would be helpful :slight_smile:
It's a very simple code snip to operate turns out, no libs just pin setup and two if else:

const byte bottom = 6;
const byte top = 7;
const byte relay = 22;
void setup ()
  Serial.begin (9600);
  pinMode (bottom, INPUT);
  pinMode (top, INPUT);
  pinMode(relay, OUTPUT);
}  // end of setup

void loop ()
    if (digitalRead (top) == LOW && digitalRead (bottom) == HIGH)
         Serial.println ("Top closed.");
         digitalWrite(relay, LOW);  
    if (digitalRead (top) == HIGH && digitalRead (bottom) == LOW){
          Serial.println("Top open.");
          digitalWrite(relay, HIGH);  
  }  // end of loop

Correct, hoping to use 12v 3a power adapter to supply power to controller and valve from relay in one. No concerns if power is lost as water valve is normally close with no juice of course.

Thanks for the Nano suggestion I just checked it out. Looks like it only has a single 5v power out and it was my understanding that each float sensor needs to have its own 5V and GND to work properly. I could be wrong about that though, might just be ground to pin that needs to be unique and can both share same 5V?

Last question is the USB power source, how does one normally supply external power to the Nano from a power adapter into the USB plug? Kinda confused about that part.

Ah found this:

Going to try and see what happens with single 5v source on sensors on prototype, and if all works grab the nano.

Thanks again!

OK. You can also power the Nano from your 12 volt supply using the Vin pin. This might be more useful to you than using the USB power option.
Those floats look like simple switches at the electrical level. On wire would be connected to ground (which should anyway be common to all your devices). The other wire would go to the pin on the Nano which you dedicate to it (one pin per float).

Ah, good to know about the VIN pin, thank you!
Sorry for the confusion about the ground on the switches (yes they are switches),but I found this link:

here on another board where someone was asking about these exact float switch hookups (IRC) and someone pointed out that using 10k resistors from grounds to switch pin wires vs direct hookup to pins. Maybe I can still use 1 ground and run two 10k resistors from single ground out to the two wires.

I can confirm single 5v for both switches works btw so that's good!

The 10k resistors are to ensure that the when there is an open circuit (ie when the switches are not operating) the pins are not ‘floating’ and vulnerable to stray electrical effects.
You can also solve this problem by using the inbuilt pullup resistors on the Arduino pins if you wire your device (floats) between ground and the Arduino pin. You then have in your code:

pinMode (bottom, INPUT_PULLUP);

This means that a digitalRead returns HIGH if the switch is open and LOW if the switch is closed.

You may have another issue of de-bouncing. If the water moving about a lot, the floats may be switching on and off continuously when near their trigger point. You may want to build in some timing element into your code to smooth that out.

Thank you for all the info (including the recent follow up)!
I was able to get everything working perfectly with the nano and wanted to post my results: