Hi all,
I am involved onto my first project with Arduino, after doing some tutorials found in youtube and in here.
The idea of my project is to automatize the rising of a curtain if I do a clap near the device, and close the curtain if I do another clap. I am using a stepper 28BYJ-48 5V, and sound sensor KY-038.
My problem is that using stepper code and “if” condition (trigger when I clap), the stepper always go forward and automatically goes backward. Looking the serial monitor, I can see the value of the sound sensor is “blocked” in the last value when the trigger started, and I don’t know how to make the sensor read again before starting the backward movement.
int sensorAnalogPin = A0; // Select the Arduino input pin to accept the Sound Sensor's analog output
int analogValue = 0; // Define variable to store the analog value coming from the Sound Sensor.
#include "Stepper.h"
#define STEPS 200
Stepper stepper(STEPS, 8, 10, 9, 11);
void setup()
{
Serial.begin(9600); // The IDE settings for Serial Monitor/Plotter (preferred) must match this speed
stepper.setSpeed(100);
}
void loop(){
analogValue = analogRead(sensorAnalogPin);
Serial.println(analogValue);
if (analogValue>550 || analogValue<530) { //stepper go forward when I clap
stepper.step(1000);
}
if (analogValue>550 || analogValue<530) //stepper SHOULD go backward if I clap again
{
stepper.step(-1000);
}
}
I have the suspect I would need a different condition architecture, but not sure where shoud I start.
Any ideas?
Many thanks!