Hello everyone.
I have project which contains:
- Arduino uno (Connected via USB)
- Buzzer
- HC-SR04 senzor
The main idea is when object is near to sensor buzzer would make sounds and I should get mobile notification.
I prepared project on web site and I added 1 data stream for calculated distance (double). But I can´t get different value
So I my project works only missing part is update on site. I assume script to usb connection work as well (after running a script I see my device online)
This is my current code:
#define BLYNK_TEMPLATE_ID "TMPLG3UKxLkq"
#define BLYNK_DEVICE_NAME "VNOS project"
#define BLYNK_AUTH_TOKEN "******************"
#define BLYNK_PRINT SwSerial
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(10, 11); // RX, TX
#include <BlynkSimpleStream.h>
char auth[] = BLYNK_AUTH_TOKEN;
#define echoPin 7 // Echo Pin
#define trigPin 8 // Trigger Pin
#define LEDPin 13 // Onboard LED
#define buzzer 5 //buzzer pin
int maximumRange = 50; // Maximum range needed
int minimumRange = 0; // Minimum range needed
long duration, distance; // Duration used to calculate distance
BlynkTimer timer;
void myTimerEvent()
{
Blynk.virtualWrite(V6, millis() / 1000);
}
void setup() {
SwSerial.begin(115200);
Serial.begin (9600);
Blynk.begin(Serial, auth);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(LEDPin, OUTPUT);
pinMode(buzzer, OUTPUT);
timer.setInterval(1000L, myTimerEvent);
}
void loop() {
Blynk.run();
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration / 58.2;
if (distance >= maximumRange || distance <= minimumRange) {
//some stuff
}
else {
digitalWrite(buzzer, HIGH);
}
delay(2000);
digitalWrite(buzzer, LOW);
}
If anybody could help me with this that would be awsome.