• 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
sterowanie roletami
#13
Chciałem napisać w poprzednim wątku ale został zamknięty (http://forum.arduinopolska.com/watek-aut...ety?page=2).
Otóż po intensywnym kursie i lekturze o arduino udało mi się coś sklekocić z roletami. Działa to tak:
Dzwoni cichy alarm w Sleep as android (cichy, bo chcę aby rolety otwierały się pół godziny przed właściwym budzikiem) ----> informacja do IFTTT ----> IFTTT wysyła informację "1" do feed'a adafruit -----> NodeMCU v3 odczytuje informację "1" z feed'a ----> NodeMCU v3 uruchamia serwo

Na razie jest tylko odsłanianie zasłon.
Serwo to MG995 przerobione na pracę ciągłą.
Docelowo serwo będzie zasilane osobno, na razie do testów bez obciążenia zasilam z jednego USB.

Chciałbym Was prosić o poradę jak mechanicznym wyłącznikiem krańcowym przerywać pracę serwa?
a) rozwiązać to programowo funkcją if
b) wpiąć krańcówkę w kabel zasilający NodeMCU a kiedy będę wstał z łózka po prostu odłączyć zasilanie
c) inne rozwiązanie

https://drive.google.com/file/d/1m0GHfuA...sp=sharing

Proszę też o sprawdzenie kodu i wskazówki co zrobiłem źle.


Kod:
// Adafruit IO REST API access with ESP8266
//
// For use with ESP8266 Arduino from:
//   https://github.com/esp8266/Arduino
//
// Works great with ESP8266 modules like the Adafruit Huzzah ESP:
//  ----> https://www.adafruit.com/product/2471
//
// Written by Tony DiCola for Adafruit Industries.  
// MIT license, all text above must be included in any redistribution.
#include <ESP8266WiFi.h>
#include "Adafruit_IO_Client.h"
#include <Servo.h>


// Configure WiFi access point details.
#define WLAN_SSID  "xxxxxxx"
#define WLAN_PASS  "xxxxxxxx"

// Configure Adafruit IO access.
#define AIO_KEY    "xxxxxxxxxxxxxxxxxxxxxxx"


// Create an ESP8266 WiFiClient class to connect to the AIO server.
WiFiClient client;

// Create an Adafruit IO Client instance.  Notice that this needs to take a
// WiFiClient object as the first parameter, and as the second parameter a
// default Adafruit IO key to use when accessing feeds (however each feed can
// override this default key value if required, see further below).
Adafruit_IO_Client aio = Adafruit_IO_Client(client, AIO_KEY);

// Finally create instances of Adafruit_IO_Feed objects, one per feed.  Do this
// by calling the getFeed function on the Adafruit_IO_FONA object and passing
// it at least the name of the feed, and optionally a specific AIO key to use
// when accessing the feed (the default is to use the key set on the
// Adafruit_IO_Client class).
Adafruit_IO_Feed zaslony = aio.getFeed("zaslony");

// Alternatively to access a feed with a specific key:
//Adafruit_IO_Feed testFeed = aio.getFeed("esptestfeed", "...esptestfeed key...");

// Global state to increment a number and send it to the feed.
unsigned int count = 0;
Servo myservo;
int pos = 94;

void setup() {
 // Setup serial port access.
 Serial.begin(9600);
 delay(10);
 Serial.println(); Serial.println();
 Serial.println(F("Adafruit IO ESP8266 test!"));
 pinMode(2,OUTPUT);
 digitalWrite(2,LOW);
 myservo.attach(2);
 

 // Connect to WiFi access point.
 Serial.print("Connecting to ");
 Serial.println(WLAN_SSID);

 WiFi.begin(WLAN_SSID, WLAN_PASS);
 while (WiFi.status() != WL_CONNECTED) {
   delay(500);
   Serial.print(".");
 }
 Serial.println();

 Serial.println("WiFi connected");  
 Serial.println("IP address: "); Serial.println(WiFi.localIP());
 
 // Initialize the Adafruit IO client class (not strictly necessary with the
 // client class, but good practice).
 aio.begin();

 Serial.println(F("Ready!"));
}

void loop() {

 // To read the latest feed value call the receive function on the feed.
 // The returned object will be a FeedData instance and you can check if it's
 // valid (i.e. was successfully read) by calling isValid(), and then get the
 // value either as a text value, or converted to an int, float, etc.
 FeedData latest = zaslony.receive();
 if (latest.isValid()) {
   Serial.print(F("Received value from feed: ")); Serial.println(latest);
   // By default the received feed data item has a string value, however you
   // can use the following functions to attempt to convert it to a numeric
   // value like an int or float.  Each function returns a boolean that indicates
   // if the conversion succeeded, and takes as a parameter by reference the
   // output value.
   int i;
   if (latest.intValue(&i)) {
     Serial.print(F("Value as an int: ")); Serial.println(i, DEC);
   }
   // Other functions that you can use include:
   //  latest.uintValue() (unsigned int)
   //  latest.longValue() (long)
   //  latest.ulongValue() (unsigned long)
   //  latest.floatValue() (float)
   //  latest.doubleValue() (double)
   if (i == 1){
     Serial.println("Alarm on!");
     for (pos = 96; pos <= 180; pos += 1)
     myservo.write(pos);
     delay(1000);
   }
   else{
     digitalWrite(2,LOW);
   }
   }
 else{
   Serial.print(F("Failed to receive the latest feed value!"));
   digitalWrite(2,LOW);
 }
 // Now wait 10 more seconds and repeat.
 Serial.println(F("Waiting 10 seconds and then writing a new feed value."));
 delay(10000);
}
 
Odpowiedź
  


Wiadomości w tym wątku
sterowanie roletami - przez malass - 17-05-2016, 20:36
RE: sterowanie roletami - przez JasQ - 18-05-2016, 18:41
RE: sterowanie roletami - przez adix - 20-05-2016, 00:29
RE: sterowanie roletami - przez Szafa - 13-06-2016, 11:27
RE: sterowanie roletami - przez adix - 13-06-2016, 20:50
RE: sterowanie roletami - przez mavi - 20-06-2016, 12:49
RE: sterowanie roletami - przez pan_statystyka - 21-06-2016, 20:00
RE: sterowanie roletami - przez mavi - 22-06-2016, 01:10
RE: sterowanie roletami - przez adix - 13-07-2016, 23:21
RE: sterowanie roletami - przez Ghost1991 - 16-11-2016, 22:22
RE: sterowanie roletami - przez krn78 - 17-11-2016, 13:53
RE: sterowanie roletami - przez namok - 17-11-2016, 09:52
RE: sterowanie roletami - przez LucaBrasi - 03-01-2018, 21:52
RE: sterowanie roletami - przez Smaczek - 04-01-2018, 10:17
RE: sterowanie roletami - przez LucaBrasi - 06-01-2018, 22:55
RE: sterowanie roletami - przez kaczakat - 05-03-2018, 23:38
RE: sterowanie roletami - przez Alsenas - 20-08-2019, 13:22

Skocz do:


Przeglądający: 1 gości