Connecting UNO to RPi via USB link

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);
}

@Joshua_Israel_Albao What for or why are you using Blynk here? Not clear. Do you’ve a UI? I see no UI interaction.

In any case, try to remove all code in your loop() and move it as a routine that can be triggerred using a timer. Let loop() look like

void loop() 
{
   blynk.run();
   timer.run();
}

There are enough examples that show how timers can be used.

Are you getting connected to Blynk? What does the monitor output show?

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 :frowning:

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
}

Well, this forum is for assisting you with learning about and using Blynk… not general programming troubleshooting

For that you could take an online course or something?

Meanwhile… did you read my prior post?

What type of buzzer are you using?

Have you swapped it out with an LED to test the pins, etc.

Add in some DebugSerial.println() comments, assuming you have the proper TTL-USB adapter setup, to track how your program progresses?

Etc.

1 Like

Etc…

This will all be conflicting with your Blynk connection on Serial… as per…

// Blynk will work through Serial
// Do not read or write this serial manually in your sketch

So all should be like this…

#define BLYNK_PRINT DebugSerial
DebugSerial.println("Team Blynk/Arduino of BSCpE601 AY 2017-2018");
DebugSerial.println("Fire Detected");

Etc…

1 Like

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.

Are you using Windows or Apple?

1 Like

I am using Raspberry Pi 3, the Arduino is connected to it. The Arduino is connected to Blynk via Serial USB.

OK, clearly we need more details…

Are you running a Local Server on this RPi?

Is the UNO is connected via USB to the RPi only for Blynk use or are you also programming the UNO from an IDE installed on the RPi?

What are all the versions you are running for

IDE
Blynk App
Blynk Library
Blynk Local Server (if you are using one)

1 Like

Are you running a Local Server on this RPi?

No, I’m using Blynk Cloud as a server

Is the UNO is connected via USB to the RPi only for Blynk use or are you also programming the UNO from an IDE installed on the RPi?

I’m programming UNO from an IDE installed on the RPi

IDE
Blynk App
Blynk Library

IDE: Arduin IDE 1.8.5
BlynkApp: 2.19.2
Blynk Library: Blynk Library 5.1

Thank you for being patient good sir

EDIT: I run the Blynk-ser.sh whenever I want try to connect my Arduino Uno to Blynk. Unfortunately, both the buzzer and Blynk won’t work.

OK, well similar situation still… the UNO talks to the RPi via the USB… but that will not let it go online… so you need to follow these directions

http://help.blynk.cc/how-to-connect-different-hardware-with-blynk/arduino/usb-serial

And follow the Linux / Mac directions. I use Windows, so am unfamiliar with the exact procedure…

However, there have been some recent server changes that may not be reflected in the blynk-ser.sh

So you may need to update to these as well:

SERV_PORT_SSL=8441
SERV_PORT_TCP=80
SERV_PORT_2WAY=8443
LSTN_PORT=80

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.

1 Like

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 :blush:

We recommend using BlynkTimer

And the Email widget

Otherwise the rest is basic programming 101 and mostly up to you to learn.

1 Like