This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| et:iot:examples:relay [2024/07/04 16:15] – rojarl | et:iot:examples:relay [2024/07/04 16:18] (current) – rojarl | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ======Relee näidis====== | ||
| + | Relee moodul peab olema ühendatud kontrolleri või anduri mooduliga. | ||
| + | |||
| + | {{: | ||
| + | {{: | ||
| + | |||
| + | |||
| + | Releel on kolm sisend. | ||
| + | |||
| + | {{: | ||
| + | |||
| + | Vajaminevad teegid: | ||
| + | < | ||
| + | |||
| + | Näidiskood näitab kas midagi on ühendatud relee mooduliga või mitte: | ||
| + | <code c> | ||
| + | // Includes global variables and librarys that the relay shield uses | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | #define MODULE_TOPIC " | ||
| + | #define WIFI_NAME " | ||
| + | #define WIFI_PASSWORD " | ||
| + | |||
| + | #define RELAY_PIN 5 // The relay has been connected to pin 5 | ||
| + | |||
| + | // If message received switch relay | ||
| + | void iot_received(String topic, String msg) | ||
| + | { | ||
| + | Serial.print(" | ||
| + | Serial.print(topic); | ||
| + | Serial.print(" | ||
| + | Serial.println(msg); | ||
| + | |||
| + | if(topic == MODULE_TOPIC) | ||
| + | { | ||
| + | // If message received and it is 1, then switch relay on | ||
| + | if(msg == " | ||
| + | { | ||
| + | digitalWrite(RELAY_PIN, | ||
| + | } | ||
| + | // If message received and it is 0, then switch relay on | ||
| + | if(msg == " | ||
| + | { | ||
| + | digitalWrite(RELAY_PIN, | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | // Function started after the connection to the server is established. | ||
| + | void iot_connected() | ||
| + | { | ||
| + | Serial.println(" | ||
| + | iot.subscribe(MODULE_TOPIC); | ||
| + | iot.log(" | ||
| + | } | ||
| + | |||
| + | void setup() | ||
| + | { | ||
| + | Serial.begin(115200); | ||
| + | Serial.println(" | ||
| + | | ||
| + | // | ||
| + | // | ||
| + | iot.printConfig(); | ||
| + | iot.setup(); | ||
| + | |||
| + | pinMode(RELAY_PIN, | ||
| + | } | ||
| + | |||
| + | void loop() | ||
| + | { | ||
| + | iot.handle(); | ||
| + | delay(200); // Wait for 0.2 seconds | ||
| + | } | ||
| + | |||
| + | </ | ||