Hello people.
I have a problem with the program below.
The sistem is to know whether a particular POS materials of Coca-Cola is being effective or not.
The sensor in ledPin1 is to have flow of people, and others, it is to know whether or not interaction.
The taxaConv variable is to define the relationship between the number of people who have passed in front of the POS and how they interacted with.
I have two problems:
(1) when I try to know the taxConv I have instability in the system and the system does not respond with decimals and the result is passed only with integers;
(2) I do not have a high speed in the flow sensor and thus, lose accuracy;
I appreciate if someone can help me.
There is some suggestion of you?
/**************************************************************
Blynk is a platform with iOS and Android apps to control
Arduino, Raspberry Pi and the likes over the Internet.
You can easily build graphic interfaces for all your
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: http://www.blynk.cc
Blynk community: http://community.blynk.cc
Social networks: http://www.fb.com/blynkapp
http://twitter.com/blynk_app
Blynk library is licensed under MIT license
This example code is in public domain.
**************************************************************
This example runs directly on ESP8266 chip.
You need to install this for ESP8266 development:
https://github.com/esp8266/Arduino
Please be sure to select the right ESP8266 module
in the Tools -> Board menu!
Change WiFi ssid, pass, and Blynk auth token to run :)
**************************************************************/
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
char auth[] = "my code";
WidgetLED led1(V7);
WidgetLED led2(V8);
WidgetLED led3(V9);
WidgetLED led4(V10);
int interacao_pir = 0;
int ledPin1 = D5;
int ledPin2 = 4; // Não funciona com o "D" na frente.
int ledPin3 = D7; // Só funciona com "D" na frente.
int ledPin4 = D6;
int buttonPushCounter1 = 0;
int buttonState1 = 0;
int lastButtonState1 = 0;
int buttonPushCounter2 = 0;
int buttonState2 = 0;
int lastButtonState2 = 0;
int buttonPushCounter3 = 0;
int buttonState3 = 0;
int lastButtonState3 = 0;
int buttonPushCounter4 = 0;
int buttonState4 = 0;
int lastButtonState4 = 0;
int buttonresetState = 0;
int lastButtonresetState = 0;
// Instancia timer
SimpleTimer timer;
// Setup
void setup()
{
pinMode(ledPin1, INPUT);
pinMode(ledPin2, INPUT);
pinMode(ledPin3, INPUT);
pinMode(ledPin4, INPUT);
Serial.begin(9600);
// Blynk.begin(auth, XXXX);
);
Blynk.connect();
while (Blynk.connect() == false) {
// Wait until connected
}
timer.setInterval(1000L, sendUptime);
timer.setInterval(100L, pir1);
// timer.setInterval(1000L, pir2);
// timer.setInterval(1000L, pir3);
// timer.setInterval(1000L, pir4);
//timer.setInterval(10000L, conv);
}
void sendUptime()
{
Blynk.virtualWrite(V0, millis() / 1000);
Blynk.virtualWrite(V5, (interacao_pir = buttonPushCounter2+buttonPushCounter3+buttonPushCounter4));
Serial.println(interacao_pir);
}
void pir1() {
//while (buttonresetState == LOW){
// read the pushbutton input pin:
buttonState1 = pulseIn(ledPin1,LOW);
// Serial.print("Tempo = ");
// Serial.println(buttonState1);//}
// compare the buttonState to its previous state
if (buttonState1 != lastButtonState1) {
// if the state has changed, increment the counter
if (buttonState1 != 0) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter1++;
led1.on();
} else {
// if the current state is LOW then the button
// wend from on to off:
buttonPushCounter1;
}
// Delay a little bit to avoid bouncing
Blynk.virtualWrite(V1, buttonPushCounter1);
}
// save the current state as the last state,
//for next time through the loop
led1.off();
lastButtonState1 = buttonState1;
//}
//void pir2() {
// read the pushbutton input pin:
buttonState2 = digitalRead(ledPin2);
// compare the buttonState to its previous state
if (buttonState2 != lastButtonState2) {
// if the state has changed, increment the counter
if (buttonState2 == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter2++;
led2.on();
} else {
// if the current state is LOW then the button
// wend from on to off:
buttonPushCounter2;
}
// Delay a little bit to avoid bouncing
led2.off();
Blynk.virtualWrite(V2, buttonPushCounter2);
}
// save the current state as the last state,
//for next time through the loop
lastButtonState2 = buttonState2;
//}
//void pir3() {
// read the pushbutton input pin:
buttonState3 = digitalRead(ledPin3);
// compare the buttonState to its previous state
if (buttonState3 != lastButtonState3) {
// if the state has changed, increment the counter
if (buttonState3 == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter3++;
led3.on();
} else {
// if the current state is LOW then the button
// wend from on to off:
buttonPushCounter3;
}
// Delay a little bit to avoid bouncing
Blynk.virtualWrite(V3, buttonPushCounter3);
}
// save the current state as the last state,
//for next time through the loop
led3.off();
lastButtonState3 = buttonState3;
//}
//void pir4() {
// read the pushbutton input pin:
buttonState4 = digitalRead(ledPin4);
// compare the buttonState to its previous state
if (buttonState4 != lastButtonState4) {
// if the state has changed, increment the counter
if (buttonState4 == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter4++;
led4.on();
} else {
// if the current state is LOW then the button
// wend from on to off:
buttonPushCounter4;
}
// Delay a little bit to avoid bouncing
Blynk.virtualWrite(V4, buttonPushCounter4);
}
// save the current state as the last state,
//for next time through the loop
led4.off();
lastButtonState4 = buttonState4;
// RESET VOID
// read the pushbutton input pin:
BLYNK_WRITE(V6) //Button Widget is writing to pin V6
{
int buttonresetState = param.asInt();
Blynk.virtualWrite(V7, buttonresetState);
// compare the buttonState to its previous state
if (buttonresetState == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
int interacao_pir = 0;
int buttonPushCounter1 = 0;
int buttonPushCounter2 = 0;
int buttonPushCounter3 = 0;
int buttonPushCounter4 = 0;
Blynk.virtualWrite(V1, buttonPushCounter1);
Blynk.virtualWrite(V2, buttonPushCounter2);
Blynk.virtualWrite(V3, buttonPushCounter3);
Blynk.virtualWrite(V4, buttonPushCounter4);
Blynk.virtualWrite(V5, interacao_pir);
Blynk.syncAll();
}
buttonresetState=LOW;
}
// TAX OF CONVERSION VOID
// read the pushbutton input pin:
BLYNK_WRITE(V12) //Button Widget is writing to pin V6
{
int buttonConvState = param.asInt();
// compare the buttonState to its previous state
if (buttonConvState == HIGH) {
int taxaConv = (( (buttonPushCounter2+buttonPushCounter3+buttonPushCounter4)/buttonPushCounter1));
Blynk.virtualWrite(V11, taxaConv);
Serial.println(taxaConv);
}
buttonConvState=LOW;
}
void loop()
{
Blynk.run();
timer.run(); // Initiates SimpleTimer
}
IMG_0067.PNG