enter image description here I am attempting to create an electromagnetic paper airplane launcher. I am using a hall effect sensor to detect when a sled is passing a solenoid. I am using an Arduino Uno as my microcontroller so that once the hall effect sensor detects a magnetic field, an output voltage would be supplied to the gate pin on a logic-level n channel MOSFET.

As a safety feature, I have added a push-button. In my Arduino code, I am only allowing for the MOSFET to receive an input voltage once the button is being pressed and the hall effect sensor reads a magnetic field.

I tested everything today and found that current will be supplied to the solenoids as intended, but it will also be supplied when a magnetic field is present without having the button pressed.

I am not sure if this is a coding problem or not. Before hooking the solenoid to the mosfet, I used an led in place of it in order to see if anything was being sent through the MOSFET. When I used the LED, it worked as intended--only turning on when a magnetic field was present and the button was pressed down.

I was just wondering if anyone knew what might be happening when I changed the LED with a copper wire solenoid.

Here is my code:

int coil=1;//solenoid 1
int hs=2;//1st hall effect sensor

int button=3;

int coil2=4;//solenoid 2
int hs2=5;//2nd hall effect sensor

void setup() {
//establishes the hall effect sensor pins as input, the button pin as input, and the solenoid pin as output
pinMode(hs, INPUT);
pinMode(coil, OUTPUT);

pinMode(hs2, INPUT);
pinMode(coil2, OUTPUT);

pinMode(button, INPUT);

void loop() {
  if ((digitalRead(button)==HIGH)&&(digitalRead(hs)==LOW))//makes sure that the mosfet will only send current to solenoid once the button has been 
  {                                                       //been pressed and the hall effect sensor has been triggered.
    digitalWrite(coil, HIGH);
    digitalWrite(coil, LOW); 

    digitalWrite(coil2, LOW); 

  • 1
    \$\begingroup\$ Welcome! Please post a schematic. \$\endgroup\$
    – winny
    Nov 4, 2022 at 15:21
  • 2
    \$\begingroup\$ the schematic shows the FET wired in a strange way, with gate and drain shorted. Is that accurate? \$\endgroup\$
    – tobalt
    Nov 4, 2022 at 17:53
  • 1
    \$\begingroup\$ @SamRembold But that makes even less sense. A MOSFET with drain and source shorted is just a small capacitor \$\endgroup\$
    – tobalt
    Nov 4, 2022 at 17:57
  • 1
    \$\begingroup\$ That MOSFET has no ground reference. No wonder you can't control it. Its source needs to be connected to the system's ground. \$\endgroup\$ Nov 4, 2022 at 18:42
  • 3
    \$\begingroup\$ There are still too many mistakes in the schematic to provide any answer. You still have a 330 ohm resistor on the MOSFET but it appears to be shorted. The drain just goes to a capacitor. The 3.3V and 5V pins of the Arduino are shorted, PWM D3 goes to GND. The pushbutton has a 330 ohm resistor on the contacts, which go to Vcc and GND. \$\endgroup\$
    – PStechPaul
    Nov 7, 2022 at 1:38


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.