Cours en ligne Arduino basé sur un kit de démarrage simple

À l'heure actuelle, il existe un grand nombre de programmes éducatifs, de cours et de matériel pédagogique en ligne et hors ligne sur l'arduino, et la qualité de ces cours est au premier plan et ne répond pas toujours aux attentes des élèves et de leurs parents. Les cours en ligne sont généralement inefficaces en raison de leur faible interactivité. Et l'efficacité des cours hors ligne dépend fortement des qualifications de l'enseignant, avec qui il y a parfois des problèmes en raison de la relative nouveauté de ce domaine par rapport aux autres disciplines scolaires. Ce cours est destiné à résoudre partiellement ces deux problèmes. D'une part, il devrait être plus efficace que les cours en ligne existants en raison d'une forte augmentation de l'interactivité, qui sera discutée plus en détail ci-dessous. D'autre part, l'augmentation de l'efficacité du cours lui-même réduit légèrement le rôle de l'enseignant,vous permettant d'utiliser ces cours interactifs dans les régions avec une pénurie de personnel dans le domaine de l'enseignement de l'arduino.



Partie 1. Méthodologie.

Commençons donc par ce qu'est l'interactivité, pourquoi est-elle importante et comment est-elle réalisée dans le cadre de ce cours.
Une méthode d'enseignement inactive implique l'interaction des élèves non seulement avec l'enseignant, mais aussi entre eux. Vous pouvez en savoir plus sur Wikipedia.L'importance
de l'utilisation de la méthode interactive est qu'elle est plus efficace que la méthode passive de formation. Ce fait est universellement reconnu, tout comme le fait qu'une augmentation de l'interactivité augmente également l'efficacité du processus éducatif. Vous pouvez en savoir plus à ce sujet.
ici.
, , , , .



, , , .



La communication entre l'enseignant et l'étudiant ainsi qu'entre les étudiants dans le cadre de ce cours est mise en place grâce à la fonctionnalité de deux réseaux sociaux: Vkontakte et Youtube. Dans les deux réseaux sociaux, il est possible de mener une conversation publique, d'envoyer des messages privés et de recevoir des notifications sur la réponse à une question d'intérêt.
Pourquoi exactement ces deux réseaux sociaux
, Youtube , Facebook, Instagram . .


: TNS

Partie 2. Structure du cours.

Ce cours est conçu pour une année académique, se compose de 40 leçons (une leçon par semaine).
Dans la première moitié du cours (20 leçons), des connaissances générales sont données sur la plate-forme Arduino, ses fonctions, ses capacités, des exemples simples et les principes de son travail sont analysés. Des exemples de travail avec des périphériques (capteurs, systèmes d'information d'entrée et de sortie, actionneurs) sont également donnés. Il est important que pour compléter les 20 premières leçons, un kit de démarrage arduino soit suffisant , qui peut être acheté dans n'importe quelle boutique en ligne chinoise sans payer trop cher pour la marque sur l'emballage.

Chaque leçon du cours est basée sur une leçon vidéo, contient une brève description textuelle de la leçon, tous les schémas et croquis nécessaires. Si vous rencontrez des difficultés pendant le devoir, nous vous suggérons de contacter l'auteur de la leçon vidéo dans les commentaires de la vidéo, ou d'y trouver la bonne réponse si la question a été soulevée plus tôt par d'autres élèves. Il y a toujours la possibilité de demander à d'autres étudiants qui ont laissé des commentaires sur la vidéo plus tôt. Youtube est mieux adapté à cela, mais vous pouvez également utiliser Vk, ajusté du fait que l'accès direct à l'auteur d'un didacticiel vidéo dans Vk peut être limité.



Dans la seconde moitié du cours(classes 21 à 40) l'accent est mis sur les travaux de conception. Les cours sont également basés sur des didacticiels vidéo. Au début de la leçon, vous trouverez une liste des matériaux, pièces et équipements nécessaires en plus du kit de démarrage Arduino. La partie introductive est terminée, allez directement au cours.

Cours Arduino interactif

1. Connaissance de l'arduino (cliquez pour agrandir)
?



. ? .
. , ( , , -)


:





/*
Jeremy's First Program
It's awesome!
*/

int ledPin = 13;

void setup()
{
//initialize pins as outputs
pinMode(ledPin, OUTPUT);
}

void loop()
{
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}

/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.

This example code is in the public domain.
*/

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
:


:

. .

2. Bouton et PWM (PWM)
, , . . . PWM ().


1
/*
Arduino Tutorials
Episode 2
Switch1 Program
Written by: Jeremy Blum
*/

int switchPin = 8;
int ledPin = 13;

void setup()
{
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
}

void loop()
{
if (digitalRead(switchPin) == HIGH)
{
digitalWrite(ledPin, HIGH);
}
else
{
digitalWrite(ledPin, LOW);
}
}

2
/*
Arduino Tutorials
Episode 2
Switch Program
Written by: Jeremy Blum
*/

int switchPin = 8;
int ledPin = 13;
boolean lastButton = LOW;
boolean ledOn = false;

void setup()
{
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
}

void loop()
{
if (digitalRead(switchPin) == HIGH && lastButton == LOW)
{
ledOn = !ledOn;
lastButton = HIGH;
}
else
{
//lastButton = LOW;
lastButton = digitalRead(switchPin);
}

digitalWrite(ledPin, ledOn);

}

3
/*
Arduino Tutorials
Episode 2
Switch3 Program (debounced)
Written by: Jeremy Blum
*/

int switchPin = 8;
int ledPin = 13;
boolean lastButton = LOW;
boolean currentButton = LOW;
boolean ledOn = false;

void setup()
{
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
}

boolean debounce(boolean last)
{
boolean current = digitalRead(switchPin);
if (last != current)
{
delay(5);
current = digitalRead(switchPin);
}
return current;
}

void loop()
{
currentButton = debounce(lastButton);
if (lastButton == LOW && currentButton == HIGH)
{
ledOn = !ledOn;
}
lastButton = currentButton;

digitalWrite(ledPin, ledOn);

}

4
/*
Arduino Tutorials
Episode 3
Switch4 Program (pwm)
Written by: Jeremy Blum
*/

int switchPin = 8;
int ledPin = 11;
boolean lastButton = LOW;
boolean currentButton = LOW;
int ledLevel = 0;

void setup()
{
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
}

boolean debounce(boolean last)
{
boolean current = digitalRead(switchPin);
if (last != current)
{
delay(5);
current = digitalRead(switchPin);
}
return current;
}

void loop()
{
currentButton = debounce(lastButton);
if (lastButton == LOW && currentButton == HIGH)
{
ledLevel = ledLevel + 51;
}
lastButton = currentButton;

if (ledLevel > 255) ledLevel = 0;
analogWrite(ledPin, ledLevel);

}

:




.
:


3. Le potentiomètre. Fondamentaux des circuits
: , , , , , Arduino


1
//Reads the State of a Button and displays it on the screen

int buttonPin = 8;

void setup()
{
//sets the button pin as an input
pinMode(buttonPin, INPUT);

//Allows us to listen to serial communications from the arduino
Serial.begin(9600);
}

void loop()
{
// print the button state to a serial terminal
Serial.println(digitalRead(buttonPin));
delay(1000);
//wait one second, then print again.
}

2
//Reads the State of a Pot and displays on screen

int potPin = 0;

void setup()
{
//sets the button pin as an input
pinMode(potPin, INPUT);

//Allows us to listen to serial communications from the arduino
Serial.begin(9600);
}

void loop()
{
// print the button state to a serial terminal
Serial.println(analogRead(potPin));
delay(1000);
//wait one second, then print again.
}

. , . ? : (7-14 ), 5 ( HIGH). , .
: :


4. Capteur de lumière
Arduino, . .

int sensePin =0;
int ledPin =3;

void setup()
{
pinMode(ledPin, OUTPUT);
}

void loop() {
int val = analogRead(sensePin);

val = constrain(val, 750, 900);
int ledLevel = map(val, 750, 900, 255, 0);

analogWrite(ledPin, ledLevel);
}

:

:

:

.

5. LED RGB

const int RED_PIN = 9;
const int GREEN_PIN = 10;
const int BLUE_PIN = 11;

void setup()
{
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
}

void loop()
{
mainColors();
showSpectrum();
}

void mainColors()
{
digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, LOW);

delay(1000);

digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, LOW);

delay(1000);

digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, LOW);

delay(1000);

digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, HIGH);

delay(1000);

digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, LOW);

delay(1000);

digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, HIGH);

delay(1000);

digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, HIGH);

delay(1000);

digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, HIGH);

delay(1000);
}

void showSpectrum()
{
int x;
for (x = 0; x < 768; x++)
{
showRGB(x);
delay(10);
}
}

void showRGB(int color)
{
int redIntensity;
int greenIntensity;
int blueIntensity;

if (color <= 255)
{
redIntensity = 255 — color;
greenIntensity = color;
blueIntensity = 0;
}
else if (color <= 511)
{
redIntensity = 0;
greenIntensity = 255 — (color — 256);
blueIntensity = (color — 256);
}
else // color >= 512
{
redIntensity = (color — 512);
greenIntensity = 0;
blueIntensity = 255 — (color — 512);
}
analogWrite(RED_PIN, redIntensity);
analogWrite(BLUE_PIN, blueIntensity);
analogWrite(GREEN_PIN, greenIntensity);
}

:

:



6. Servo, bibliothèques

//
#include <Servo.h>
// — arduino.cc/en/Reference/Servo

Servo servo1; // №1

void setup()
{
servo1.attach(9); // 9
//servo1.detach()
}

void loop()
{
int position; // ,

// :

servo1.write(90); // 90 .
delay(1000); //
servo1.write(180); // 180 .
delay(1000); //
servo1.write(0); // 0 .
delay(1000); //

// :
// 0 180 2

for(position = 0; position < 180; position += 2)
{
servo1.write(position); //
delay(20); //
}

// 180 0 1

for(position = 180; position >= 0; position -= 1)
{
servo1.write(position); //
delay(20); //
}
}

:

:



7. Récepteur IR

#include «IRremote.h»

// 0
const int IR_PIN = A0;

//
IRrecv irrecv(IR_PIN);
void setup (){
Serial.begin(9600);
Serial.println(«ready»);
//
irrecv.enableIRIn();
}

void loop() {
// results
//
decode_results results;
// —
//
if (irrecv.decode(&results)) {
Serial.println(results.value);
irrecv.resume();
}
}

IRremote
:

serial monitor :



8. Capteur de température DHT11


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <DHT.h>
#define dht_apin A0 // Analog Pin sensor is connected to

dht DHT;

void setup(){

Serial.begin(9600);
delay(500);//Delay to let system boot
Serial.println(«DHT11 Humidity & temperature Sensor\n\n»);
delay(1000);//Wait before accessing Sensor

}//end «setup()»

void loop(){
//Start of Program

DHT.read11(dht_apin);

Serial.print(«Current humidity = „);
Serial.print(DHT.humidity);
Serial.print(“% „);
Serial.print(“temperature = „);
Serial.print(DHT.temperature);
Serial.println(“C „);

delay(5000);//Wait 5 seconds before accessing sensor again.

//Fastest should be once every two seconds.

}// end loop()

