Hello! I am trying to implement this schema in the arduino MKR1010, the only difference betwen the real arduino version and the schematics is that the power source is of 5v instead of 9.
The problem is when I use the push button it works ok (it activates the pump) but when I push it again it does not turn it off. In the simulation it works perfect (turn off and turn on)
The transistor is a 222A (The complete inscription is PN / 222A / 6E
Please edit your post, select all code and click the </> button to apply so-called code tags and next save your post. It makes it easier to read, easier to copy and prevents the forum software from incorrect interpretation of the code.
Probably not the cause of the problem but your schematic is missing a resistor between pin 12 and the base of the transistor. You're also missing a flyback diode over the motor.
I put the resistor where proposed but nothing changes. When I push the pushboton and the engine starts then it appears the arduino doesn't detect the pushbuton again pin 12 keep having 3,3V.
Even if I disconnect the cable on pin 8 (input which changes the variable to false).
If I use a 1k resistor then the engine works for one second and then stops. When I use the pushbutton again the resistor starts again for one second.
The thing is that if I check the voltage with the multimeter it works just fine: I push the button 0V, I push the button again 5V....
The pumps are this one and in the specifications is stated that works with 5v
(amazon) gp/product/B082PM8L6X/ref=ppx_yo_dt_b_asin_title_o01_s01?ie=UTF8&psc=1
I do not see a pull-up or pull-down resistor on your push button. You need one unless you declare your pin as INPUT_PULLUP to enable the internal pull-up resistor.
Also made the change as blh64 proposed but nothing changes. I added some Serial output and there you can see the difference betwen when I have connected the pump (red square) and when it's not connected (Green square).
I am sure that the problem is my poor knoledge of electronics as it seems as son as I connect the pump the pump itself low the voltage of the input in pin 8.
Your button is wired incorrectly, if wired as shown your power supply would short out.
Remove the 5V line to the button and enable the pull up resistor on the pin mode call.
If you put a 5V signal into a MKR 1010 you will damage it. The biggest voltage you should put in is 3.3V.
Where is your fly back diode?
What power supply do you have?
What is the current capability of it?
Yes I am very new. The idea is that the pin 13 is providing the 3V energy to manage the logic and the base to the transistor.
connected pin 13 to the supply rail of your breadboard?
are connecting a switch between pin 13 and pin 8?
2.Correct. I am using the 8 to detect when I push the pushbutton. When I detect this then I change a boolean variable that activates the high of pin 12. This pin is the one that provides the voltage to activate the transistor.
If in any time you see that it's better that I try more basics circuit it's ok I dont want to lose your time!
int c_outPuls = 13;
int c_outMotor = 12;
int c_inPuls = 8;
int v_pulsador = 0;
bool v_estadoPuls = false;
void setup() {
pinMode(c_outPuls,OUTPUT);
pinMode(c_outMotor,OUTPUT);
pinMode(c_inPuls,INPUT);
Serial.begin(9600);
}
void loop() {
// pin 13 always high
digitalWrite(c_outPuls, HIGH);
v_pulsador = digitalRead(c_inPuls);
//Change variable status . If i read that the voltage of pin 8 is low then I change the variable
if (digitalRead(c_inPuls) == LOW )
{
if( v_estadoPuls == true ){
v_estadoPuls = false;
Serial.println("TurnOff ");
}else
{
v_estadoPuls = true;
Serial.println("TurnOn ");
}
//Delay reading again
delay(1000);
}
if( v_estadoPuls == false ){
digitalWrite(c_outMotor, LOW);
}
else{
digitalWrite(c_outMotor, HIGH);
}
}
You button should be ground on one side and connected to pin 8 on the other with the internal pullup enabled. When using one of those 4 pad buttons, you normally use the diagonal corner pins (either way) so the orientation of the button does not matter. Refer to button #3 below...
Ok I've made this change but I keep having the same problem.
Probably what I am going to say it's stupid but it could be that
Done but it happens the same. The pump works for one second and then stops (the same that would happend if I push the pushbutton). If I push the button again it happens the same: it works for 2s and it stops.
I simplified the code:
#define BUTTON_IN 8
#define POWER_ENGINE 12
int v_buttonIn = LOW;
int v_engineIn = LOW;
bool v_engineActive = false;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(BUTTON_IN, INPUT_PULLUP);
pinMode(POWER_ENGINE, OUTPUT);
}
void loop() {
//When buttonIn = low then change the variable to the opposite
if( digitalRead(BUTTON_IN) == LOW ){
v_engineActive = !v_engineActive;
delay( 1000 );
}
//Activate the power engine when v_engineActive = True
digitalWrite(POWER_ENGINE, ( v_engineActive ) ? HIGH : LOW );
}
You can change POWER_ENGINE to be pin 13 and then watch to see if the on-board LED lights up or not according to your button presses. If that works correctly, then you know you have a power issue for your pump - usually not enough current.
I tested it on a Uno board I have and it works as expected, although the 1s delay after a button push seems odd
Yes that is what the code has been programmed to do.
Remember the loop function does just that, it loops. The only thing slowing it down is that delay.
Finally and I know it's not going to sound good I tried to simplify more the circuit and so I use the 5V output from the arduino itself. Yet this doesn't solved the problem (after 5s the pump stop and it seems it makes the action of the pushbutton).
I tried to add the flyback diode, this didn't solve the problem either.
Finally out of desperation I tried to test again but puting the pump inside the water and ... it works just fine. I dont know if the engine of the pump expects the work and if it is not pumping water provokes a malfunction.
Thank you very much for your help. And for future posts I will try to post schematics instead of the physical schemas.