Help with project

BlynkTimer timer;

void emailOnButtonPress()
{
 //  *** WARNING: You are limited to send ONLY ONE E-MAIL PER 15 SECONDS! ***
 //  ***AND 100 emails per day on blynk-cloud.com Server!!

//   Let's send an e-mail when Analog value is >100

  int isButtonPressed = 0; // Invert state, since button is "Active LOW"

int x=analogRead (A0);
  if (x>100) // You can write any condition to trigger e-mail sending
  {
    Serial.println("Button is pressed."); // This can be seen in the Serial Monitor
    Blynk.email("********@gmail.com", "Subject: Button Logger", "ITEM STOLEN");

    // Or, if you want to use the email specified in the App (like for App Export):
    //Blynk.email("Subject: Button Logger", "You just pushed the button...");
  }
  else
    {
       Serial.println("Button is NOT pressed.");
    }
}


void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  // Send e-mail when your hardware gets connected to Blynk Server
  // Just put the recepient's "e-mail address", "Subject" and the "message body"
  Blynk.email("**********@gmail.com", "Subject", "My Blynk project is online.");

  // Setting the button
  pinMode(A0, INPUT_PULLUP);

// Setup a function to be called every 15 seconds (see warning in function above)
  timer.setInterval(15000L,emailOnButtonPress);
}

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

that code did not work for some reason

Did you add BlynkTimer timer;?

I think you need to do a little homework, and learn about the simple timer library, which the BlynkTimer is based on. Especially if you plan on using Blynk. It is the most important concept to understand for well performing Blynk code.

Ok, so the code worked but for some reason the force sensor was always on max value of 1024 (without me touching it) and did not work like with the first code i sent maybe it’s got something to do with the connections, although last time it worked normally anyone knows how to solve this? image

image

image

wiggle the wires, check resistor values, etc.? We really cant help in that department. The code you are running does not effect the value being read.

ok, so we added a buzzer and a LED to the code for our project but the thing is we cannot use void loop because of blynk.run and we need the LED and the Buzzer (simultaneously) to keep blinking while the code is active how do we do that? (we don’t want to just write the same thing 20 times)

/* Set this to a bigger number, to enable sending longer messages */
//#define BLYNK_MAX_SENDBYTES 128

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "******************************";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "***********";
char pass[] = "*************";
BlynkTimer timer;

void emailOnButtonPress()
{
 //  *** WARNING: You are limited to send ONLY ONE E-MAIL PER 15 SECONDS! ***

//   Let's send an e-mail when you press the button
 //  connected to digital pin 2 on your Arduino

  int isButtonPressed = 0; // Invert state, since button is "Active LOW"
  const int buzzer = D8;
  pinMode(D7, OUTPUT);

int x=analogRead (A0);
  if (x>100) // You can write any condition to trigger e-mail sending
  {
    Serial.println("Button is pressed."); // This can be seen in the Serial Monitor
    Blynk.email("**************@gmail.com", "Subject: Button Logger", "ITEM STOLEN");
    pinMode(buzzer, OUTPUT);
  tone(buzzer, 10000); // Send 1KHz sound signal...
  digitalWrite(D7, HIGH);

    // Or, if you want to use the email specified in the App (like for App Export):
    //Blynk.email("Subject: Button Logger", "You just pushed the button...");
  }
  else
    {
       Serial.println("Button is NOT pressed.");
  noTone(buzzer);     // Stop sound...
  digitalWrite(D7, LOW);
    }
}
void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(***,***,*,***), ****);

  // Send e-mail when your hardware gets connected to Blynk Server
  // Just put the recepient's "e-mail address", "Subject" and the "message body"
  Blynk.email("**************@gmail.com", "Subject", "My Blynk project is online.");

  // Setting the button
  pinMode(A0, INPUT_PULLUP);
  

// Setup a function to be called every 15 seconds (see warning in function above)
  timer.setInterval(15000L,emailOnButtonPress);
}

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

i thought i could open another { } in the loop but didn’t have the chance to check it out yet so i’m not sure

also big thanks to the people that told me to remove everything from the loop because i was stuck on that code for over a 2 weeks

You could use a Blynk timeout timer, or start a regular timer then delete it, but that might be a bit too difficult with your current coding skills.

The other option is to use a library like “Ticker”. If you google it you’ll find information about how to install the library and how to start and stop a ticker that will flash your LED and sound your buzzer.
Take a look at this bit of code where I use Ticker to flash an LED when required:

Pete.

i had a little time and i did some tests and i found a way to make it work like that :
tell me what you think if it’s ok

/* Set this to a bigger number, to enable sending longer messages */
//#define BLYNK_MAX_SENDBYTES 128

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "*********************";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "***********";
char pass[] = "*****************";
BlynkTimer timer;

void emailOnButtonPress()
{
 //  *** WARNING: You are limited to send ONLY ONE E-MAIL PER 15 SECONDS! ***

//   Let's send an e-mail when you press the button
 //  connected to digital pin 2 on your Arduino

  int isButtonPressed = 0; // Invert state, since button is "Active LOW"

int x=analogRead (A0);
const int buzzer = D8;
  pinMode(D7, OUTPUT);
  pinMode(buzzer, OUTPUT);
  if (x>100) // You can write any condition to trigger e-mail sending
  {
    Serial.println("Button is pressed."); // This can be seen in the Serial Monitor
    Blynk.email("**********@gmail.com", "Subject: Button Logger", "ITEM STOLEN");

    // Or, if you want to use the email specified in the App (like for App Export):
    //Blynk.email("Subject: Button Logger", "You just pushed the button...");
  }
  else
    {
       Serial.println("Button is NOT pressed.");
  noTone(buzzer);     // Stop sound...
  digitalWrite(D7, LOW);
    }
}
void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

  // Send e-mail when your hardware gets connected to Blynk Server
  // Just put the recepient's "e-mail address", "Subject" and the "message body"
  Blynk.email("*************@gmail.com", "Subject", "My Blynk project is online.");

  // Setting the button
  pinMode(A0, INPUT_PULLUP);
  

// Setup a function to be called every 15 seconds (see warning in function above)
  timer.setInterval(15000L,emailOnButtonPress);
}

void loop()
{
  int x=analogRead (A0);
  const int buzzer = D8;
  pinMode(D7, OUTPUT);
  pinMode(buzzer, OUTPUT);
  if (x>100) // You can write any condition to trigger e-mail sending
  {
   tone(buzzer, 10000); // Send 1KHz sound signal...
  digitalWrite(D7, HIGH); 
  delay(100);
  noTone(buzzer);     // Stop sound...
  digitalWrite(D7, LOW);
  delay(100);

    // Or, if you want to use the email specified in the App (like for App Export):
    //Blynk.email("Subject: Button Logger", "You just pushed the button...");
  }
 
  Blynk.run();
  timer.run();
}

Your solution to your newest problem is to ignore the advice given, and put lots of junk back in your void loop!

What do you think to that approach?

Pete.

i mean it works and i didn’t ignore the advice given i just didn’t understand it so i found another way

If you aren’t able to work out how the Ticker library from the code example I linked and by searching the internet for Ticker examples the you’d be better to come back here with a question about that, explaining what it is that you’ve tried and what hasn’t worked.

If you don’t want people to tell you what they think of your code then don’t ask the question!"

I’ll mark this topic as “Solved” as you’ve clearly solved your original issue and seem happy with your solution to the follow-up problem.

Pete.

closing the thread just because i didn’t use your advice and done something by my self my project isn’t complete so i will propably need more help (btw from the way you write things you look really triggered about someone that doesn’t do what you say) so don’t abuse your power and reopen this.

The thread isn’t closed, it is now categorised as ‘solved’, because you said:

and

If you want to change the category back you can, simply click the pencil icon next to title and choose from the list of available categories then press the :heavy_check_mark: icon to save the change.

I’m sorry that you don’t like my style - I’ll step back and let others help you in future.

Good luck with your project.

Pete.

1 Like

for anyone that wants to do the same thing as me or smh, you got the code and the build now btw it is not arduino leonardo i just couldn’t find wemos D1

@Dedi, as I mentioned before:

Once you have a grasp on how the timer library works, you can then solve your issue of:

Heck there are probably some examples of similar tasks somewhere on this forum, but without knowing how it functions you will not be able to adapt it to your needs, or even know example to look for.

Or you can do as @PeteKnight suggested:

If you do not want to take the time to further your knowledge of either, or both, of these suggestions, then you will not make it too far in the BLYNK world.

The solution you came up with may get you through this simple task, but it will not work for more advanced BLYNK projects.

Don’t assume your persecution, the topic was never closed nor was anything forced upon you. If you wish to ignore sage advice and find flawed workarounds, then that it your right… just don’t push the faulty methods here where others are trying to learn the proper way to use Blynk, timers, “background” operations, etc.