:

:

.

9. Capteur de température LM35

float tempC;
int reading;
int tempPin = 0;

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

void loop()
{
reading = analogRead(tempPin);
tempC = reading / 9.31;
Serial.println(tempC);
delay(1000);
}




:



10. Relais

/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.

This example code is in the public domain.
*/

// Pin 4 has an LED connected on most Arduino boards.
// give it a name:
int led = 4;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

:

:

:


11. Affichage à sept segments

//http://arduinoworks.com
int e = 3;
int d = 4;
int c = 5;
int b = 6;
int a = 7;
int f = 8;
int g = 9;
int p= 10;
void setup()
{
pinMode(e, OUTPUT);
pinMode(d, OUTPUT);
pinMode(c, OUTPUT);
pinMode(b, OUTPUT);
pinMode(a, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
pinMode(p, OUTPUT);
digitalWrite(p,HIGH);
}
void displayDigit(int digit)
{
//Arduino Works Code for 7 segment Display
if(digit ==0)
{
digitalWrite(e,HIGH);
digitalWrite(d,HIGH);
digitalWrite(c,HIGH);
digitalWrite(b,HIGH);
digitalWrite(a,HIGH);
digitalWrite(f,HIGH);

}
else if(digit==1)
{
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
}

else if(digit ==2)
{
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(g,HIGH);
digitalWrite(e,HIGH);
digitalWrite(d,HIGH);
}

else if(digit ==3)
{
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(g,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
}


else if(digit == 4)
{
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
}
else if(digit == 5)
{
digitalWrite(a,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
}



else if(digit ==6)
{
digitalWrite(a,HIGH);
digitalWrite(f,HIGH);
digitalWrite(e,HIGH);
digitalWrite(d,HIGH);
digitalWrite(c,HIGH);
digitalWrite(g,HIGH);
}
else if(digit ==7)
{
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
}
else if(digit ==8)
{
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);

}
else if(digit ==9)
{
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(c,HIGH);
digitalWrite(d,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
}


}
void turnOff()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}

void loop()
{
//7 Segment Display with Arduino
for(int i=0;i<10;i++)
{
displayDigit(i);
delay(1000);
turnOff();
}
}

:

:



12. Indicateur à quatre chiffres et sept segments

/* A, B, C, D, E, F, G DP.
5 12: Arduino Uno,
.*/
int A = 5;
int B = 6;
int C = 7;
int D = 8;
int E = 9;
int F = 10;
int G = 11;
int DP = 12;
int z,y,w,x;
int K1 = 4;
int K2 = 3;
int K3 = 2;
int K4 = 1;
/*
,
0 9.*/
int a [10] = {1,0,1,1,0,1,1,1,1,1};
int b [10] = {1,1,1,1,1,0,0,1,1,1};
int c [10] = {1,1,0,1,1,1,1,1,1,1};
int d [10] = {1,0,1,1,0,1,1,0,1,1};
int e [10] = {1,0,1,0,0,0,1,0,1,0};
int f [10] = {1,0,0,0,1,1,1,0,1,1};
int g [10] = {0,0,1,1,1,1,1,0,1,1};
int dp [10] = {0,0,0,0,0,0,0,0,0,0};

void setup() {
// Arduino
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT);
pinMode(E, OUTPUT);
pinMode(F, OUTPUT);
pinMode(G, OUTPUT);
pinMode(DP, OUTPUT);
pinMode(K1, OUTPUT);
pinMode(K2, OUTPUT);
pinMode(K3, OUTPUT);
pinMode(K4, OUTPUT);
}

void loop() {

for( z = 9; z > 1; z-) {
for( y = 9; y > 1; y-) {
for( w = 9; w > 1; w-) {
for( x = 9; x > 1; x-) {
Myflesh(z,y,w,x);
Myflesh(z,y,w,x);
Myflesh(z,y,w,x);
Myflesh(z,y,w,x);
Myflesh(z,y,w,x);
}
}
}
}
}

void Myflesh(int i,int j,int k,int m) {
digitalWrite(A, a [i]);
digitalWrite(B, b [i]);
digitalWrite(C, c [i]);
digitalWrite(D, d [i]);
digitalWrite(E, e [i]);
digitalWrite(F, f [i]);
digitalWrite(G, g [i]);
digitalWrite(DP, dp [i]);
digitalWrite(K1, 0);
delay(3);
digitalWrite(K1, 1);
digitalWrite(A, a [j]);
digitalWrite(B, b [j]);
digitalWrite(C, c [j]);
digitalWrite(D, d [j]);
digitalWrite(E, e [j]);
digitalWrite(F, f [j]);
digitalWrite(G, g [j]);
digitalWrite(DP, dp [j]);
digitalWrite(K2, 0);
delay(3);
digitalWrite(K2, 1);
digitalWrite(A, a [k]);
digitalWrite(B, b [k]);
digitalWrite(C, c [k]);
digitalWrite(D, d [k]);
digitalWrite(E, e [k]);
digitalWrite(F, f [k]);
digitalWrite(G, g [k]);
digitalWrite(DP, dp [k]);
digitalWrite(K3, 0);
delay(3);
digitalWrite(K3, 1);
digitalWrite(A, a [m]);
digitalWrite(B, b [m]);
digitalWrite(C, c [m]);
digitalWrite(D, d [m]);
digitalWrite(E, e [m]);
digitalWrite(F, f [m]);
digitalWrite(G, g [m]);
digitalWrite(DP, dp [m]);
digitalWrite(K4, 0);
delay(3);
digitalWrite(K4, 1);
// delay(3);
}

/*
This Arduino code for “4-digit-7-segment-led-display» (KYX-5461AS).
* This code can display one Number in all 4 digit!
* This code can display 4 Numbers each on in specific digit
* This code can also make a Number Countdown (Timers).
author: Oussama Amri (@amriunix)
website: ithepro.com
*/

//display pins
int segA = 5; // >> 11
int segB = 13; // >> 7
int segC = 10; // >> 4
int segD = 8; // >> 2
int segE = 7; // >> 1
int segF = 4; // >> 10
int segG = 11; // >> 5
int segPt = 9; // >> 3
//------------//

//display digit
int d1 = 6; // >> 12
int d2 = 3; // >> 9
int d3 = 2; // >> 8
int d4 = 12; // >> 6
//------------//

int delayTime = 5000; //delayTime <Don't change it, if you don't know where is it!>

int i=0;

//=============================================//
//init all pin used
void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}

