etru_RU

Практическое занятие 7 Двигатель и датчик измерения расстояния

от автора

в

7.1 Katse Mootori kasutamine

https://www.tinkercad.com/things/e22w8iOXJa7-tremendous-kieran-krunk

Tööpõhimõte Katse Mootori kasutamine:

  • H-silla kontrolli mootori pöörlemissuunda. Lüliti paneb mootori tööle, lüliti mis muudab pöörlemissuunda ja muuttakisti mootori kiiruse muutmiseks.

Komponeendid Katse Mootori kasutamine :

  • 16 juhtmed ;
  • 1 H-sild ;
  • 1 gearmotor ;
  • 1 resistor ;
  • 1 button ;
  • 1 Breadboard Small ;
  • 1 Arduino Uno R3

Katse Mootori kasutamine kood :

int switchPin = 2; // lüliti 1 

int motor1Pin1 = 3; // viik 2 (L293D) 

int motor1Pin2 = 4; // viik 7 (L293D) 

int enablePin = 9; // viik 1(L293D) 

 void setup() { 

 // sisendid 

 pinMode(switchPin, INPUT);

 //väljundid 

 pinMode(motor1Pin1, OUTPUT); 

 pinMode(motor1Pin2, OUTPUT); 

 pinMode(enablePin, OUTPUT); 

 // aktiveeri mootor1 

 digitalWrite(enablePin, HIGH); 

} 

 void loop() { 

 // kui lüliti on HIGH, siis liiguta mootorit ühes suunas: 

 if (digitalRead(switchPin) == HIGH) 

{ 

 digitalWrite(motor1Pin1, LOW); // viik 2 (L293D) LOW 

 digitalWrite(motor1Pin2, HIGH); // viik 7 (L293D) HIGH 

 } 

 // kui lüliti on LOW, siis liiguta mootorit teises suunas: 

 else

 { digitalWrite(motor1Pin1, HIGH); // viik 2 (L293D) HIGH 

 digitalWrite(motor1Pin2, LOW); // viik 7 (L293D) LOW 

 } 

} 

7.2 Katse Kauguse mõõtmise anduri kasutamine

https://www.tinkercad.com/things/fiBgK1TvjgP-brave-snicket-blad

Tööpõhimõte Katse Kauguse mõõtmise anduri kasutamine :

  • Ultraheli sensor mõõdab heliimpulsi abil kaugust eesoleva takistuseni.

Komponeendid Katse Kauguse mõõtmise anduri kasutamine :

  • 4 juhtmed ;
  • Ultraheli sensor ;
  • 1 Arduino Uno R3

Katse Kauguse mõõtmise anduri kasutamine kood :

#define ECHO_PIN 8

#define TRIG_PIN 7

void setup() {

  pinMode(ECHO_PIN, INPUT);

  pinMode(TRIG_PIN, OUTPUT);

  Serial.begin(9600);

}

void loop() {

  digitalWrite(TRIG_PIN,HIGH);

  digitalWrite(TRIG_PIN,LOW);

  int distance=pulseIn(ECHO_PIN, HIGH)/50;

  Serial.println(distance);

}

Rahakarp või Prügikast

Rahakarp kasutamine :

  • Kui anduri kaugus on väiksem kui kümme, ilmub ekraanile fraas — «Distance < 10″ ; » +1 coin» ja coin pilt
  • Kui kaugus andurist on suurem kui kakskümmend, ilmub ekraanile fraasid — «Distance > 20» ; «Far away» ; «No coins» ja cross pilt

Rahakarp komponeendid :

  • 3 resistor ;
  • 2 LED ;
  • 1 Ultraheli sensor ;
  • Servo mootor ;
  • 1 1602 LCD ekraan ;
  • 1 potentsiomeeter ;
  • 23 juhtmed ;
  • 1 Breadboard Small ;
  • 1 Arduino Uno R3

Rahakarp kood :

