• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Arduino servo mechanizm
#4
model serwa to Tower pro SG-90 
a kod :
Kod:
#include <SPI.h>
#include <RFID.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include<SoftwareSerial.h>
LiquidCrystal_I2C lcd(0x3F, 16, 2);
#include <Servo.h>
int czujnik =  A0;
int czujnik2 = A2;
int czujnik3 = A4;
int czujnik4 = A6;
int odczyt = 0 ;
int odczyt2 = 0 ;
int odczyt3 = 0;
int odczyt4 = 0;
//int buzzer = 11;
int poziom_gazu = 400;
int pos = 90;

int suma;
#define SIM800_TX_PIN 8
#define SIM800_RX_PIN 7
SoftwareSerial serialSIM800(SIM800_TX_PIN, SIM800_RX_PIN);
Servo myservo;
#define SDA_DIO 9
#define RESET_DIO 10
RFID RC522(SDA_DIO, RESET_DIO);


void setup()

{
 pinMode(czujnik, INPUT);
 pinMode(czujnik2, INPUT);
 pinMode(czujnik3, INPUT);
 pinMode(czujnik4, INPUT);
 myservo.attach(2);
 Serial.begin(9600);
 SPI.begin();
 RC522.init();
 //pinMode(buzzer, OUTPUT);
 lcd.init();
 lcd.backlight();
 lcd.setBacklight(HIGH);
 RC522.init();
 while (!Serial);
 serialSIM800.begin(9600);
 delay(1000);




}
void loop()
{
myservo.write(pos);
 odczyt = analogRead(czujnik);

 odczyt2 = analogRead(czujnik2);
 odczyt3 = analogRead(czujnik3);
 odczyt4 = analogRead(czujnik4);

 Serial.print(odczyt);
 Serial.print(" ");
 Serial.print(odczyt2);
 Serial.print(" ");
 Serial.print(odczyt3);
 Serial.print(" ");
 Serial.print(odczyt4);
 Serial.println(" ");
 czujnik_gazu();

 lcd.setCursor(1, 0);
 lcd.print("Przyloz karte");
 if (RC522.isCard())
 {
   RC522.readCardSerial();
   Serial.println("Card detected:");

   for ( int i = 0; i < 5; i++)
   {
     Serial.print(RC522.serNum[i], DEC);

   }
   suma = RC522.serNum[0] + RC522.serNum[1] + RC522.serNum[2] + RC522.serNum[3] + RC522.serNum[4];
   Serial.print(suma, DEC);
   if (suma == 542) {
//      digitalWrite(buzzer, HIGH);
     lcd.setCursor(8, 0);
     lcd.print("        ");
     lcd.setCursor(1, 0);
     lcd.print("Dziekuje ");
     lcd.setCursor(1, 1);
     lcd.print("Milego dnia ");
     delay(250);
//      digitalWrite(buzzer, LOW);
 
void otiweranie_drzwi();

   } else {
     lcd.setCursor(1, 0);
     lcd.print("Incorrect ID!");

   }

 }
 delay(1000);
 lcd.clear();
}
void czujnik_gazu() {

 if (odczyt > poziom_gazu or odczyt2 > poziom_gazu or odczyt3 > poziom_gazu or odczyt4 > poziom_gazu )
 {
   serialSIM800.write("AT+CMGF=1\r\n");
   delay(1000);

   //serialSIM800.write("AT+CMGS=\"+48xxx\"\r\n");
   delay(1000);

   serialSIM800.write("Poziom gazu w Twoim domu jest zbyt wysoki  !!");
   delay(1000);

   serialSIM800.write((char)26);
   delay(1000);

 }
}


void otiweranie_drzwi() {

for (pos = 90; pos >= 10; pos--)
 {

   myservo.write(pos);
   delay(20);
 }
 delay(6000);
 for (pos = 10; pos <= 90; pos++)
 {
   myservo.write(pos );
   delay(20);

 }

}
 
Odpowiedź
  


Wiadomości w tym wątku
Arduino servo mechanizm - przez koziollbk - 16-04-2018, 09:26
RE: Arduino servo mechanizm - przez es2 - 16-04-2018, 10:59
RE: Arduino servo mechanizm - przez Robson Kerman - 16-04-2018, 15:54
RE: Arduino servo mechanizm - przez koziollbk - 16-04-2018, 18:01

Skocz do:


Przeglądający: 1 gości