//=============================================//
void loop() {
//down(0,0,2,4);
all(5);
//writeN(1,9,9,4);
}

//=============================================//
//Write a Number — writeN(1,9,9,0) -> 1990
void writeN(int a,int b,int c,int d){
selectDwriteL(1,a);
selectDwriteL(2,b);
selectDwriteL(3,c);
selectDwriteL(4,d);
}

//=============================================//
//Make a Number Number Countdown (Timers).
void down(int a,int b,int c,int d){
while (a != -1) {
while(b != -1){
while(c != -1){
while (d != -1) {
while (i<10) { // i here is like a timer! because we can't use delay function
selectDwriteL(1,a);
selectDwriteL(2,b);
selectDwriteL(3,c);
selectDwriteL(4,d);
i++;
}
i=0;
d--;
}
d=9;
c--;
}
c=9;
b--;
}
b=9;
a--;
}
}

//=============================================//
//Select Wich Digit (selectD) is going to Display (writeL)
void selectDwriteL(int d,int l){
switch (d) { // choose a digit
case 0: digitalWrite(d1, LOW); //case 0 — All ON
digitalWrite(d2, LOW);
digitalWrite(d3, LOW);
digitalWrite(d4, LOW);
break;
case 1: digitalWrite(d1, LOW);//case 1 — Digit Number 1
digitalWrite(d2, HIGH);
digitalWrite(d3, HIGH);
digitalWrite(d4, HIGH);
break;
case 2: digitalWrite(d1, HIGH);//case 1 — Digit Number 2
digitalWrite(d2, LOW);
digitalWrite(d3, HIGH);
digitalWrite(d4, HIGH);
break;
case 3: digitalWrite(d1, HIGH);//case 1 — Digit Number 3
digitalWrite(d2, HIGH);
digitalWrite(d3, LOW);
digitalWrite(d4, HIGH);
break;
case 4: digitalWrite(d1, HIGH);//case 1 — Digit Number 4
digitalWrite(d2, HIGH);
digitalWrite(d3, HIGH);
digitalWrite(d4, LOW);
break;
}

switch (l) { // choose a Number
case 0: zero();
break;
case 1: one();
break;
case 2: two();
break;
case 3: three();
break;
case 4: four();
break;
case 5: five();
break;
case 6: six();
break;
case 7: seven();
break;
case 8: eight();
break;
case 9: nine();
break;
case 10: point(); // print a Point
break;
case 11: none(); // make all them off!
break;
}

delayMicroseconds(delayTime); // delayTime for nice display of the Number!

}

//=============================================//
//shown one Number in the 4 Digit
void all(int n){
selectDwriteL(0,n);
}

//=============================================//
void zero(){
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, LOW);
digitalWrite(segPt, LOW);
}
//=============================================//
void one(){
digitalWrite(segA, LOW);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
digitalWrite(segPt, LOW);
}
//=============================================//
void two(){
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, LOW);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, LOW);
digitalWrite(segG, HIGH);
digitalWrite(segPt, LOW);
}
//=============================================//
void three(){
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, HIGH);
digitalWrite(segPt, LOW);
}
//=============================================//
void four(){
digitalWrite(segA, LOW);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
digitalWrite(segPt, LOW);
}
//=============================================//
void five(){
digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
digitalWrite(segPt, LOW);
}
//=============================================//
void six(){
digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
digitalWrite(segPt, LOW);
}
//=============================================//
void seven(){
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
digitalWrite(segPt, LOW);
}
//=============================================//
void eight(){
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
digitalWrite(segPt, LOW);
}
//=============================================//
void nine(){
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
digitalWrite(segPt, LOW);
}
//=============================================//
void point(){
digitalWrite(segA, LOW);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
digitalWrite(segPt, HIGH);
}
//=============================================//
void none(){
digitalWrite(segA, LOW);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
digitalWrite(segPt, LOW);
}

:



:

, . , 4 :

.

13. Moteur pas à pas 28BYJ-48

// This Arduino example demonstrates bidirectional operation of a
// 28BYJ-48, using a ULN2003 interface board to drive the stepper.
// The 28BYJ-48 motor is a 4-phase, 8-beat motor, geared down by
// a factor of 68. One bipolar winding is on motor pins 1 & 3 and
// the other on motor pins 2 & 4. The step angle is 5.625/64 and the
// operating Frequency is 100pps. Current draw is 92mA.
////////////////////////////////////////////////

//declare variables for the motor pins
int motorPin1 = 8; // Blue — 28BYJ48 pin 1
int motorPin2 = 9; // Pink — 28BYJ48 pin 2
int motorPin3 = 10; // Yellow — 28BYJ48 pin 3
int motorPin4 = 11; // Orange — 28BYJ48 pin 4
// Red — 28BYJ48 pin 5 (VCC)

int motorSpeed = 1200; //variable to set stepper speed
int count = 0; // count of steps made
int countsperrev = 512; // number of steps per full revolution
int lookup[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};

//////////////////////////////////////////////////////////////////////////////
void setup() {
//declare the motor pins as outputs
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
Serial.begin(9600);
}

//////////////////////////////////////////////////////////////////////////////
void loop(){
if(count < countsperrev )
clockwise();
else if (count == countsperrev * 2)
count = 0;
else
anticlockwise();
count++;
}

//////////////////////////////////////////////////////////////////////////////
//set pins to ULN2003 high in sequence from 1 to 4
//delay «motorSpeed» between each pin setting (to determine speed)
void anticlockwise()
{
for(int i = 0; i < 8; i++)
{
setOutput(i);
delayMicroseconds(motorSpeed);
}
}

void clockwise()
{
for(int i = 7; i >= 0; i--)
{
setOutput(i);
delayMicroseconds(motorSpeed);
}
}

void setOutput(int out)
{
digitalWrite(motorPin1, bitRead(lookup[out], 0));
digitalWrite(motorPin2, bitRead(lookup[out], 1));
digitalWrite(motorPin3, bitRead(lookup[out], 2));
digitalWrite(motorPin4, bitRead(lookup[out], 3));
}


:
5V+ connect to +5V
5V- connect to 0V (Ground)
IN1: to Arduino digital input pin 8
IN2: to Arduino digital input pin 9
IN3: to Arduino digital input pin 10
IN4: to Arduino digital input pin 11
:

.

14. Joystick

/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor.
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

This example code is in the public domain.
*/

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(1); // delay in between reads for stability
}

// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott <people.interaction-ivrea.it/m.rinott>

#include <Servo.h>

Servo myservo; // create servo object to control a servo

int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}

void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}

:

:

.

15. Capteur sonore

/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor.
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

This example code is in the public domain.
*/

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(1); // delay in between reads for stability
}

:

, .

:
int Count=0; //
int Relay=0; //
void setup() {
pinMode(3, OUTPUT); // 3

}

void loop() {
Count=analogRead(4); //
if(Count > 200 && Count < 600)
{
delay(250); // 250
for(int t=0; t<=500; t++)
{
delay(1);
Count=analogRead(4); //
if(Count > 200 && Count < 600)
{
Relay=!Relay; //
break; //
delay(200); //
}
}
}
digitalWrite(3,Relay);
}

:

:

.

16. Module d'horloge DS1302


// DS1302_Serial_Easy ©2010 Henning Karlsen
// web: www.henningkarlsen.com/electronics
//
// A quick demo of how to use my DS1302-library to
// quickly send time and date information over a serial link
//
// I assume you know how to connect the DS1302.
// DS1302: CE pin -> Arduino Digital 2
// I/O pin -> Arduino Digital 3
// SCLK pin -> Arduino Digital 4

#include <DS1302.h>

// Init the DS1302
DS1302 rtc(2, 3, 4);

void setup()
{
// Set the clock to run-mode, and disable the write protection
rtc.halt(false);
rtc.writeProtect(false);

// Setup Serial connection
Serial.begin(9600);

// The following lines can be commented out to use the values already stored in the DS1302
rtc.setDOW(FRIDAY); // Set Day-of-Week to FRIDAY
rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)
rtc.setDate(6, 8, 2010); // Set the date to August 6th, 2010
}

void loop()
{
// Send Day-of-Week
Serial.print(rtc.getDOWStr());
Serial.print(" ");

// Send date
Serial.print(rtc.getDateStr());
Serial.print(" — ");

// Send time
Serial.println(rtc.getTimeStr());

// Wait one second before repeating :)
delay (1000);
}

:

:



17. Capteur de niveau de liquide
:
:
: dc3-5v
: 20
:
. . .

AnalogRead
/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor.
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

This example code is in the public domain.
*/

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(1); // delay in between reads for stability
}

:

:


18. Matrix 8x8
. 16 . MAX7219, 5 .


// Show messages scrolling from right to left.
#include <FrequencyTimer2.h>

#define SPACE { \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0}, \
{0, 0, 0, 0, 0, 0, 0, 0} \
}

#define E { \
{0, 1, 1, 1, 1, 1, 1, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0} \
}

#define G { \
{0, 1, 1, 1, 1, 1, 1, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 1, 1, 1}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0} \
}

#define H { \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0} \
}

#define K { \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 1, 0, 0}, \
{0, 1, 0, 0, 1, 0, 0, 0}, \
{0, 1, 1, 1, 0, 0, 0, 0}, \
{0, 1, 0, 1, 0, 0, 0, 0}, \
{0, 1, 0, 0, 1, 0, 0, 0}, \
{0, 1, 0, 0, 0, 1, 0, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0} \
}

#define L { \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 0, 0, 0, 0, 0, 0}, \
{0, 1, 1, 1, 1, 1, 1, 0} \
}

#define O { \
{0, 0, 0, 1, 1, 0, 0, 0}, \
{0, 0, 1, 0, 0, 1, 0, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 1, 0, 0, 0, 0, 1, 0}, \
{0, 0, 1, 0, 0, 1, 0, 0}, \
{0, 0, 0, 1, 1, 0, 0, 0} \
}

byte col=0;
byte leds[8][8];

int pins[17]={-1, 5, 4, 3, 2, 14, 15, 16, 17, 13, 12, 11, 10, 9, 8, 7, 6};
int cols[8] ={pins[13], pins[3], pins[4], pins[10], pins[06], pins[11], pins[15], pins[16]};
int rows[8] ={pins[9], pins[14], pins[8], pins[12], pins[1], pins[7], pins[2], pins[5]};

