The original link: www.shuaihuajun.com/article/ard…

I have a Ruff kit and an Arduino kit. After going through all the sensors in the Ruff development kit and not getting enough of them, I started playing Arduino. No comparison means no harm. It is true that although I have not been in contact with Arduino for a long time, in my opinion, Arduino is more low-level and flexible than Ruff in terms of program and hardware. Arduino is more valuable for learning and research in the long run. So abandon Ruff and embrace Arduino.

But Ruff’s JavaScript programming to control hardware really got me interested in the big world of the Internet of Things. Ruff is better for rapid prototyping, but it doesn’t make it into production, which doesn’t satisfy my curiosity about the lower levels of the iot world. So goodbye, Ruff. Hello, Arduino.

Arduino IDE

The Arduino IDE integrated development environment interface

The Arduino integrated development environment supports syntax checking, uploading programs to the development board, and serial port monitors, which are the three most commonly used features.

An Arduino program needs to include a setup function, which is executed repeatedly during the program, and a loop function, which is executed only once when the program starts to run. Learning is a repetitive process.

Creative idea

No matter what you do, you should always have a general outline in your mind before you start. Although you will have new ideas during the actual operation, it is good to have an idea at the beginning.

Since it is a beginner Arduino, the purpose is simple, that is, to light up an LED light. When you successfully light up an LED, you can try to light up a row of LED lights and make these LED lights into a symbol. It is also good to keep flashing, or turn on and off one by one.

Start by drawing a circuit in your head.

For me such a beginner of the small white, still can remember the middle school physics circuit knowledge, is also very worthy of encouragement. If I’m not mistaken, the situation in the figure above is called a parallel circuit. The reason for adding a 220 ohms resistor is that the LED cannot withstand too much current.

The Arduino development board can be regarded as a battery. I set the mode of pin 8 as the output, which can be regarded as the positive pole of the battery. The LED lights are connected in parallel and collected to the negative ground pin of the Arduino.

I first had a general idea in my mind, and then I played with the circuit and thought about it at night, because when I connected the circuit, I kept trying to find out how to connect the circuit to make it more beautiful. Finally, the circuit was connected like this, and the LED light was finally turned on.

In my opinion, the process of learning should be to understand and digest what the predecessors have summarized, and then memorize and absorb it after truly understanding. Then, you should constantly imitate and repeat, innovate again, and finally summarize and share the innovation, waiting for the understanding of those who recognize the value you have created. Innovation is hard, and it is not easy to imitate and repeat.

My learning process

Assemble the circuit

As you try to figure out how to connect the circuits based on what you imagine in your head, you improve and refine your previous ideas.

A set of LED lights are plugged into the breadboard and dupont wire is connected to the Arduino development board and the computer is connected to the programming wire

After wiring up the circuit, it’s time to program. PinMode (8, OUTPUT) function is used to take pin 8 as the OUTPUT port of the level, which is the positive pole. The level of pin 8 is constantly changed in the loop function.

Write a program

Because the circuit has only on and off states, either on or off, the second argument to digitalWrite() has only medium possibilities, either HIGH or LOW. When executing digitalWrite(8, HIGH), there is a voltage generated in the circuit, so there is a moving current, the current flows from the LED anode to the cathode, and the LED will emit light; When digitalWrite(8, LOW) is executed, the power is off, there is no voltage in the circuit, there is no moving current, and the LED lamp will not turn on.

int led = 8;

void setup() {// Write the initial configuration here, execute only once: pinMode(led, OUTPUT); } voidloop() {// digitalWrite(led, HIGH); delay(500); digitalWrite(led, LOW); delay(500); }Copy the code

After digitalWrite(8, HIGH) is executed, the circuit is powered on, and the LED lights up. At this time, the main program will pause for 500 milliseconds when the delay(500) function is executed, and the LED lights up for 500 milliseconds. Then digitalWrite(8, LOW) is executed, and the LED is off, and the main program will pause for 500 milliseconds. At this point, the end of one cycle, immediately into the next cycle.

I watched a row of LED lights on the bread board go on and off every second.

I also found that if the LED lights are connected in series, each LED emits very weak light, and when the LED lights are connected in parallel, each LED emits the same light and is very bright.