I manage to connect the Arduino Nano 33 IoT with the new Blynk 2:0 This is my code:
#define BLYNK_TEMPLATE_ID "TMPLlIYEGdKX"
#define BLYNK_DEVICE_NAME "Quickstart Device"
#define BLYNK_AUTH_TOKEN "i6_6RtubQuDG9EtBEIE1h2Y6vOX__yVG"
//Aukaforrit=library fyrir kóða__________________________________________________________________
#define BLYNK_PRINT Serial
#include <WiFiNINA.h>
#include <BlynkSimpleWiFiNINA.h>
#include <SPI.h> // Þarf ekki þetta safn
// Auto Token ________________________________________________________________________
//char auth[] = "e7EWNTmRObb3r1k68lYIRXP-R5YqZwV5"; //HVITTBOX
char auth[] = BLYNK_AUTH_TOKEN;
// Þitt WIFI _________________________________________________________________________
//char ssid[] = "HFN-Gestir"; // ÞRÁÐLAUST NET HEITI
//char pass[] = "Net.fyrir.Gest!"; // Leyniorð
//char ssid[] = "FAS1";
//char pass[] = "fasergodur";
char ssid[] = "ard-net";
char pass[] = "";
//char ssid[] = "Siminn542879";
//char pass[] = "4DE63BF795";
// Relay pinni __________________________________________________________________________
const int Relay_pin = 8;
// Snúningstakki skilgreining ___________________________________________________________
const int Snuningstakki = A0;
int lesa_takki_fasti;
int skrifa_takki_fasti;
// Rakaskynjari skilgreining ____________________________________________________________
const int RakaSensor = A1; // Pinni fyrir rakaskynjara er A1
int RakaFasti;
const int dry = 718; // Hæsta gildi rakaskynjara
const int wet = 316; // Lægsta gildi rakaskynjara
// Flotskynjari skilgreining ____________________________________________________________
const int Float_sensor = 7; //Flot skynjari er skráður á pinna 7.
int Float_fasti = 0; //fasti eða gildi sem lesturinn skynjarans færist á.
// RGB LED peru skilgreining ____________________________________________________________
const int LED_RED = 3; //rauður
const int LED_BLUE = 4; //blár
const int LED_GREEN = 5; //grænn
const int resetPin = 2; // Til að geta endurræst Arduino eftir þörfum.
BlynkTimer timer; // Keyra upp "BlynkTimer" til að halda öllu í réttri tímaröð
// This function is called every time the device is connected to the Blynk.Cloud
BLYNK_CONNECTED()
{
// Change Web Link Button message to "Congratulations!"
Blynk.setProperty(V3, "offImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations.png");
Blynk.setProperty(V3, "onImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations_pressed.png");
Blynk.setProperty(V3, "url", "https://docs.blynk.io/en/getting-started/what-do-i-need-to-blynk/how-quickstart-device-was-made");
}
WidgetLCD lcd(V2); // Keyra upp stuðning fyrir stafrænan LCD skjá fyrir Blynk á stafrænan pinna V2.
// Þessi loopa sendir upplýsingar á serverinn á 1 sec frestii____________________________
void sendFlagToServer() {
lesa_takki_fasti = analogRead (Snuningstakki); // Lesa snúningstakka pinnann
skrifa_takki_fasti = (255./1023.) * lesa_takki_fasti; // Breyta gildunum í 0 til 255.
RakaFasti = analogRead(RakaSensor); // Lesa rakaskynjara pinnnann
Serial.println(RakaFasti);
int Rakastig = map(RakaFasti, wet, dry, 100, 0); // Breyta gildunum í 0 til 100 %.
if(Rakastig >= 100)
{
Serial.println("100 %");
}
else if(Rakastig <=0)
{
Serial.println("0 %");
}
else if(Rakastig >0 && Rakastig < 100)
{
Serial.print(Rakastig);
Serial.println("%");
}
Float_fasti = digitalRead (Float_sensor); //Lesa flotskynjarann og færa yfir í Float_fasti
Blynk.virtualWrite(V4,Rakastig); // Senda gildi rakaskynjarans á Blynk á stafrnæna pinna V4
Blynk.virtualWrite(V5,Float_fasti); // Senda gildi flotskynjarans á Blynk á stafrnæna pinna V5
// Þessi if loopa stýrir LED perunum miðað við stöðu flotskynjarans.
if (Float_fasti ==0) //HVÍTUR 0 , GRÆNN 1
{
analogWrite (LED_GREEN,0);
digitalWrite (LED_RED,HIGH);
}
else {
analogWrite (LED_GREEN,skrifa_takki_fasti);
digitalWrite (LED_RED,LOW);
}
}
// Þessi if loopa sendir lcd tilkynningu á Blynk appið miðað við stöðu flotskynjarans.
void sendFlag2ToServer() {
if (Float_fasti ==1) //HVÍTUR 0
{
lcd.clear ();
lcd.print(1, 0, "G-KERFI:");
lcd.print(1, 1, "VATN-ON");
}
else {
lcd.clear ();
lcd.print(1, 0, "FORÐABÚR:");
lcd.print(1, 1, "Vatn vantar");
Serial.println ("Rakaskynjari");
Serial.print (Float_fasti);
}
}
// Forrit bíður eftir skipun frá Blynk appi (V1) kveikja eða slökkva á dælu.
BLYNK_WRITE(V1) {
long Relay_Value = param[0].asLong();
if (Relay_Value !=0)
{
digitalWrite (Relay_pin,HIGH);
Blynk.virtualWrite(V7,255);
}
else {
digitalWrite (Relay_pin,LOW);
Blynk.virtualWrite(V7,0);
}
}
BLYNK_WRITE(V8) // Til að geta endurræst tölvuna frá Bynk með stafrnænapinnaum V8
{
if (param.asInt()==1) {
digitalWrite (resetPin,LOW);
delay(5000);
}
}
// Uppsetning forrits, Blynk, serial, pinnar og tími uppsettur.
void setup()
{
// Debug console
Serial.begin(115200);
//Blynk.begin(auth, ssid, pass);
// You can also specify server:
Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
// Setup a function to be called every second
timer.setInterval(1000L, sendFlagToServer);
timer.setInterval(9950L, sendFlag2ToServer);
pinMode(Relay_pin, OUTPUT);
pinMode(RakaSensor, INPUT);
pinMode (Snuningstakki, INPUT);
pinMode(Float_sensor,INPUT_PULLUP);
pinMode (LED_BLUE,OUTPUT);
pinMode (LED_RED,OUTPUT);
pinMode (LED_GREEN,OUTPUT);
pinMode (resetPin,OUTPUT);
digitalWrite (resetPin,HIGH);
digitalWrite (LED_BLUE,HIGH);
delay (200);
digitalWrite (LED_BLUE,LOW);
delay (200);
digitalWrite (LED_BLUE,HIGH);
delay (200);
digitalWrite (LED_BLUE,LOW);
delay (200);
digitalWrite (LED_BLUE,HIGH);
delay (200);
digitalWrite (LED_BLUE,LOW);
delay (30);
// Serial.print ("Reset");
}
// Meginn loopan inniheldur aðeins Blynk run og timer run.
void loop()
{
Blynk.run();
timer.run();
}