Skip to content

Instantly share code, notes, and snippets.

@rafalw
Created February 6, 2020 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafalw/b6a6650ca820f7734a469d5d2b4a59ad to your computer and use it in GitHub Desktop.
Save rafalw/b6a6650ca820f7734a469d5d2b4a59ad to your computer and use it in GitHub Desktop.
Arduino + Blynk + lokalny serwer na RaspberryPi = Smart Home (cz. 2 – ciągle sterowanie przekaźnikiem)
/*************************************************************
SmartHome by Rafał ;)
Sterowanie przekaźnikiem z wykorzystaniem:
– Arduino UNO
– Ethernet Shield W5100
– modułu DIY z przekaźnikiem RM96P-5-W
– dwukolorowej diody świecącej (do sygnalizacji stanu połączenia)
Kod mocno bazujący na przykładzie ze strony projekytu Blynk,
stąd pozostawiony oryginalny komentarz poniżej.
*************************************************************/
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Sketch generator: http://examples.blynk.cc
Blynk community: http://community.blynk.cc
Follow us: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
*************************************************************
You’ll need:
- Blynk App (download from AppStore or Google Play)
- Arduino Uno board
- Decide how to connect to Blynk
(USB, Ethernet, Wi-Fi, Bluetooth, ...)
There is a bunch of great example sketches included to show you how to get
started. Think of them as LEGO bricks and combine them as you wish.
For example, take the Ethernet Shield sketch and combine it with the
Servo example, or choose a USB sketch and add a code from SendData
example.
*************************************************************/
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
// Wyprowadzenia dla diody i przekaźnika
#define LED_RED 7
#define LED_GREEN 3
#define RELAY 5
// Token projektu (serwer lokalny)
char auth[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // tutaj wpisać token dla swojej aplikacji i urządzenia
// Wyprowadzenia konfiguracyjne Ethernet Shield
#define W5100_CS 10
#define SDCARD_CS 4
// Konfiguracja sieciowa Arduino w formacie zgodnym z biblioteką Arduino Ethernet
byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED }; // adres MAC dowolny...
IPAddress ip ( 192, 168, 1, 80); // Adresacja zgodna z siecią domową
IPAddress dns ( 1, 1, 1, 1);
IPAddress gateway ( 192, 168, 1, 100);
IPAddress subnet ( 255, 255, 255, 0);
IPAddress server ( 192, 168, 1, 2);
int port = 8080;
void setup()
{
// Debug console
Serial.begin(9600);
pinMode(LED_RED, OUTPUT);
digitalWrite(LED_RED, HIGH); // na początku świeci czerwona dioda – brak połączenia
pinMode(LED_GREEN, OUTPUT);
digitalWrite(LED_GREEN, LOW);
pinMode(RELAY, OUTPUT);
digitalWrite(RELAY, LOW);
pinMode(SDCARD_CS, OUTPUT);
digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card
Blynk.begin(auth, server, port, ip, dns, gateway, subnet, mac);
}
void loop()
{
if (Blynk.connected()) {
// Jeśli połączenie z serwerem Blynk zostało ustanowione
// świeci dioda zielona...
digitalWrite(LED_RED, LOW);
digitalWrite(LED_GREEN, HIGH);
} else {
//... zaś w przeciwnym przypadku – czerwona
digitalWrite(LED_GREEN, LOW);
digitalWrite(LED_RED, HIGH);
}
Blynk.run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment