Trigger a Solenoid with Arduino. Need help please.

Hi everyone!

New here and need help don’t know where to start. :confused:

I have a project that I really don’t know how to accomplish.
I have attached a drawing of it.

A photocell and a mic that would trigger a solenoid and hold it for 1 second. (Verry fast)

Photocell and mic work together to make sure it triggers if the other fails.

Can you program?

Or are you more of a hardware designer?

If not, perhaps you should consider posting in the Gigs forum and paying someone to do this project for you.

ieee488: Can you program?

Or are you more of a hardware designer?

If not, perhaps you should consider posting in the Gigs forum and paying someone to do this project for you.

Thanks! I didn't know there is a Gigs forum.

The photoresistor needs to be part of a voltage divider. It will not work by itself.

Don't put both the mike and LDR to the same pin.

The mike, if just a mike, will likely need amplification to be read by an arduino digital pin. There are available mikes with amps and a comparator with adjustable threshold that have a digital output.

Even small solenoids cannot be driven, directly, by an Arduino pin. A transistor is used to pass current to the solenoid from a suitable power source under control of the Arduino pin. A flyback diode is require to protect the transistor from induced spikes when the solenoid is powered off.

9V transistor batteries will not last long nor will they provide enough current for a solenoid of any size. What are the voltage and current rating for the solenoid?

groundFungus: The photoresistor needs to be part of a voltage divider. It will not work by itself.

Don't put both the mike and LDR to the same pin.

The mike, if just a mike, will likely need amplification to be read by an arduino digital pin. There are available mikes with amps and a comparator with adjustable threshold that have a digital output.

Even small solenoids cannot be driven, directly, by an Arduino pin. A transistor is used to pass current to the solenoid from a suitable power source under control of the Arduino pin. A flyback diode is require to protect the transistor from induced spikes when the solenoid is powered off.

9V transistor batteries will not last long nor will they provide enough current for a solenoid of any size. What are the voltage and current rating for the solenoid?

thanks! @groundFungus

The solenoid is a Mini Push Pull Solenoid Electromagnet, DC 4.5V, 40 g/2 mm.

Amazon Solenoid

seems like you know your stuff what would it take from me for you to create something like this?

I don’t do contact work, but I (and a bunch of other forum members) would be glad to help you with the project. On the face of it it is a pretty easy project

Which parts do you already have?

I suggest that you focus on one part at a time.

Get the photocell working, by itself, and display its output on the serial monitor. Then light an LED when the light is over (or under) a threshold.

Get the mike setup to turn a LED on when the sound level is over a threshold.

Make a driver (transistor and diode) for the solenoid and get the solenoid to fire with the push of a button switch.

Use the millis() function to time the on time of the solenoid (1 second).

Once you understand the individual parts, putting them together will be easier.

What happens after the solenoid is on for one second and goes off? Will there be a wait time before the solenoid is triggered again or can it be triggered right away?

There are tutorials for each part on the web if you look. For the photocell Google “arduino ldr”, for instance.

groundFungus: I don't do contact work, but I (and a bunch of other forum members) would be glad to help you with the project. On the face of it it is a pretty easy project

Which parts do you already have?

I suggest that you focus on one part at a time.

Get the photocell working, by itself, and display its output on the serial monitor. Then light an LED when the light is over (or under) a threshold.

Get the mike setup to turn a LED on when the sound level is over a threshold.

Make a driver (transistor and diode) for the solenoid and get the solenoid to fire with the push of a button switch.

Use the millis() function to time the on time of the solenoid (1 second).

Once you understand the individual parts, putting them together will be easier.

What happens after the solenoid is on for one second and goes off? Will there be a wait time before the solenoid is triggered again or can it be triggered right away?

There are tutorials for each part on the web if you look. For the photocell Google "arduino ldr", for instance.

So this is my parts list.

Pro Micro board https://www.amazon.com/gp/product/B012FOV17O/ref=ox_sc_act_title_1?smid=A2EI6KAMUCDRJD&psc=1

Sonline 50x Through Hole Carbon Film Resistors 220 Ohm https://www.amazon.com/gp/product/B00X9HRKKY/ref=ox_sc_act_title_2?smid=AMRKIIKW22PW7&psc=1

PODOY 20PCS Photoresistor https://www.amazon.com/gp/product/B016D737Y4/ref=ox_sc_act_title_3?smid=A9CRI1JVHA9LE&psc=1

5V Indicator Light LED One 1 Channel Relay Module For Arduino https://www.amazon.com/gp/product/B00P7QDJD2/ref=ox_sc_act_title_4?smid=A1B4V5VJQK2QAS&psc=1

Uxcell a14092600ux0438 Open Frame Actuator Linear Mini Push Pull Solenoid https://www.amazon.com/gp/product/B013DR655A/ref=ox_sc_act_title_5?smid=ATVPDKIKX0DER&psc=1

The photocell will need to be part of a resistor voltage divider to work. The 220 Ohm resistors are way too low in value to use for that. I usually use a 10K resistor.

I have posted before regarding this project not sure how to work this forum cant find my post new here.

Anyways i came up this this set up. with the help of (www.circuito.io)
the only thing what is throwing me off is why isn’t ground connected to the arduino or am i missing something,
it is a correct set up to Trigger solenoid Push-Pull (5v) with a LDR (Mini Photocell)?

Attached is the diagram and code.

parts list

1-Solenoid Push-Pull - 5v (Small)
1-LDR (Mini Photocell)
1-N-Channel MOSFET 60V 30A
1-10K Ohm Resistor
1-Voltage Regulator 5v
1-Electrolytic Capacitor - 1uF/50V
1-Capacitor Ceramic 100nF

Code:

const int ldr = A0; //pin for ldr
const int solenoid = 2; //pin for relay
int value; //variable to save value of ldr
bool trigger = false; //variable to trigger the solenoid


void setup() {
  // put your setup code here, to run once:
pinMode(solenoid,OUTPUT); //setting solenoid as output
Serial.begin(9600); //setting baud rate
}

void loop() {
  value = analogRead(A0); //read the value from ldr and save it to value variable
  Serial.println(value); //printing ldr values on serial monitor
  if(value >= 300){ //if value is greater than 300
    trigger=true; //trigger is true
  }
  if(trigger){ //if trigger is true
    digitalWrite(solenoid,HIGH); //solenoid on
    delay(1000); //wait for a second
    digitalWrite(solenoid,LOW); //solenoid off
  }

}

http://ge.tt/3TCkmCp2

Hi,

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

OPs circuit;
86c59c73ab525f111e3a5a3bce3d5ce73ac7603f.png

Tom… :slight_smile:

Hi, That diagram has many errors. The gnd of the Nano should be connected to the neg/gnd of the supply. A 9V battery will not last long. The solenoid should have a back EMF diode across it. The 5V from the LM7805 should go to the Nano 5V pin, not Vin.

The author of that project does not know much about his project.

Do you have a DMM?

Tom... :)

TomGeorge: Hi, That diagram has many errors. The gnd of the Nano should be connected to the neg/gnd of the supply. A 9V battery will not last long. The solenoid should have a back EMF diode across it. The 5V from the LM7805 should go to the Nano 5V pin, not Vin.

The author of that project does not know much about his project.

Do you have a DMM?

Tom... :)

yes i got a dmm.

how long the battery will last? if it lasts a day with a triggering of about 10 times a day im happy with that.

seriy: how long the battery will last? if it lasts a day with a triggering of about 10 times a day im happy with that.

Depends on the type of battery and the current draw of the solenoid. It might not work at all.

Another error to add to the list. The LDR is also connected wrong. Both LDR and resistor are connected to 5volt. One should go from pin to 5volt, and the other one from pin to ground. Leo..

what about this set up? attached is the diagram. and use a bigger battery or a wall plug.

Thank you!

Please ditch Fritzing NOW. Get a proper schematic drawing program. KiCAD and EagleCAD are just two of many free alternatives, and allow you to draw schematics that are actually readable, have values and other annotations for components, etc.

In your second image you draw a motor, while you said you need a solenoid. That doesn't make sense. In a normal schematic you will just draw a connector and write "solenoid" on it, then it's obvious what's going on. You also miss a flyback diode. Some filtering caps are also useful for motors.

You draw a battery pack - supplying 4.5V - which you don't seem to have connected to the Arduino. Well, maybe you did for GND through that mystery blue block thing? Definitely not for the +4.5V line.

Using a wall power supply is very sensible; if your solenoid needs 5V you can use a regular 5V mobile phone charger (of sufficient current rating). One of the black things, presumably a MOSFET transistor, is gone from your second schematic for whatever reason.

seriy: I have posted before regarding this project not sure how to work this forum cant find my post new here.

I believe this is it. I will ask the Moderator to merge it with this Thread

...R

Threads merged.

wvmarle: Please ditch Fritzing NOW. Get a proper schematic drawing program. KiCAD and EagleCAD are just two of many free alternatives, and allow you to draw schematics that are actually readable, have values and other annotations for components, etc.

In your second image you draw a motor, while you said you need a solenoid. That doesn't make sense. In a normal schematic you will just draw a connector and write "solenoid" on it, then it's obvious what's going on. You also miss a flyback diode. Some filtering caps are also useful for motors.

You draw a battery pack - supplying 4.5V - which you don't seem to have connected to the Arduino. Well, maybe you did for GND through that mystery blue block thing? Definitely not for the +4.5V line.

Using a wall power supply is very sensible; if your solenoid needs 5V you can use a regular 5V mobile phone charger (of sufficient current rating). One of the black things, presumably a MOSFET transistor, is gone from your second schematic for whatever reason.

Since I'm not a pro at creating schematics the drag and drop of Fritzing is just perfect for me. ill try to create a good schematic using a pro cad program.

the mystery blue block thing is a (5V Indicator Light LED One 1 Channel Relay Module For Arduino ARM PIC AVR DSP)

Amazon

Was thinking to use the relay and have it control the solenoid, i will be placing a flyback diode, and supplying the whole system with a wall plug power.

When you look at your own schematics next year, for the lack of any annotation of parts you have no idea of what you actually tried to do, and readability of such wiring diagrams is terrible at best.

If that’s a regular relay module, your Arduino has no power supply whatsoever in this schematic.

Hi,

Can you please post a copy of your circuit, in CAD or [u]a picture of a hand drawn circuit in jpg, png[/u]?

Tom... :)