Basic Introduction to Arduino –(1)


What is the Arduino

Arduino is a convenient and flexible open source electronic prototype platform, including hardware (Arduino board of various types) and software (Arduino IDE). It’s for artists, designers, and people who are interested in “interaction.” Of course, if you want, you can do all kinds of electrical Internet of things 😁😁😁


directory

  1. The installation
  2. Basic parts
  3. hello world
  4. summary


1, install,

The Arduino consists of two parts

Hardware:

This is an Arduino Uno board on which the rest of the series will be based. Detailed illustration:

Software: Arduino IDE

Arduino programming is done via Arduino programming language (based on Wiring) and Arduino development environment (based on Processing).

The official Arduino programming language learning websitewww.arduino.cc/reference/e… Of course, the official IDE will be more basic, later you can search for how to use a third-party IDE for development, here will not be introduced

Official IDE download address: www.arduino.cc/en/software…


2. Basic accessories

The bread version:

A convenient circuit board, according to the need to insert or pull out components, without welding. The upper and lower are connected with a positive and negative power supply area, the middle is the component area, vertical 5 unicom with each other, not unicom;

Resistance:

We are all nine years of compulsory education, what is the role of resistance will not be introduced. The figure below is the color ring resistance. The resistance value can be distinguished according to the packaging of different color rings on the ordinary resistance. Generally, there are four rings and five rings.

Color ring resistance card:

The resistance of the four rings, the first and second rings represent numbers, the third ring represents multiple, and the fourth ring represents error; The resistance of the fifth ring, the first ring, the second ring, the third ring represents the number, the fourth ring represents the multiple, the fifth ring represents the error;

Jump line:

The circuit and the wire that connects the Arduino board on the bread plate are basically wires

Led lights:

Various colors of the lamp, the two pins of the lamp will have long feet, long feet connected to the positive pole, short feet connected to the negative pole

RGB lamp:

There are LED lights, of course, there are RGB lights. RGB light is different from LED light, it has four legs, respectively corresponding to B G +(positive) R, the longest pin is still connected to the positive, the other is connected to different output pins

3, hello world

As we all know, no matter what language or technology you learn, the first project should be a Hello World.

void setup() {
  Serial.begin(9600);
}

void loop() {
   Serial.print("Hello World");
}

Copy the code

Then connect the Arduino Uno board to the computer and run it. After opening the serial detector, you can see it. Then we will get an Led water lamp to start our Arduino learning road. The component list is:

  • Arduino uno board
  • Bread version
  • Led lights
  • 1 k resistor
  • Jump line

Then connect the circuit like this

Then open the IDE and start coding

Void setup() {// Set the pins of the led interface to OUTPUT mode pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); pinMode(7, OUTPUT); pinMode(8, OUTPUT); pinMode(9, OUTPUT); } void loop() {// start a new loop // connect 2 pin LED light digitalWrite(2, HIGH); // Hold half-second delay(500); DigitalWrite (2, LOW); digitalWrite(2, LOW); // Connect pin 3 LED light digitalWrite(3, HiGH); . DigitalWrite (8, LOW); // Hold half-second delay(500); // Connect pin 9 LED light digitalWrite(9, LOW); }Copy the code

And then we can have one light going on and one light going off and the next light going on, but that’s too much code, so we can change it, and then we can change it again

void setup() { for(int i = 2; i < 10; i++){ pinMode(i, OUTPUT); digitalWrite(i, LOW); } } void loop() { for(int i = 9; i > 1; I --){// Extinguish the LED digitalWrite(I, LOW) connected to pin I in this loop; // wait 0.1sec delay(100); } for(int I = 2; i < 10; I ++){// Immediately on digitalWrite(I, HIGH); // light 0.1sec delay(100); } // Enter the next loop}Copy the code

The end result is this:

This time we use ==pinMode==, ==delay==, ==digitalWrite==

PinMode (pin, mode)

The first parameter is pin, and the second parameter is output or input or output mode. Before using the input or output function, you need to set the pinMode to input or output mode using the pinMode() function.

delay(time)

How long to wait before executing down

DigitalWrite (Pin, value)

Parameter pin specifies the pin number of the output; The value argument is the level you want to specify for the output; HIGH specifies the output HIGH level, or LOW specifies the output LOW level. This function is used to power on or off a pin;


4, summary

As we learn more and more Arduino, what we can do will become more and more interesting. Let’s continue to learn together and make some more interesting things. Some of the pictures are from the Internet

Basic Introduction to Arduino –(1)

Wechat search public number: DigitMagic magic laboratory