24W Linear Solenoid and ADXL335 Accelerometer on Uno R3


I am new here! I’m a mechanical engineer, but I am totally new to the whole electronics side of things. I understand basic circuit design from undergrad, but I am pretty boggled by the whole diode/transistor/inductor world and how to figure out what base-resistor and what ratings are needed for the diode and transistor, based on the power of the solenoid and from the Arduino.

Goal: make a solenoid pull when the system senses a certain acceleration.

What I have: Arduino Uno Rev3, ADXL335 accelerometer on Adafruit breakout board, 24W-6ohm-12VDC linear solenoid, AA battery holders, jumper wires, transistors, diodes, resistors.

What I know(ish):

  1. Connect the ADXL335 acceleration outputs to the analog inputs on the Uno, the Vin input of the ADXL335 to the 5V output of the Uno (the Adafruit breakout board has a voltage regulator for its input and output 3.3V voltage), the 3Vo (vout) output of the ADXL335 board to the AREF input of the Uno, and the GND to GND between them.

  2. Connect 6 AA batteries (9V input to Uno for 5V use) in series and plug into the 2.1 mm port of the Uno, and connect 8 AA batteries in series and connect to the breadboard bus strips for the solenoid’s power supply. Also connect the negative bus rail to GND on the Uno.

What I am confused about (actually):

I know that I need a rectifier diode to prevent damaging the Uno when the field of the solenoid collapses, and I know I need a MOSFET transistor to trigger the solenoid’s current with the Uno’s output pin. I also know that the high lead wire of the solenoid should be connected to the positive bus rail, the base leg of the transistor should be connected to the Uno output pin through a resistor, the collector leg of the transistor should be connected to the low lead wire of the solenoid in parallel with a rectifier diode with the anode on the positive power rail and cathode at the collector terminal strip, and that the emitter leg should be connected to the negative bus rail to go to GND via the wire to the Uno GND.

I do NOT know how to select the correct diode, transistor, and resistor, nor am I confident on how to calculate the current of the solenoid. Since the voltage is 12V and the power draw is 24W, is the current 2A? If I use the TIP120 MOSFET transistor which has a gain of 1000, does that mean I need the current out of the base resistor to be 2 mA? If the current into the base needs to be 2mA and the voltage from the Uno digital output pin is 5V, does that mean the resistor has to be 2500 Ohm? If the solenoid needs 2A to operate at the rated pull force, how much current should the diode be rated for? (is the 1N4004 or 1N4001 sufficient? And if it is taking some of the MOSFET current in parallel with the solenoid/inductor, should the collector actually be higher current than 2A? Like 3A if the diode is taking 1A?) Also, if I am only operating the solenoid 1 time after the ADXL335 shows a certain value range, does that change things?

I know that this is a lot of questions, but hopefully somebody here can help clarify things for me and help me make sure I don’t mess something up.

Thank you!



I saw this circuit diagram online: http://playground.arduino.cc/uploads/Learning/solenoid_driver.pdf
But, I am not sure if the TIP120/Q1 and 1N4004/MUR340 are appropriate for my solenoid, or whether the 1k or 2.2k are appropriate, regardless of if it says there at the bottom that it should work for “up to 24W.”

I “figured” most of this out from:


Also, here is the code that I was thinking of using. If anyone has any advice on this, I would appreciate it.

// global parameters
const int accelerometer = A0; // desired axis acceleration input pin
const int solenoid = 13; // transistor trigger output pin
const int g = 10; // approximate acceleration of gravity in SI

// global variable initializations
int safety = 1; // for using solenoid only one time
int acceleration = 0; // initialize the acceleration variable to 0

// initial setup of pins:
void setup() {
pinMode(accelerometer, INPUT); // set the A0 pin as an input
pinMode(solenoid, OUTPUT); // set the 13 pin as an output

// observation and control
void loop() {
analogReference(EXTERNAL); // for the 3.3 V accelerometer output voltage
if (safety = 1) { // check if the solenoid has already been activated
acceleration = map(analogRead(accelerometer), 0, 1023, -3g, 3g); // read the accelerometer sensed value
if (abs(acceleration) > g/2) { // check if sought acceleration observed
delay(1000); // giving time for a purpose
digitalWrite(solenoid, HIGH); // turn on the solenoid
delay(100); // give solenoid time to fully pull back
digitalWrite(solenoid, LOW); // turn off the solenoid
safety = 0; // remember that the solenoid has been activated
} // end solenoid process
} // continue loop (if safety = 0, no further action occurs)

The TIP120 is a darlington transistor, not a MOSFET and it's going to drop about a volt or more so your 12V solenoid will see about 10 to 11 volts and 85% normal current. Will that work? A logic level MOSFET would be better (almost zero V drop and much less heat).

  if (safety = 1) Oops! "==". Always use code tags ("</>" button) when posting code.

You need a logic level MOSFET, like this one. Drive the solenoid as shown in the schematic below: