Question: This the code im working on it. Code isn't work properly. Idea is running stepper motor with water sensor in arduino. When it rains to
This the code im working on it. Code isn't work properly. Idea is running stepper motor with water sensor in arduino. When it rains to water sensor, stepper motor must go forward and when it dries then stepper motor must go backwards but instead it goes always backwards when the rain dropped the water sensor. How can i solve it?
//This header file is used to write , update and read data in the Arduino UNO. #include
//Global variables. int address = 0; int addr = 0;
int sensorValue = analogRead(A0);
//One of the basic method of Arduino UNO. void setup() { Serial.begin(9600); int i; for (i = 8; i < 12; i++) { pinMode(i, OUTPUT); }
}
//Method stepforward() can rotate the stepper motor in clockwise direction. void stepforward() { int sensorValue = analogRead(A0); Serial.println("stepforward"); Serial.println(sensorValue); Serial.println("yooooooooooo"); for(int i=0 ; i<100;i++) { if(i==99) { stopMotor(); } Serial.println(i); Serial.println(sensorValue); //Forward Rotation stepper motor. digitalWrite(8, HIGH); digitalWrite(9, LOW); digitalWrite(10, LOW); digitalWrite(11, LOW); delay(30); digitalWrite(8, LOW); digitalWrite(9, HIGH); digitalWrite(10, LOW); digitalWrite(11, LOW); delay(30); digitalWrite(8, LOW); digitalWrite(9, LOW); digitalWrite(10, HIGH); digitalWrite(11, LOW); delay(30); digitalWrite(8, LOW); digitalWrite(9, LOW); digitalWrite(10, LOW); digitalWrite(11, HIGH); delay(30); } }
void stopMotor() { int sensorValue = analogRead(A0); Serial.println("Inside StopMotor"); Serial.println(sensorValue); while(sensorValue>900) { int sensorValue = analogRead(A0); Serial.println(sensorValue); Serial.println("StopMotor"); delay(200);
if(sensorValue<900) { loop(); } } if(sensorValue<900) { loop(); } }
//stops stepper motor once it pull or push the clothes void stopMotorDry() { int sensorValue = analogRead(A0); Serial.println("Inside StopMotor Dry"); Serial.println(sensorValue);
while(sensorValue<900) { int sensorValue = analogRead(A0); Serial.println(sensorValue); Serial.println("StopMotorDry"); delay(1000); if(sensorValue>900) { Serial.println("sensorValue>900"); loop(); } } if(sensorValue>900) { loop(); } }
//Method stepbackward() can rotate the stepper motor in anticlockwise direction. void stepbackward() { int sensorValue = analogRead(A0); Serial.println("stepbackward");
//this for loop can be adjusted depending on need of number of rotation for(int i=0 ; i<100;i++) { Serial.println(i); //this 'if' condition helps to keep the stepper motor in stop mode by calling stopMotorDry() method. if(i==99)\ { Serial.println("stepbackward if"); // calling stop method. stopMotorDry(); }
Serial.println(sensorValue); Serial.println("inside for"); //Backward Rotation stepper motor. digitalWrite(8, LOW); digitalWrite(9, LOW); digitalWrite(10, LOW); digitalWrite(11, HIGH); delay(30); digitalWrite(8, LOW); digitalWrite(9, LOW); digitalWrite(10, HIGH); digitalWrite(11, LOW); delay(30); digitalWrite(8, LOW); digitalWrite(9, HIGH); digitalWrite(10, LOW); digitalWrite(11, LOW); delay(30); digitalWrite(8, HIGH); digitalWrite(9, LOW); digitalWrite(10, LOW); digitalWrite(11, LOW); delay(30); } }
void loop() { int updateValue=1; //value 1 show that clothes are inside int value = 4; //value 4 show that clothes are outside
// storing analog value of Rain Drop sensor. int sensorValue = analogRead(A0); // EEPROM.write(addr, value); // you need to run this code for the 1st time only so that memory can store a number which help in deciding the status of clothes. Serial.print(value, DEC); Serial.println(); value = EEPROM.read(address);
// checking weather condition and cloths status. if(sensorValue>900 && value==4) { //updating status of cloth so that in case of power failure device remember its state EEPROM.update(address, updateValue); Serial.println("greater than 900"); stepforward(); //Repeats the required sequence over & //over to make the motor turn continuously Forward Rotation. } // checking weather condition and cloths status. if(sensorValue<900 && value==1) {>
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
