So, I have a buzzer connected to a fire sensor on my Arduino Uno, it runs just fine if I don’t add the codes for the Blynk. But whenever I un-comment
Blynk.begin(Serial, auth);
on my code, the buzzer won’t switch on.
Here is the full code:
#define BLYNK_PRINT DebugSerial
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3);
int sensorPin = A0;
int sensorValue = 0;
int led = 9;
int buzzer = 12;
#include <BlynkSimpleStream.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "728bc5722a3f43208bb57905ec22f226";
void setup()
{
// Debug console
DebugSerial.begin(9600);
// Blynk will work through Serial
// Do not read or write this serial manually in your sketch
pinMode(led, OUTPUT);
pinMode(buzzer,OUTPUT);
Serial.begin(9600);
//Blynk.begin(Serial, auth);
}
void loop()
{
Blynk.run();
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
if (sensorValue < 100){
Serial.println("Fire Detected");
digitalWrite(buzzer,HIGH);
exit(0);
}
digitalWrite(buzzer,LOW);
delay(sensorValue);
}
Aside from the aforementioned total lack of Blynk issue in this topic… unless your buzzer has built in oscillator and just requires power to “buzz”, then it is probably just a simple piezo and requires analogWrite(pwm-capable-pin, value) with value being a PWM range of 0-255 for differing “sounds”.
We’re going to use Blynk to make a disarm button, but we haven’t yet made to that part yet. I’ve followed your advice but it still is not working
Here is the new code:
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#include <BlynkSimpleStream.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken"; //MyAuthToken
int sensorPin = A0;
int sensorValue = 0;
int led = 9;
int buzzer = 12;
BlynkTimer timer;
void myTimerEvent()
{
Serial.println("Team Blynk/Arduino of BSCpE601 AY 2017-2018");
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
if (sensorValue < 100){
Serial.println("Fire Detected");
digitalWrite(buzzer,HIGH);
exit(0);
}
digitalWrite(buzzer,LOW);
delay(sensorValue);
}
void setup()
{
// Debug console
DebugSerial.begin(9600);
// Blynk will work through Serial
// Do not read or write this serial manually in your sketch
Serial.begin(9600);
Blynk.begin(Serial, auth);
// Setup a function to be called every second
timer.setInterval(1000L, myTimerEvent);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}
I’m sorry for the late reply and stating my problem unclear.
My problem is that, the buzzer (piezo) is triggered and buzzes just fine with:
digitalWrite(buzzer,HIGH);
but when this part:
Blynk.begin(Serial, auth);
is uncommented, it stops working all together. Now I have to choose whether to use Blynk or discard it. Here is my new code:
#include<SoftwareSerial.h>
#include "Timer.h"
#include <BlynkSimpleStream.h>
char auth[] = "YourAuthToken"; //My Token Here
Timer t;
int sensorPin = A0; // select the input pin for the LDR
int sensorValue = 0; // variable to store the value coming from the sensor
int led = 9; // Output pin for LED
int buzzer = 11; // Output pin for Buzzer
void setup() {
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(buzzer,OUTPUT);
t.every(1000, checkFire);
Blynk.begin(Serial, auth);
}
void loop()
{
Blynk.run();
t.update();
}
void checkFire(){
sensorValue = analogRead(sensorPin);
if (sensorValue < 100){
digitalWrite(led,HIGH);
digitalWrite(buzzer,HIGH);
Serial.println("1"); //This is used to trigger SendEmail to my python code, how can I make this without it interfering with Blynk?
t.oscillate(led, 500, LOW, 60);
t.oscillate(buzzer, 100, LOW, 60);
digitalWrite(led,LOW);
digitalWrite(buzzer,LOW);
}
digitalWrite(led,LOW);
digitalWrite(buzzer,LOW);
}
Blynk.begin() is a blocking command… which means that the UNO will stop running until it connects to the Blynk Server. This is normal.
So what is probably happening is that you do not have the USB script running on your PC (it is needed to convert the USB link to TCP/IP), or that it is not setup properly.
Also, remember that you will need to run this script (and leave it running) when you want to have the UNO connect to the Server. But stop running the script when you want to program the UNO.
Also, you can NOT use any serial print commands, including the #define BLYNK_PRINT Serial so remove or comment them out.
Okay so it is now working and I can now control both the LED and buzzer with the Blynk. My problem persists though, the buzzer is still not responding to the fire sensor whenever I try to, I think the whole checkFire() method is not working.
Also, when I try to run the script for SendEmail (Which is triggered in the checkFire() method), the console says:
File “build/bdist.linux-armv7l/egg/serial/serialposix.py”, line 501, in read
serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected or multiple access on port?)
The code also uses the same port as Blynk-ser.sh, can you help me on how to make them work alongside each other?
I am unfamiliar with the Mac/Linux script… so I can’t explain why it would interfere with your python script. @Dmitriy, is this something on the Blynk side?
As for the rest, none of your timer or email methods are what Blynk normally use and are completely unfamiliar to me, so you are on your own with them
We recommend using BlynkTimer
And the Email widget
Otherwise the rest is basic programming 101 and mostly up to you to learn.