const int numPatterns=10;
byte patterns[numPatterns][8][8]={H,E,L,L,O,SPACE,G,K,L,SPACE};
int pattern=0;

void setup()
{
for (int i=1; i<=16; i++) {pinMode(pins[i], OUTPUT);}
for (int i=1; i<=8; i++) {digitalWrite(cols[i-1], LOW);}
for (int i=1; i<=8; i++) {digitalWrite(rows[i-1], LOW);}

clearLeds();

FrequencyTimer2::disable();
FrequencyTimer2::setPeriod(2000); // sets refresh rate
FrequencyTimer2::setOnOverflow(display);
setPattern(pattern);
}

void loop()
{
pattern=++pattern%numPatterns;
slidePattern(pattern, 60);
}

void clearLeds() {
for (int i=0; i<8; i++) {
for (int j=0; j<8; j++) {leds[i][j]=0;}
}
}

void setPattern(int pattern) {
for (int i=0; i<8; i++) {
for (int j=0; j<8; j++) {leds[i][j] = patterns[pattern][i][j];}
}
}

void slidePattern(int pattern, int del) {
for (int l=0; l<8; l++) {
for (int i=0; i<7; i++) {
for (int j=0; j<8; j++) {leds[j][i] = leds[j][i+1];}
}
for (int j=0; j<8; j++) {leds[j][7] = patterns[pattern][j][0 + l];}
delay(del);
}
}

void display() {
digitalWrite(cols[col], LOW);
col++;
if (col==8) {col=0;}
for (int row=0; row<8; row++) {
if (leds[col][7-row]==1) {digitalWrite(rows[row], LOW);}
else {digitalWrite(rows[row], HIGH);}
}
digitalWrite(cols[col], HIGH);}


:

:


19. Lecteur RFID RC522


Dumpinfo
/*
* — * Example sketch/program showing how to read data from a PICC to serial.
* — * This is a MFRC522 library example; for further details and other examples see: github.com/miguelbalboa/rfid
*
* Example sketch/program showing how to read data from a PICC (that is: a RFID Tag or Card) using a MFRC522 based RFID
* Reader on the Arduino SPI interface.
*
* When the Arduino and the MFRC522 module are connected (see the pin layout below), load this sketch into Arduino IDE
* then verify/compile and upload it. To see the output: use Tools, Serial Monitor of the IDE (hit Ctrl+Shft+M). When
* you present a PICC (that is: a RFID Tag or Card) at reading distance of the MFRC522 Reader/PCD, the serial output
* will show the ID/UID, type and any data blocks it can read. Note: you may see «Timeout in communication» messages
* when removing the PICC from reading distance too early.
*
* If your reader supports it, this sketch/program will read all the PICCs presented (that is: multiple tag reading).
* So if you stack two or more PICCs on top of each other and present them to the reader, it will first output all
* details of the first and then the next PICC. Note that this may take some time as all data blocks are dumped, so
* keep the PICCs at reading distance until complete.
*
* @license Released into the public domain.
*
* Typical pin layout used:
* — * MFRC522 Arduino Arduino Arduino Arduino Arduino
* Reader/PCD Uno Mega Nano v3 Leonardo/Micro Pro Micro
* Signal Pin Pin Pin Pin Pin Pin
* — * RST/Reset RST 9 5 D9 RESET/ICSP-5 RST
* SPI SS SDA(SS) 10 53 D10 10 10
* SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
*/

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance

void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD — MFRC522 Card Reader details
Serial.println(F(«Scan PICC to see UID, SAK, type, and data blocks...»));
}

void loop() {
// Look for new cards
if (! mfrc522.PICC_IsNewCardPresent()) {
return;
}

// Select one of the cards
if (! mfrc522.PICC_ReadCardSerial()) {
return;
}

// Dump debug info about the card; PICC_HaltA() is automatically called
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}

:

:

.

20. Affichage 16x2

LiquidCrystal_I2C
I2C Scanner
// — // i2c_scanner
//
// Version 1
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
// Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26 2013
// V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
// by Arduino.cc user Krodal.
// Changes by louarnold removed.
// Scanning addresses changed from 0...127 to 1...119,
// according to the i2c scanner by Nick Gammon
// www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
// As version 4, but address scans now to 127.
// A sensor seems to use address 120.
// Version 6, November 27, 2015.
// Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>


void setup()
{
Wire.begin();

Serial.begin(9600);
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
}


void loop()
{
byte error, address;
int nDevices;

Serial.println(«Scanning...»);

nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();

if (error == 0)
{
Serial.print(«I2C device found at address 0x»);
if (address<16)
Serial.print(«0»);
Serial.print(address,HEX);
Serial.println(" !");

nDevices++;
}
else if (error==4)
{
Serial.print(«Unknow error at address 0x»);
if (address<16)
Serial.print(«0»);
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println(«No I2C devices found\n»);
else
Serial.println(«done\n»);

delay(5000); // wait 5 seconds for next scan
}

:

:



En combinant ces 20 classes entre elles, vous pouvez obtenir 190 autres classes (20 * 19/2) différentes. Par exemple, en combinant une leçon sur un relais avec une leçon sur un récepteur infrarouge, vous pouvez assembler un appareil qui contrôle la charge de la télécommande du téléviseur. Dans ce cas, l'étudiant devra non seulement connecter deux éléments à l'arduino et rédiger un croquis pour qu'ils fonctionnent ensemble, mais aussi réfléchir à l'objectif possible de tels appareils. Par conséquent, ces 190 tâches peuvent être considérées comme créatives.

Classes 21-40. Les projets

21. Véhicule sans pilote

#define Trig 8
#define Echo 9
#include <Servo.h>

Servo servo;

int ugol = 90;
int smotrim_vlevo = 0;
int smotrim_vpravo = 0;
int smotrim_priamo = 0;
int vremia;

const int in11 = 0; // L298N-1 pin 1
const int in12 = 1; // L298N-1 pin 2
const int in13 = 2; // L298N-1 pin 2
const int in14 = 3; // L298N-1 pin 3

const int in21 = 4; // L298N-2 pin 1
const int in22 = 5; // L298N-2 pin 2
const int in23 = 6; // L298N-2 pin 2
const int in24 = 7; // L298N-2 pin 3

void setup()
{
servo.attach(10); // 10

pinMode(Trig, OUTPUT); //
pinMode(Echo, INPUT); //

pinMode(in11, OUTPUT); // L298n
pinMode(in12, OUTPUT); // L298n
pinMode(in13, OUTPUT); // L298n
pinMode(in14, OUTPUT); // L298n

pinMode(in21, OUTPUT); // L298n
pinMode(in22, OUTPUT); // L298n
pinMode(in23, OUTPUT); // L298n
pinMode(in24, OUTPUT); // L298n

}

void ehat_priamo(){

digitalWrite(in11, LOW);
digitalWrite(in12, HIGH);

digitalWrite(in13, LOW);
digitalWrite(in14, HIGH);

digitalWrite(in21, LOW);
digitalWrite(in22, HIGH);

digitalWrite(in23, HIGH);
digitalWrite(in24, LOW);
}

void ehat_vpravo()
{

digitalWrite(in21, LOW);
digitalWrite(in22, HIGH);

digitalWrite(in23, HIGH);
digitalWrite(in24, LOW);
}

void ehat_vlevo(){

digitalWrite(in21, HIGH);
digitalWrite(in22, LOW);

digitalWrite(in23, LOW);
digitalWrite(in24, HIGH);

}

void stoiat(){ //
digitalWrite(in11, LOW);
digitalWrite(in12, LOW);

digitalWrite(in13, LOW);
digitalWrite(in14, LOW);

digitalWrite(in21, LOW);
digitalWrite(in22, LOW);

digitalWrite(in23, LOW);
digitalWrite(in24, LOW);
}

void kak_meriat_sleva(){
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
vremia = pulseIn(Echo, HIGH);
smotrim_vlevo = vremia/58;
}

void kak_meriat_priamo(){
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
vremia = pulseIn(Echo, HIGH);
smotrim_priamo = vremia/58;
}

void kak_meriat_sprava(){
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
vremia = pulseIn(Echo, HIGH);
smotrim_vpravo = vremia/58;
}

void loop(){
kak_meriat_priamo();
if(smotrim_priamo<30){
stoiat();
delay(100);
for(ugol=90;ugol>=10;ugol--){
servo.write(ugol);
delay(5);
}

kak_meriat_sprava();
delay(100);
for(ugol=10;ugol<=170;ugol++){
servo.write(ugol);
delay(5);
}

kak_meriat_sleva();
delay(100);
for(ugol=170;ugol>=90;ugol--){
servo.write(ugol);
delay(5);
}

if(smotrim_vpravo < smotrim_vlevo){


ehat_vpravo();
delay(400);
stoiat();
}

else{

ehat_vlevo();
delay(400);
stoiat();
}

}

else{
ehat_priamo();
}
}


2WD . 4WD .

:



22. Machine contrôlée depuis un smartphone

int val;
int LED = 13;
int LED2 = 11;
int LED3 = 12;

#include <AFMotor.h> //
#include <Servo.h> // ,

// M1, M2, M3, M4
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);

void setup()
{
// ( PWM)
motor1.setSpeed(255);
motor1.run(RELEASE);
motor2.setSpeed(255);
motor2.run(RELEASE);
motor3.setSpeed(255);
motor3.run(RELEASE);
motor4.setSpeed(255);
motor4.run(RELEASE);

Serial.begin(9600);

}
int i;

void loop()
{
if (Serial.available())
{
val = Serial.read();

if (val == '5') // «5»
{digitalWrite(LED, HIGH);}
if (val == '6') // «6»
{digitalWrite(LED,LOW );}
if (val == 'Y') // «7»
{digitalWrite(LED2,HIGH );}
if (val == 'B') // «8»
{digitalWrite(LED3,HIGH );}

//
if (val == 'W') // «W»
{
// Motor Shield'
//
motor1.run(FORWARD); //
motor4.run(FORWARD);
motor1.setSpeed(255); //
motor4.setSpeed(255);
}

//
if ( val == 'S')
{
//
motor1.run(BACKWARD); //
motor4.run(BACKWARD);
motor1.setSpeed(255); //
motor4.setSpeed(255);
}

//
if ( val == 'D')
{
motor4.run(FORWARD); //
motor4.setSpeed(255); //
}

//
if ( val == 'A')
{
motor1.run(FORWARD); //
motor1.setSpeed(255); //
}

//
// «T»
if ( val == 'T') // «T»
{
motor1.run(RELEASE);
motor4.run(RELEASE);

}
if ( val == 'N') // «T»
{
// ENABLE ,

digitalWrite(LED2,LOW );
digitalWrite(LED3,LOW );
}
}
}


:

:



23. Robot aspirateur

- Android , RobotC, AppInventor.
«» , Bluetooth -.
: , , , , , , . , Bluetooth , Arduino , , - , Arduino.
«» - , «».
«» .
- , .
#define mot_ena 9 //
#define mot_in1 8 //
#define mot_in2 7 //
#define mot_in3 6 //
#define mot_in4 4 //
#define mot_enb 10 //

#define ir_1 A0 // 1 -
#define ir_2 A1 // 2 -
#define ir_3 A2 // 3 -
#define ir_4 A3 // 4 -
#define ir_5 A4 // 5 -
#define ir_6 A5 // 6 -

#define lev_vik 11 //
#define pra_vik 12 //

//
byte max_skor_lev = 254;
byte max_skor_prav = 244;
//---------------------------------

byte min_skor = 0;

void setup() {

randomSeed(analogRead(A7));
//
pinMode(3, INPUT); //
pinMode(2, INPUT); //
//-------------------------
//
pinMode(mot_ena, OUTPUT);
pinMode(mot_in1, OUTPUT);
pinMode(mot_in2, OUTPUT);
pinMode(mot_in3, OUTPUT);
pinMode(mot_in4, OUTPUT);
pinMode(mot_enb, OUTPUT);
//-------------------------------------------
// -
pinMode(ir_1, INPUT);
pinMode(ir_2, INPUT);
pinMode(ir_3, INPUT);
pinMode(ir_4, INPUT);
pinMode(ir_5, INPUT);
pinMode(ir_6, INPUT);
//-------------------------
//
pinMode(lev_vik, INPUT);
pinMode(pra_vik, INPUT);
//---------------------------
delay(3000);

ROB_VPERED();
}

void loop() {

//
if (digitalRead(lev_vik) == LOW)
{
ROB_STOP();
delay(200);
ROB_NAZAD();
delay(150);
ROB_STOP();
delay(200);
ROB_PRAV();
delay(random(400, 1500));
ROB_STOP();
delay(200);
ROB_VPERED();
}
//-----------------------------------------------
//
if (digitalRead(pra_vik) == LOW)
{
ROB_STOP();
delay(200);
ROB_NAZAD();
delay(150);
ROB_STOP();
delay(200);
ROB_LEV();
delay(random(400, 1500));
ROB_STOP();
delay(200);
ROB_VPERED();
}
//-----------------------------------------------
// 2 -
if (digitalRead(ir_2) == LOW)
{
ROB_STOP();
delay(200);
ROB_PRAV();
delay(random(200, 1100));
ROB_STOP();
delay(200);
ROB_VPERED();
}
//-----------------------------------------------
// 3 -
if (digitalRead(ir_3) == LOW)
{
ROB_STOP();
delay(200);
ROB_PRAV();
delay(random(200, 1100));
ROB_STOP();
delay(200);
ROB_VPERED();
}
//-----------------------------------------------
// 4 -
if (digitalRead(ir_4) == LOW)
{
ROB_STOP();
delay(200);
ROB_LEV();
delay(random(200, 1100));
ROB_STOP();
delay(200);
ROB_VPERED();
}
//-----------------------------------------------
// 5 -
if (digitalRead(ir_5) == LOW)
{
ROB_STOP();
delay(200);
ROB_LEV();
delay(random(200, 1100));
ROB_STOP();
delay(200);
ROB_VPERED();
}
//-----------------------------------------------
// 1 -
if (digitalRead(ir_1) == LOW)
{
ROB_PRAV();
delay(10);
ROB_VPERED();
}
//-----------------------------------------------
// 6 -
if (digitalRead(ir_6) == LOW)
{
ROB_LEV();
delay(10);
ROB_VPERED();
}
//-----------------------------------------------

}

//
void ROB_PRAV()
{
//
digitalWrite(mot_in1, LOW);
digitalWrite(mot_in2, HIGH);
analogWrite(mot_ena, max_skor_lev);
//
digitalWrite(mot_in3, LOW);
digitalWrite(mot_in4, HIGH);
analogWrite(mot_enb, max_skor_prav);
}
//-----------------
//
void ROB_LEV()
{
//
digitalWrite(mot_in3, HIGH);
digitalWrite(mot_in4, LOW);
analogWrite(mot_enb, max_skor_prav);
//
digitalWrite(mot_in1, HIGH);
digitalWrite(mot_in2, LOW);
analogWrite(mot_ena, max_skor_lev);
}
//---------------------
//
void ROB_VPERED()
{
//
digitalWrite(mot_in1, LOW);
digitalWrite(mot_in2, HIGH);
analogWrite(mot_ena, max_skor_lev);
//
digitalWrite(mot_in3, HIGH);
digitalWrite(mot_in4, LOW);
analogWrite(mot_enb, max_skor_prav);
}
//-------------------------------------
//
void ROB_NAZAD()
{
//
digitalWrite(mot_in1, HIGH);
digitalWrite(mot_in2, LOW);
analogWrite(mot_ena, max_skor_lev);
//
digitalWrite(mot_in3, LOW);
digitalWrite(mot_in4, HIGH);
analogWrite(mot_enb, max_skor_prav);
}
//------------------------------------
//
void ROB_STOP()
{
//
digitalWrite(mot_in1, LOW);
digitalWrite(mot_in2, LOW);
analogWrite(mot_ena, min_skor);
//
digitalWrite(mot_in3, LOW);
digitalWrite(mot_in4, LOW);
analogWrite(mot_enb, min_skor);
}
//--------------------------------


:

:

.

24. Robot araignée (hexapodes)

,



-

1
#include <Wire.h>
#include <Multiservo.h>

Multiservo myservo;

int pos = 0;

void setup(void)
{
Wire.begin();
myservo.attach(17);
}

void loop(void)
{
for (pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}

, .



:


.


En ce moment, il y a une recherche et une sélection de matériel pour les classes 25-40. Des liens vers des leçons vidéo en russe avec des projets intéressants sur l'arduino peuvent être laissés dans les commentaires de l'article.

Source: https://habr.com/ru/post/fr397019/


All Articles