The problem is: a steppermotor is activated when it should not be activated because the conditions are not met yet.
I am using a slide potentiometer, an LDR (GL5528 LDR) to set the conditions.
So, the steppermotor only should be activated when the potentiometer value reads <10, the boolean pot2 == true and when the LDR value <500 (when it is covered).
When I run the program and the potentiometer reads a potvalue> 10 and the LDR value < 500, the steppermotor is not supposed to run, since the potmeter reads a value which is too high. However, in my case the steppermotor starts moving anyway.
In the attachment which is called Hot Beverage Machine option 2 you can see my full code.
Because this code did not work, I tried to test this separately in another code.
Here I used the same technique, with the same conditions in the if statement. In this separate code the steppermotor did activate on the right moment with the correct conditions.
This code can be found in the attachment as well and it is called Stepper motor test HBM.
I think it has to do with the fact that in my Hot Beverage Machine option 2 I use two if statements in the void loop and that they interferes with each other?...
If someone could help me out, that would be great!
Yes, I have already tested the potentiometer values and the LDR values separately to decide which values I wanted to have as ''bounderies''. The LDR values are also adapted to the light environment the LDR is in, so these values are correct.
But I just cannot figure out why in my ''stepper motor test HBM'' code test the steppermotor is activated when the correct conditions are met and in my ''Hot Beverage Machine option 2'' code this is not the case even though I use the same conditions.
I believe he meant that you should have code in your misbehaving program that prints the value from the pot and the LDR immediately before those values are used in the IF test so that you can see what the test is actually working with.
Ahh thank you!
I just printed both values. Right before my steppermotor starts moving (incorrectly) the potmeter reads a value of 976 and the LDR value reads a value of 497. This is not corresponding with the conditions in the if statement.
edit: with ''right before...'' I meant that these were the last two values that were read before the steppermotor actually started moving.
As you might see, in my ''Hot Beverage Machine option 2'' code, I use booleans pot1, pot2 and pot3.
I used these booleans to let the codes only run once. When these codes have run,
these booleans become false. As soon as the LDR value is in open light again with sensorvalue >650, the booleans pot1, pot2 and pot3 should become true again, so the codes can be run again.
However, when my full code has run once and the LDR has a sensorvalue>650 again, I am not able to run my code again. I honestly do not know what is causing this problem.... Any advice/tips on this as well?
UKHeliBob:
Did you mean to digitalWrite() tp the LED pins ?
About this: Yes I did, stupid mistake. Haven't focused on the LED system yet!
UKHeliBob:
Why subtract a float from it ?
And about this: I want the servo to move back in little steps of 2.3 . Is this incorrect? and if so, what do you advise me to do?
edit: Ooooh i think I understand now, it is weird to substract a float from a int... so I should make a float of the x like this : float x = 90;
And about this: I want the servo to move back in little steps of 2.3 . Is this incorrect? and if so, what do you advise me to do?
edit: Ooooh i think I understand now, it is weird to substract a float from a int... so I should make a float of the x like this : float x = 90;
Lots wrong here.
servo.write() takes an integer of between 0 and 180 as its argument, not a float. Using servo.write() you can only move in steps of 1 between 0 and 180 but note that not all servos actually move through 180 degrees.
To move the servo in smaller steps consider using servo.writeMicroseconds() with values between 1000 and 2000 which gives you a possible 1000 steps
UKHeliBob:
To move the servo in smaller steps consider using servo.writeMicroseconds() with values between 1000 and 2000 which gives you a possible 1000 steps
chineesinspace:
Unfortunately I just noticed another problem....
As you might see, in my ''Hot Beverage Machine option 2'' code, I use booleans pot1, pot2 and pot3.
I used these booleans to let the if-statements only run once. When these codes have run,
these booleans become false. As soon as the LDR value is in open light again with sensorvalue >650, the booleans pot1, pot2 and pot3 should become true again, so the codes can be run again.
However, when my full code has run once and the LDR has a sensorvalue>650 again, I am not able to run the if-statements depended on pot1 and pot3 again. I honestly do not know what is causing this problem.... Any advice/tips on this as well?
I have checked and the pot1 and pot3 are correctly made true again by the LDR. This is indeed the case.
Also checked if the if-statements depended on pot1 and pot3 would run again after they have run once before. It became clear that these statements aren't running again.