another question about solenoids and power

Hi.
I have built a photoresistor activated solenoid circuit and it works if Arduino is powered from usb and Solenoid is powered from 12v wall power.
I have a power problem.
What I want to do is power the Arduino board from the wall.
The wall wart has 12v and 5v DC out (5v is currently unused).
If I use the barrel connector as 12 v to the arduino then arduino works but solenoid doesn't fire.
How do I get my Arduino to run and my solenoid to run off of wall power?
Haven't figured out how to upload a pic here so I posted at flickr:

Imgur

Wrong polarity on the barrel jack? My best guess.

If the 5V is well regulated, you can wire that straight into the +5V pin on the Arduino, and use the 12V for the Solenoid.

Else use a splitter to break the single barrel connector 12V to both the Arduino and the Solenoid. Make sure to get the ground right for both :slight_smile:

OK, so i finally bought a small multimeter and found my voltages were switched.
I've verified that 5v is powering the arduino (and it is working through the barrel jack). 12v is for the solenoid and it isn't working.
If the lights go out the arduino fires the led which tells me that the solenoid should fire too but no luck.

dean123:
OK, so i finally bought a small multimeter and found my voltages were switched.
I've verified that 5v is powering the arduino (and it is working through the barrel jack). 12v is for the solenoid and it isn't working.
If the lights go out the arduino fires the led which tells me that the solenoid should fire too but no luck.

First, 5V on the barrel means at best 4.5V, and more likely 3.5V for the Arduino. The chip will actually run on that voltage, but not as fast as on 5V, and if the clock is still trying for 16 MHz, you're in marginal territory.

Second, what's the driving the Solenoid when the Arduino LED lights up? Are you using a MOSFET, or some other switching mechanism? You can't run 12V straight through an Arduino pin, and you can't run the current of a Solenoid straight through an Arduino pin, either.

I'm using the mosfet for a switch.

Here's the code so you can see inputs and outputs- like I said earlier- if the arduino is powered via usb (ie I don't use the barrel jack) then it all works.

I figured it is easier to post the code than to explain the inputs and outputs...
// read a photo diode
// turn on an indicator LED and activate a solenoid

const int LED=9; // the output pin for the LED
const int SOLENOID=10; // the output pin for the Solenoid
const int LIGHTVAL=512; // value from 0-1023; 512 is 50% light
int val=0; // val will be used to store the value from the sensor

void setup() {
pinMode(LED, OUTPUT); // tell Arduino LED is an output
pinMode (SOLENOID,OUTPUT); //sets the digital pin as output
// analog pins are already set as inputs
}

void loop() {
val=analogRead(0); // read from the sensor
if ( val < LIGHTVAL )
{
analogWrite(LED,254); // turn on the LED
// check if there was a transition
digitalWrite(SOLENOID,HIGH); // turns SOLENOID on
delay(2000); // waits for 2 seconds
digitalWrite(SOLENOID, LOW); // turns the SOLENOID off
}
else
{
analogWrite(LED,0);
}
if ( val > LIGHTVAL )
{
delay(5000); // sleeps for 5 seconds
// ie if someone is walking by it won't trigger
}
}

dean123:
Here's the code so you can see inputs and outputs- like I said earlier- if the arduino is powered via usb (ie I don't use the barrel jack) then it all works.

And, as I said before: you need to provide more than 5V to the barrel connector. Ideally, 7V or more. If you have exactly 5V, you can provide that to the "+5V" pin instead of the barrel jack.

and your god like forum status is intact.
I moved the barrel jack to 12v power and the whole thing works great.

Question: The circuit uses the +5v pin on the arduino for one leg of the photo diode. Could I have just added 5v wallwart power there or would i mess up the circuit?

thanks for the advice.

Yes you can add 5v input power on the same pin as you take 5v.

Just to finish this up...
Here's a youtube link to the actual lightbot/ light activated solenoid:

This was my first arduino project.
It is really a combination of 3 smaller beginner tasks:
blink an LED
Use of a photoresistor
Control a motor or solenoid with a mosfet transistor

I combined all 3 to fix an annoying problem at work: The building control system turns out the lights at 6 or 7 pm but we stay til 1am.

dean123:
Just to finish this up...
Here's a youtube link to the actual lightbot/ light activated solenoid:
IMG_0379.MOV - YouTube

This was my first arduino project.
It is really a combination of 3 smaller beginner tasks:
blink an LED
Use of a photoresistor
Control a motor or solenoid with a mosfet transistor

I combined all 3 to fix an annoying problem at work: The building control system turns out the lights at 6 or 7 pm but we stay til 1am.

Nice project to get started that covers the basics of learning the IDE and sketch format and learning enough interfacing electronics for a basic sensor and controlling a output device. Now if it was to be a final project you might consider adding a I2C controlled real time chip to keep from turning on the lights on days that nobody works there (weekend, holidays, etc) and maybe work on final packaging using a standalone chip rather then using up the arduino board (adds about $10, but frees up your board for the next prototyping project.)

Good show, Lefty