Dear All, I’m new to arduino and to Blynk.
But I’m trying to build a simple project. In Blynk I use only two buttons connected to virtual ports V0 and V1.
I’m using arduino MKR1000 and on V1 i have connected a servo motor, On V0 I have just a small submergable pump (3V) connected with a transistor to MKR1000.
Now my problem. when I press button V1 on Blynk the servo does what he need to do.
But when pressing Button V0 the pump starts, and blynk loses his connection, and the pump works on without to stop even when the program is in the MKR1000 to stop it,
What am I doing wrong?
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <WiFi101.h>
#include <BlynkSimpleMKR1000.h>
#include "Servo.h"
Servo servo; // kreiramo servo objekt za upravljanje motorom
int pos = 0; // varijabla u koju spremamo trenutnu poziciju motora
int pinValue;// Varijabla za dugme iz Blynka).
int pinValue0;// Varijabla za dugme iz Blynka).
char auth[] = "19aebd4f72494940bcc82808d303fc21";// You should get Auth Token in the Blynk App.
char ssid[] = "AndroidAP";// Your WiFi credentials.
char pass[] = "3042311471"; // Set password to "" for open networks.
BLYNK_WRITE(V0){ //starts when V0 is pressed
int pinValue0 = param.asInt();//copy virtual pin to pinValue
digitalWrite(9, HIGH); // start pump on pin 9
delay(5000); // wait 5 seconds
digitalWrite(9, LOW); // stop pump
}
BLYNK_WRITE(V1){ //servo
int pinValue = param.asInt();//copy virtual pin state
if (pinValue == HIGH) {
servo.attach(8);// connects servo to D8
for (pos = 0; pos <= 70; pos += 1) { // goes from 0 degrees to 70 degrees in steps of 1 degree
servo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
delay (1000);//delay between open and close
for (pos = 70; pos >= 0; pos -= 1) { // goes from 70 degrees to 0 degrees
servo.attach(8);
servo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
servo.detach();
} }
void setup()
{
Serial.begin(9600);
servo.write(0);
Blynk.begin(auth, ssid, pass);
pinMode(9, OUTPUT);
}
void loop()
{
Blynk.run();
}