#include <LiquidCrystal.h>
#include <Servo.h>
#define ECHO_PIN 8
#define TRIG_PIN 7
Servo servo1;
int numRows = 2;
int numCols = 16;
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
int GREEN = 10;
int RED = 13;
byte coin[8] = {
    0b00000,
    0b01110,
    0b11011,
    0b10101,
    0b11011,
    0b01110,
    0b00000,
    0b00000
};
byte nocoin[8] = {
    0b10001,
    0b01010,
    0b00100,
    0b01010,
    0b10001,
    0b00000,
    0b00000,
    0b00000
};
byte road[8] = {
    0b00110,
    0b01100,
    0b01100,
    0b00110,
    0b00110,
    0b01100,
    0b01100,
    0b00110
};
byte small_road[8] = {
    0b01100,
    0b01100,
    0b00000,
    0b00000,
    0b00000,
    0b00000,
    0b00000,
    0b00000
};
void setup() 
{
  pinMode(ECHO_PIN, INPUT);
  pinMode(TRIG_PIN, OUTPUT);
  servo1.attach(9);
  Serial.begin(9600);
  pinMode(RED, OUTPUT);
  pinMode(GREEN, OUTPUT);
  lcd.begin(numCols, numRows);
  lcd.createChar(1, coin);
  lcd.createChar(2, nocoin);
  lcd.createChar(3, road);
  lcd.createChar(4, small_road);
}
void loop() 
{
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  unsigned long duration = pulseIn(ECHO_PIN, HIGH);
  int distance = duration * 0.034 / 2;
  Serial.println(distance);
  digitalWrite(RED, LOW);
  digitalWrite(GREEN, LOW);
  if (distance < 10) 
  {
    servo1.write(0);
    digitalWrite(GREEN, HIGH);
    digitalWrite(RED, LOW);
    lcd.setCursor(0, 1);
    lcd.write(4);
    lcd.setCursor(2, 0);
    lcd.print("Distance < 10");
    lcd.setCursor(4, 2);
    lcd.print("Close");
    delay(800);
    lcd.setCursor(2, 1);
    lcd.write(1);
    lcd.setCursor(4, 2);
    lcd.print(" +1 coin");
    lcd.clear();
    } 
  else if (distance > 20) {
        servo1.write(180); // Adjust servo position based on your requirements
        digitalWrite(RED, HIGH);
        digitalWrite(GREEN, LOW);
        lcd.setCursor(0, 1);
        lcd.write(3);
        lcd.setCursor(2, 0);
        lcd.print("Distance > 20");
        lcd.setCursor(4, 2);
        lcd.print("Far away");
        delay(800);
        lcd.setCursor(2, 1);
        lcd.write(2);
        lcd.setCursor(4, 2);
        lcd.print("No coins");
        lcd.clear();
    }
}

void texts(char *text) {
    int length = strlen(text);
    if (length < numCols)
        lcd.print(text);
    else {
        int pos;
        for (pos = 0; pos < numCols; pos++)
            lcd.print(text[pos]);
        delay(800);
        while (pos < length) {
            lcd.scrollDisplayLeft();
            lcd.print(text[pos]);
            pos = pos + 1;
            delay(500);
        }
    }
}

Photo / Video :

Photo :

Video :

https://drive.google.com/file/d/1Nn8hhQeM3jWpIARAJP1_75hq-lKpax4l/view?usp=drivesdk

Kommentaatorid (uued võimalused) :

  • H-silla — saaksime kontrollida mootori pöörlemissuunda. lisame skeemi lüliti, mis paneb mootori tööle, lüliti mis muudab pöörlemissuunda ja muuttakisti mootori kiiruse muutmiseks.
  •  if (digitalRead(switchPin) == HIGH) — kui lüliti on HIGH, liigutage mootorit ühes suunas.
  • digitalWrite(motor1Pin2, LOW); — kui lüliti on LOW, liigutage mootorit teises suunas

Комментарии

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *