How to combine two Arduino sketches
I have two Arduino sketches for two sensors. How to combine two different Arduino sketches to one complete sketch?
Suppose that you have two Arduino code as below
Arduino sketch 1
Arduino sketch 2
How to combine two above sketches
- In both sketches, use millis() instead of delay()
- Make sure that two sketches do not conflict to each other in using Arduino pin. If conflicted, change the pin in a sketch
- Make sure that variable name or user-defined functions in both sketches are not the same. If both sketches have the same variable name or user-defined function, rename the variable name or user-defined function to make it different
- Merge two sketches. code will merge as below
※ NOTE THAT:
The combined code might not works. You may need to make more modification based on the combined code.
|1 × Arduino UNO Buy on Amazon
|1 × USB 2.0 cable type A/B Buy on Amazon
|1 × Jumper Wires Buy on Amazon