Uno, MOSFET, Servo.write issue with digital read

I'm STUCK! I posted a short piece of code as an example. The first 3 lines work well. Power up the PIR, read the signal Turn the MOSFET switch on or off. (Powers the servo from the UNO) I need to do the same thing at the same time with the servo.write but I can't for the life of me figure it out since it isn't a digital or analog write. There is bound to be a statement? or maybe even a combo statement to do both at the same time??? Thank you!

void loop() {

  digitalWrite(POWER_PIR, HIGH);  //turns on the PIR

  val = digitalRead(PIR_SIGNAL);   // read the input pin
  digitalWrite(POWER_MOSFET, val);  // sets the MOSFET to the PIRS's value, HIGH or LOW
  
  servo1.write(0);
  delay(100);
  servo1.write(10);
  delay(50);
  

Yes it is

servo1.write(0);

That is all you need to write to the servo!

What else are you expecting to do?

How about an if statement that directs what value to send to the servo depending on what value you read from the sensor?

you mean something like this?

val = digitalRead(PIR_SIGNAL); // read the input pin
if (val==0)
{servo1.write(0)

because it doesn't work!

I have tried several, got any suggestions. remember we're talking servo.write NOT turn the servo ON.

So what does it do?
And what exactly are you trying to do?
Given that you have just used the value of val, to turn off the FET that powers the servo why would you expect any servo movement anyway?

It is quite clear that you have not posted enough information about your project.
Please post the full code, and what you are trying to do along with full schematic.

While you are at it take a read of this:-
(How to get the best out of this forum) before you proceed any further.

well that's another problem in it's self, at the moment the servo is connected directly to a power source. because when I try to power it from the mosfet, it just wigs out. But, it should also STOP sending the servo.write call. I also believe another issue is that I an using delays. so I'll be looking into millis because as I understand it, they don't BLOCK code, Is that correct?

The may or may not block code it depends on how you write them.

Thank you for ignoring my request for all that information that is needed to help you solve your problem. Sorry it is needed because my crystal ball is in for its annual service at the moment.

Maybe you will find some one else who's crystal ball still works.

Good bye.
I will put this thread on mute so I will not see any more posts in it.

1 Like

Whatever Grump!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.