-
If you will be using an Arduino, tell us what components you have.
-
If you are going to be using a raspberry pi, ask for help on that forum.
Suggestions of things you need to master
Ask questions as they come up
-
Always start a project with a circuit schematic showing all the components and their interconnections.
-
Code “must” be written in a non blocking fashion.
-
To keep code organized and easy to follow, the State Machine technique needs to be adhered to.
-
Using HIGH or LOW does not explain what is happening, use names like: LEDon, RELAYon, ENABLED, CLOSED etc.
-
Avoid magic numbers. Use names that describe the value.
unsigned long oneSecond = 1000; // 1000 ms in one second
unsigned long oneMinute = 60 * oneSecond;
unsigned long oneHour = 60 * oneMinute;
unsigned long oneDay = 24 * oneHour;
-
Let the compiler do the math for you, for 15 minutes, instead of 900000 use: 15ul * oneMinute
-
Keep version backups so you can always go back to the last working version.
-
Do not use delay(…) as it will stop code execution during this delay interval.
-
Avoid using while( ) if there is any chance it significantly blocks normal code execution.
-
Use non blocking TIMERs based on the millis() or micros() functions.
-
Write your code in a neat easy to read style, use white space, add meaningful comments throughout.
-
Use the Arduino onboard LED on pin 13 as a heartbeat LED to show code is running and code is not stuttering.
-
For mechanical switches avoid looking at digital input levels, instead, look at digital input “changes in state”.
-
For readability, place { and } on separate lines by themselves, place each line of code on a separate line.
-
LEDs displaying the current state in a State Machine, can be used to diagnose problems.
-
For diagnosing problems, use serial monitor print statements to confirm variables are what you think they are.
-
Write only small blocks of code at a time. Prove the new code block works 100% before proceeding.
-
The way you learn how to write software is by writing software.
Make this commitment to yourself.
- Before wiring and turning on the power to a circuit, I will always draw a schematic showing how I will connect the components in my project; this schematic is exactly how I will wire things.
- I will double check that power connections are correct.
- I will always use a series resistor of 220Ω on both Inputs and Outputs to protect my controller’s GPIO pins from my blunders.
- I will never re-wire a circuit when power is applied.
We can help you in your journey when you need explanation on things you do not understand.