H-Bridge for Project not Working

Hello, I require an H-Bridge to drive a solenoid valve I am using in another project and wanted to use on I received in an Arduino Starter kit. I previously worked on the starter kit's project 10 and never got it to work but I blamed the push buttons. Now, in trying my new project and using the motor as a placeholder for the valve I run into the same issue which I believe is related the h-bridge. I have an example of my original Code and the test Code for the h-bridge I used as well as the wiring on the breadboard incase any mistake was made their. I am a beginner in working with electronics so I am very open to any criticism and don't doubt I made a mistake but I cannot see one as of right now and with double checking. Any help is greatly appreciated and I a want to say thanks in advance.


'Test Code:' 
void setup() {
digitalWrite(4, HIGH);
digitalWrite(8, HIGH);
digitalWrite(7, LOW);

'Original Code:'
//#include <LowPower.h>
const int enablePin=4;
const int onPin=8;
const int offPin=7;
const int soilSensor=A0;
int moisture=0;
unsigned long prevTime=0;
int interval=10000;
int soilAverage;
int i;

void setup() {
    Serial.begin(9600);
    pinMode(7, OUTPUT);
    pinMode(8, OUTPUT);
    pinMode(9, OUTPUT);
    digitalWrite(onPin, LOW);
    digitalWrite(offPin, LOW);
    digitalWrite(enablePin, LOW);
}

void loop() {
  soilAverage=0;
  i=0;
  while (i<5){
    moisture=analogRead(soilSensor);
    soilAverage+=moisture;
    i+=1; 
    delay(50);
    }
  soilAverage=soilAverage/i; 
    Serial.print("Soil Average Mositure:");
      Serial.println(soilAverage);
  if(soilAverage<600&soilAverage>100){
    digitalWrite(enablePin,HIGH);
      digitalWrite(onPin,HIGH);
        delay(4000);
      digitalWrite(onPin,LOW);
      Serial.println("Turned ON");
        delay(10000);  /*delay(600000);*/
      digitalWrite(offPin,HIGH);
          delay(4000);
      digitalWrite(offPin, LOW);
    digitalWrite(enablePin, LOW);
  Serial.println("Turned OFF");
  }
   if (soilAverage<100){
    Serial.println("Soil Sensor HAS ERROR");
  }
      delay(100);
       /* put sleep mode here */
  }

  


}```

Please post a link to the valve, and state which H-bridge chip you have. It is likely that they are incompatible.

Also, it is unlikely that anyone will be interested in figuring out the problem with the nest of wires shown in the photo.

Instead, please post a hand-drawn wiring diagram showing all the connections, with each pin number and part clearly labeled.

Be sure to show how everything is powered. The Arduino 5V output cannot be used for motors, servos or solenoids. Avoid the many bad tutorials that suggest otherwise.

Hi jremington,

The solenoid valve is a hunter latching but that was not hooked up to the circuit I posted. The circuit was just a basic motor from project 10 of the arduino starter kit. Additionally, the power supply for the circuit is from a 9v battery with my arduino powering pin 9 on the h bridge only. I will post a circuit drawing as soon as I get the chance and add ito this comment but my main thought was my circuit was correct in following the project 10 guidelines for the h bridge connections meaning the only error was in my actual circuit, the code, or in the h bridge.


9V PP3 batteries do not supply enough current to operate most motors or solenoids. Use a 6xAA battery pack instead, or a 9V DC wall wart power supply capable of 1 or more Amperes.

The solenoid valve is a hunter latching

That is not helpful. Post a link to the data sheet or product page. Also state the exact designation of the H-bridge IC. There are many different types.

The H-Bridge(L293D) used:https://www.ti.com/product/L293D

The solenoid(the datasheet is very bare minimum but from other searching I believe it requires around 0.3 amps and 6-9v DC):https://www.hunterindustries.com/sites/default/files/CA-Cutsheet-DC-Solenoids-Additional-Data-US.pdf

For the battery point you brought up: I have tested both the solenoid and motor and they can be run off the batteries power. Additionally, the solenoid I use has a controller that could be bought which uses 9v batteries like the one I have and the motor was included with 9v battery snaps. So, both of these items I believe are capable of being run off one or should be atleast. Additionally, I agree with your point on the battery and I don’t intend for this to be my final power source. The project is supposed to be solar powered so I will try and find a rechargeable battery for the voltage supply.

For a few minutes, with a fresh battery and a direct connection.

Unfortunately, that particular H-bridge IC design is over 30 years old and extremely inefficient. Around 1/3 to 1/2 of the battery voltage is internally wasted as heat (that is, if you have wired it correctly), so in many cases not enough voltage will be left over to actually drive the motor.

The diagram you posted is helpful, but does not show all the connections. Did you connect the 9V battery negative to the Arduino and motor driver GND pins?

Finally, it is not clear that you are writing the correct logic levels to the motor control pins. According to the wiring diagram, you are using pins 7, 8 and 9 to control the driver, but the code refers to the following pins by name. What is pin 4 (enabelPin) doing?

const int enablePin=4;
const int onPin=8;
const int offPin=7;

Thank you for your responses and help btw. I did connect the grounds together for the arduino,motor, and driver and the pin 4 being enabled is what was connected to pin 1 of the h bridge. I originally had it as my arduino pin 9 aswell but switched it for an easier picture of the bread board so that was my error in not correcting it.
Edit: I ’mistyped pin 1 on h bridge as pin 9 and I fixed it

Sorry, I don't understand either your description of the wiring or the posted diagram, which is incomplete and misleading.

You need to make very clear which Arduino pin is connected to which IC pin, and that those pins are clearly identified in the program, with meaningful names. All power and ground wiring must be represented in the diagram.

I recommend to start over with the code, using a much simpler program to test motor functions.

The code I used was just

digitalWrite(4, HIGH); //the pin for pin 1 on h bridge//
digitalWrite(7, LOW); // the pin for 2 on h-bridge
digitalWrite(8, HIGH);// the pin for 7 on h-bridge

My apologies on when I wrote my correction- I confuse the h bridge names sometimes and meant my arduino pin 9 originally went to pin 1 on the h bridge but then I switched arduino pin 9 to arduino pin 4

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