help!!! i need to finish my project before thursday.
Back to the topic,I want to make a push button that every time you push it ,it will move the servo from 0 to 90 then back to 0 again.
As i tried it,the servo doesn’t move at all
#include <Servo.h>
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include
#include <BlynkSimpleEsp8266.h>
#define SensorPin A0 //pH meter Analog output to Arduino Analog Input 2
#define Offset 0.0 //deviation compensate
#define samplingInterval 20
#define printInterval 800
#define ArrayLenth 40 //times of collection
#define plus D7
#define minus D8
int pHArray[ArrayLenth]; //Store the average value of the sensor feedback
int pHArrayIndex = 0;
int Liquid_level=0;
int pHcurrent1 = 0;
int pHcurrent2 = 0;
int pHyes1 = 0;
int pHyes2 = 0;
char auth[] = "xxxxxxxxxxx";
char ssid[] = "MAKMAL BIO"; //Enter your WIFI Name
char pass[] = "janganmencuri"; //Enter your WIFI Password
Servo myservo1; //acid
Servo myservo2; //alkali
BLYNK_WRITE(V4)
{
myservo1.write(0);
delay(1000);
myservo1.write(90);
delay(1000);
myservo1.write(0);
}
BLYNK_WRITE(V3)
{
myservo2.write(0);
delay(1000);
myservo2.write(90);
delay(1000);
myservo2.write(0);
}
void setup()
{
Blynk.begin(auth, ssid, pass);
Serial.begin(9600);
Blynk.notify("PROJECT IS ONLINE!!!");
pinMode(D1,INPUT);
myservo1.attach(13);
myservo2.attach(15);
}
void loop()
{
Blynk.run();
phsensor();
liquid();
}
void phsensor ()
{
static unsigned long samplingTime = millis();
static unsigned long printTime = millis();
static float pHValue, voltage;
if (millis() - samplingTime > samplingInterval)
{
pHArray[pHArrayIndex++] = analogRead(SensorPin);
if (pHArrayIndex == ArrayLenth)pHArrayIndex = 0;
voltage = avergearray(pHArray, ArrayLenth) * 5.0/4095/6;
pHValue = 6000*voltage + Offset;
samplingTime = millis();
}
if (millis() - printTime > printInterval) //Every 800 milliseconds, print a numerical, convert the state of the LED indicator
{
printTime = millis();
Blynk.virtualWrite(V2,pHValue, 2);
delay(3000);
}
/*else if ( pHyes1 > 0 , pHcurrent1 <= pHValue ){
delay(10000);
Blynk.notify("Value does not change!!!");
pHyes1 = pHyes1 - pHyes1 ;
}
else if (pHyes2 > 0 , pHcurrent2 >= pHValue ){
delay(10000);
Blynk.notify("Value does not change!!!");
pHyes2 = pHyes2 - pHyes2 ;
}
*/
}
double avergearray(int* arr, int number)
{
int i;
int max, min;
double avg;
long amount = 0;
if (number <= 0)
{
Serial.println("Error number for the array to avraging!/n");
return 0;
}
if (number < 5) //less than 5, calculated directly statistics
{
for (i = 0; i < number; i++)
{
amount += arr[i];
}
avg = amount / number;
return avg;
}
else
{
if (arr[0] < arr[1])
{
min = arr[0]; max = arr[1];
}
else
{
min = arr[1]; max = arr[0];
}
for (i = 2; i < number; i++)
{
if (arr[i] < min)
{
amount += min; //arr<min
min = arr[i];
}
else
{
if (arr[i] > max)
{
amount += max; //arr>max
max = arr[i];
}
else
{
amount += arr[i]; //min<=arr<=max
}
}//if
}//for
avg = (double)amount / (number - 2);
}//if
return avg;
}
void liquid (){
Liquid_level=digitalRead(5);
delay(500);
if (Liquid_level == 1 ){
Blynk.notify("PENUH OI");
}
}