Hi!
I must preface that i don't know a lot about programming, Arduinos and such. I'm just getting interested in this sort of things for the first time!
What i'm trying to build (Just as a creative hobby) is a simple device, composed of a small red LED and a button, which:
By default, it starts with the LED on
When i press the button, the LED turns off, and the device starts an internal one-week timer
If at least a week has passed since the last time i've pressed the button, then it turns the LED back on.
Again, it's nothing incredible. The reason i would like to do this is that I have a lot of plants around the house, each requiring a different watering schedule (Once a week, once a month, once every two weeks..), and i thought that assigning a LED light to each one, telling me if it needs to be watered, would ease the process of remembering the schedule for each.
I know that this is probably not the easiest/cheapest way to do this, and i could probably set something analogous up entirely on my phone with some kind of reminder app, but i thought that this would be a fun little project to get started with small-scale programming and Arduinos, which is something that i am interested in.
As i have different plants with different watering schedules, perhaps this could also be 'scaled up' to contain different LEDs and different buttons, each for a different plant, but i would be content if i were able to just start with the one.
I'm of course looking into how to do this myself, but i would much appreciate any inputs anyone might have! As stated, i have 0 experience with this
Have you examined Arduino moisture sensors? Why a week if it's not a week that's needed, but the moisture level in the soil?
That's what makes Arduino so cool: pretty much any real world scenario you can imagine, there is an input sensor out there for only a few dollars that will allow you to interact with the real world problem, in this case, your having a device that reminds you to water your plants when they're thirsty.
Some of these plants are.. algae. Which means that, instead of being planted in soil, each one is in a jar full of water, and instead of watering them, i need to switch out the water every few days!
Thanks for the reply!
So far i haven't really tried anything!
I've watched a few tutorials on Arduino on YouTube, the absolute basics
I was thinking that i would start with a single LED with a single Arduino for a single plant, just to get started with things, learning the ropes a bit, and then maybe expand the project to multiple LEDs, each with a different timer, but still connected to a single Arduino, so as to minimize the cost (?).
One thing that i'm trying to understand is the cheapest Arduino model that would be capable of achieving the end goal - i wouldn't want to purchase a Ferrari just to drive around my house!
Welcome, interesting little project for a beginner, one which presents several possibilities.
You can do as @arduinor3broken suggests and use delay, which is quick and simple but which you will quickly realise means that once the timer starts then nothing else happens for 7 days or however long the time runs for, meaning you can only have one timer per Arduino. Given that one Arduino is more than capable of running lots of timers I suggest using delay is good to get you started, but you will need to move on to something better pretty quickly.
Using millis will allow multiple timers on the same Arduino, and each timer can be made to work independently of the others, here is a tutorial to get you started:
As to which Arduino board you use, any are capable of doing what you want. The Uno is the original beginner's board, but is not breadboard friendly.
The Nano is a breadboard friendly version of the Uno:
And the Nano Every is similar in some ways but is actually based around a completely different processor. I prefer it because it has a spare hardware serial port, possibly not required for your project but useful for some projects:
Once you have a working project, and you'd like a sensor for each plant, you could go to something like
$7
Since you need only one input and one output this small package would suffice. You should also look into power saving techniques if this will be a battery powered application.
Nice idea for a first project. But you should continue getting your feet wet (see what I did there?) with small steps maybe nothing to do with the actual goal.
A processor and LED and button per plant would make it easy, but maybe spendy. If the LEDs and buttons don't have to be physical distant one set to the next, one Arduino board will be able to do quite a few pairs.
I suggest getting the sketch you wrote going. Of course for testing set the delay to something like 7 seconds, and test that nothing breaks for longer delays.
You will see us perhaps wanting to make this larger; for now try to avoid mission creep. Pick attainable goals and deploy something, then revisit for version 2. And 3. I won't even say the kind of places ppl take these little projects.
On behalf of your algae (!), however, I would like the device to power up or reset with an indication it was a new world, say another LED that is on only at that time, and goes off and stays off for the rest of eternity once you hit the "I did it" button.
Unless the power fails and you might not have noticed - all copies of the device, or the one multichannel device would show that power had been lost, and the timing lost.
if you are cheap or a sedentary type, this project's software can be fully developed without leaving your chair or spending and money.
Check out this simulator, not too much harder than coming to grips with the IDE, and certainly easier than fiddling with breadboxes and wires and components and so forth.
So far, i've put together this simulation (With some strong help from ChatGPT for the coding part): Wowki Simulation
The simulation has a single button, a single LED, and a much smaller timer (5 seconds) for testing purposes.
Problem is, this doesn't work as intended...
The expected behavior, to recap, is that, when i run the simulation:
The LED starts on by default
Once i press the button, the LED turns off, and the time of pressing is recorded
After 5 seconds, the LED turns back on, and stays on until i press the button again.
What happens instead, for reasons unknown, is that:
The LED starts on by default
It stays on for a very brief time, then it turns itself off
The button does not seem to affect the LED behavior in any way.
I have been trying to debug this for a while, but nothing seems to be working.
Again, i learned what a breadboard and resistors and pins are literally yesterday, so i expect this to be a very basic problem
In your code you have configured the button pin using:
pinMode(buttonPin, INPUT_PULLUP);
However on the breadboard you have also fitted a pull down resistor to the button input pin.
The pull up and pull down resistors are fighting each other to determine the pin's state.
I don't know how the simulator deals with this issue, as the internal pullup resistor is not a fixed value but lies within a range of values.
My guess is that the simulator thinks the button input is always HIGH.
I suggest that you either change the button pin to be an INPUT (without the pull up), or remove the pull down resistor on the breadboard, and rewire the push button so it pulls the input low. (You would need to change the code to check for the button pin going low, if you took the second option)
Your circuit shows LED connected to D2, D7 and D8. Also, there doesn't seem to be any power going to the Arduino. The 5V pin is 5 volts out, the VIN pin is to give power to the Arduino. Without power in, you can't send power out.
Would the LED being connected to D7 and D8 be a functional problem or one of tidyness, given that they are (for now) unassigned? I assumed that any unassigned pins wouldn't affect the operation either way.
Also, there doesn't seem to be any power going to the Arduino. The 5V pin is 5 volts out, the VIN pin is to give power to the Arduino. Without power in, you can't send power out.
This makes perfect sense, which makes me all the more confused as to why it now works after @JohnLincoln 's suggestion to change the code