Hello everyone I would like to ask you for help. I want to make a bidirectional counter with esp8266 using a ultrasound sensor. Then when it reach a certain number to send the data to a database. And then to display the data on webb page as a pop-up. I have litl knowledge about programming I found code for the counter and how to send to databases but I don't know how to combine them.. I spent almost 8 hours on searching but to much for me......
EDIT:I don't uploaded the codes because I am no able to combine them. What I found about sending data to mysql was discussed about other sensors/projects
You can spend Your entire life programming and still have things to learn.
Please read thhe topic "How to get the best from forum". Then update Your post.
I read it but I can't give you the codes if I wasn't able to test it because I can't understand how to put them together. If I omitted something then apologise. My English isn't perfect
If you do not provide the code - so you expect that somebody write a code for you from scratch? This is not a way that the forum works.
Or you can find somebody who do it for you and should be ready to pay for the work.
If you agree with it - I will move you message to Paid Jobs Category of the forum.
Sorry for late reply i didn't had time.I changed ultrasonic to switches and sending counter data to mysql with no issue. But i want to send a text instead of a number for exemple if counter reach 5 then prepare if 10 then start just i can't figure out how to do that.
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <Wire.h>
const char* ssid = "INFOS_Jurcsik";
const char* password = "tojure29het";
const char* serverName = "http://localhost/post-sensor-data.php";
String apiKeyValue = "tPmAT5Ab3j7F9";
String reference = "7590";
String lis = "I7046";
const int buttonPin0 = 0; //D3
const int buttonPin1 = 5; //D1
const int buttonPin2 = 4; //D2
const int buzzerPin = 14; //D5
int currentState0; // variable for reading the pushbutton status
int currentState1; // variable for reading the pushbutton status
int currentState2; // variable for reading the pushbutton status
int pushCounter = 0; // counter for the number of button presses
int resetCounter = 10; // reset counter
int lastState0 = HIGH; // previous state of the button
int lastState1 = HIGH; // previous state of the button
int lastState2 = HIGH; // previous state of the button
void setup() {
Serial.begin(115200);
Serial.println("Push Button Counter");
Serial.println(" ");
pinMode(buttonPin0, INPUT_PULLUP);
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buzzerPin, OUTPUT);
WiFi.begin(ssid, password);
Serial.println("Connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
}
void loop() {
if (pushCounter == resetCounter) {
dataHTML();
tone(buzzerPin, 1500, 300); // buzzer turn on
delay(300);
tone(buzzerPin, 2000, 300);
delay(300);
tone(buzzerPin, 2500, 900);
pushCounter = 0;
}
if (pushCounter <= resetCounter) {
buttons();
}
}
void dataHTML() {
if (WiFi.status() == WL_CONNECTED) {
WiFiClient client;
HTTPClient http;
http.begin(client, serverName);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
String httpRequestData = "api_key=" + apiKeyValue + "&reference=" + reference + "&lis=" + lis + "&batch=" + pushCounter + ""; //String httpRequestData = "api_key=theiotprojects&reference=7590&lis=I7044&pushCounter=12";
Serial.print("httpRequestData: ");
Serial.println(httpRequestData);
int httpResponseCode = http.POST(httpRequestData);
if (httpResponseCode > 0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
} else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
//}
http.end();
} else {
Serial.println("WiFi Disconnected");
//Send an HTTP POST request every 20 seconds
// delay(900);
}
}
void buttons() {
currentState0 = digitalRead(buttonPin0);
currentState1 = digitalRead(buttonPin1);
currentState2 = digitalRead(buttonPin2);
//IF BUTTON '0' AND '1' LOW AND BUTTON 2 HIGHT THEN COUNT +1
if (currentState0 != lastState0) {
if (currentState1 != lastState1) {
if (currentState0 == LOW && currentState1 == LOW && currentState2 == HIGH) {
pushCounter++;
Serial.println(pushCounter);
}
}
}
//IF BUTTON '0' AND '2' LOW AND BUTTON 1 HIGHT THEN COUNT -1
if (currentState0 != lastState0) {
if (currentState2 != lastState2) {
if (currentState0 == LOW && currentState2 == LOW && currentState1 == HIGH) {
pushCounter--;
Serial.println(pushCounter);
}
}
}
lastState1 = currentState1;
lastState2 = currentState2;
delay(50);
}