Can I do multiple (unrelated) things with my Arduino Uno?
For example, can I regulate and display the temperature in my beer fridge and turn on/off my desk lamp off the same unit?
I made it through about 4 lessons in the starter kit, but I've kind of put my arduino down for a bit because I didn't have any real world problems that needed solving. Now I have 2. The thermostat display went out on my beer fridge and the stock one is rather crummy anyway, and I'd like to use a photosensor to turn my desk lamp on and off. I just have the one board, but the fridge is about 8 feet away from the lamp, so I thought I may be able to kill 2 birds with one Uno.
Am I over- or under-simplifying this? It looks like the Uno is about $25 US, and I would imagine sensors & display would cost at least that much, so should I just build the one, then build the other?
Thanks.
Edit: Thanks for all the responses, folks. They got over my head pretty quickly, though. I guess I have a little more reading and tinkering to do.
Posted Jul 10, 2014, 11:08 AM UTC · edited
The short answer is, yes - if you write your program properly.
Design your code so that the two functions that you want your Arduino to perform, each has their own neatly segregated routine that can run side by side without interfering with the other. So they have to be good neighbors. That means they can not use delay() which just makes everything (including the other process) grind to a halt. Define a time regimen for how often each of the two functions are run (once a second? 100 times a second?) and have for your main loop a simple scheduler function looking at millis() and comparing with timestamps to determine when to run each of the two (or more) functions you want to run side by side.
edit: To avoid variable names belonging to each process from "stepping on each other" , you can organize the data that each process type uses, into a struct. Structs are like records or data cards; for example, you could for your thermostat function store the high and low threshold set temperatures in a struct you can call ThermostatSetting. It could also contain a reference to the IO pins that the process uses. Then if for whatever reason you want to add more things to be temperature controlled, you can reuse the thermostat function and just call it with the different structs pertaining to each controlled thermostat. The same goes for lights. And anything else. The 16MHz Atmel CPU is plenty powerful to run basic home automation for a whole house.