Rotary encoder controlled solenoid

I've been tinkering for 2 days now and I am officially stuck. What I'm trying to do is use a basic hall effect rotary encoder I have built to control when a pneumatic solenoid is energized / de-energized.

I have a 10k potentiometer in the circuit that controls how long the solenoid stays energized.

What I'm trying to achieve...
Whenever the hall effect is closed (magnet present), I want the solenoid
energized for a time that is controlled by the pot setting.

I then want the Arduino to "see" the hall effect go low again before it repeats the loop...that way if you ever stop on a magnet it won't machine gun fire the solenoid.

Here's the code so far, I don't think I'm understanding the while function correctly.

// GH Bear auto driller supplement

// Set analog pin 1 as venier control
// Venier control sets how long solenoid is energized
int venierPin = 1;
int venierValue = 1;

// Set analog pin 2 as hall effect sensor
int hallPin = 2;
int hallValue = 2;

// Set digital pin 13 as solenoid transistor control
const int solPin = 13;

// Set threshold for hall effect sensor
const int threshold = 170;

// Set constant for using vernier setting to determine time
// to energize soleniod
const int constvenierValue = 5;

// Set digital pin 12 as hall effect supply transistor base
const int dhallPin = 12;

void setup() {
// initialize digital pins as outputs
pinMode(solPin, OUTPUT);
pinMode(dhallPin, OUTPUT);

// give juice to hall effect supply transistor base
digitalWrite(dhallPin, HIGH);
delay(1000);
digitalWrite;(dhallPin, LOW);
delay(2000);
digitalWrite;(dhallPin, HIGH);
}

void loop() {
// read hall effect state
hallValue = analogRead(hallPin);

// read venier setting
venierValue = analogRead(venierPin);

// add 10 millisecond delay
delay(10);

// if magnet is present, energize solenoid for time as
// function of vernier setting
if (hallValue > threshold) {
digitalWrite(solPin, HIGH);
}
delay(venierValue * constvenierValue);
digitalWrite(solPin, LOW);

// do not repeat loop until hall effect goes low again,
// indicating movement
while (hallValue > threshold) {
delay(100);
hallValue = analogRead(hallPin);
}
}

Also, if someone will tell me how, I'll provide a copy of my wiring diagram.

Also, I have an led that will turn on when the solenoid is to be energized. When I put the magnet over the hall effect, the response time is terribly slow (like 3 seconds).

I'm in desperate need of some help as I've got to have this thing perfected in a couple of days. Thanks guys.

Also, at the end of the void setup, the "on off on" for the hall effect supply transistor base is there because for some reason, when I give power to the whole circuit, the hall effect switch gets hung closed, magnet present or not. But, if I unhook one of the two positive voltage leads on the hall effect, it will "reset" and actually switch with respect to magnet present correctly.

?????

Link to the hall effect part and to the solenoid and show your wiring...

how would i post a scan of my wiring diagram?

Hall Effect

  • PN: US5881EUA-ND

Solenoid

  • Peter Paul Electronics
    PN: 23NN9ZCM
    12 volt, 9.5 watt, 35 psi

However, the solenoid will not energize on 12 volt. It takes more like
18. I've got another one from years ago and it's the same way.

yea i'm workin on it...i don't have facebook or any of that.

Here's the circuit diagram...

I've simplified my circuitry to where the and led is representing my solenoid.
I've also changed the code. I found an example similar to what I'm trying to achieved in the beginning arduino book by banzi.

When I try it, the led flashes very quickly, exactly in accordance with the amount I set the debounce delay.

I also have a section of code that, when the led is triggered, to stay on for an amount of time determined by the position of the potentiometer.

Here is a wiring diagram and the code.

// GH Bear auto driller supplement

#define LED 13 // the pin for the led

// Set analog pin 1 as venier control
// Venier control sets how long solenoid is energized
int venierPin = 1;
int venierValue = 1;

// Set analog pin 2 as hall effect sensor
int hallPin = 2;
int hallValue = 2;

// Set threshold for hall effect sensor
const int threshold = 750;

// Set constant for using vernier setting to determine time
// to energize soleniod
const int constvenierValue = 4;

// val will be used to store the state of the input pin
int val = 0;

// store previous state
int old_value = 0;

// 0 = LED off and 1 = LED on
int state = 0;

void setup() {
// initialize digital pins as outputs
pinMode(LED, OUTPUT);
}

void loop() {
// read hall effect state
val = analogRead(hallPin);

// check if there was a transition
if ((val >= threshold) && (old_value < threshold)) {
state = 1 - state;

// debounce
delay(20);
}

if (state == 1){
digitalWrite(LED, HIGH); // turn on LED
delay(venierValue * constvenierValue); // delay as per venier
digitalWrite(LED, LOW); // turn off LED
} else {
digitalWrite(LED, LOW);
}
}

I notice you haven't got even a single capacitor in that circuit. you need them at least each side of the voltage regulator. The whole thing is probably hooting like a banshee. Have you looked at any voltages with a scope?

You appear to have the transistors wired up wrong. It should be:- Collector to the solenoid emitter to ground. Other end of solenoid to +12V.

Why do you need that 1N4001? What do you think it is doing.

Well, I had tried a couple capacitors, and saw no difference. However, it's very possible I was not putting them where needed, or the size I needed.

The 1N4001 was just to drop the voltage a bit after the regulator. I really didn't want to be supplying the board w/ any more than 12 volts. It came out the regulator as slightly over 12, inserted the diode, and of course dropped it slightly below.

Take a look at my last circuit diagram I've posted and the latest code.
Thanks for the help.

Sorry, forgot to say...i don't have an oscilliscope.
So, no, haven't checked that.
However, I'd like to say the absence of caps is causing the problem.
I knew I needed caps somewhere, just didn't know where to put and what size.

I found online what caps to put on the ins and outs of my voltage regulators. However, didn't fix problem. I think it's in my code, but i can't for the life of me figure out what it is.

I tried taking the pot analog control completely out of the sequence, and just put in a 5 second delay (on-time for LED). The led got brighter (had full 5 volts) when magnet was present and would flicker off and then back on every 5 seconds. When the magnet wasn't present, digital pin 13 was still feeding 3 volts to the LED.

???

Take a look at my last circuit diagram I've posted

That looks bad. It's hard to follow but it looks like the high voltage is connected directly to the arduino. Either you have the diagram very wrong or you have a fried arduino. The wiring on the hall effect doesn't look convincing either. I can't seem to down load a data sheet for it, all the google leads result in an error when you actually get to the data sheet.

However, didn't fix problem.

It fixes the problem of having no caps, if there were no other problems it would have fixed it.
You need to post a schematic of exactly what you have including capacitors.

Here's the link to the datasheet. (FCI semiconducter)

And here's the link to the circuit diagram I just re-did. Sorry if it looks like crap, I've never drawn circuits before.

I made a barrel plug for the 11.8 volts I'm supplying the board with. The hall effect works well when I just put the output on an LED, so I believed I have it wired correctly, but perhaps not.

Thanks again.

so I believed I have it wired correctly, but perhaps not.

Why is it wired up to 12V as the data sheet says it will work off 5V?

Your diagram shows pins 1 and 3 connected to +12V. It should be Pin 1 to 12V Pin 3 to ground with pin 2 the output and a pull up resistor to 5V.

It is not an analogue output so why feed it into an analogue input?

Ok. I agree with Mike. If you are RELYING on a hall sensor... wire it correctly.

That is just not the way to hook up a Hall effect sensor.

You have the Supply Voltage and the Ground pin tied to 12V and the output Pin tied to an Arduino PIN. What?

There are literally no HALL sensor situations where two pins are tied together. And use the 5V Source! (Wide operating voltage range from 3.5V to 24V on the sensor)

Error - Melexis better data sheet

I had found a circuit on the web that had 9volts to vin, center pin to ground, but the signal pin was tapped off of the vin, had a resistor and an led that was contacted to the signal.

It made sense to me as a magnet was present, the sensor closed the switch and gave the voltage to the led a path to ground.

I placed an led on my solderless breadboard and connected it (with a 220 ohm resistor) to the signal (terminal 3) on the hall effect and it worked fine. However, the arduino went nuts when I placed the signal wire into an analog pin that was coded to turn on an led over a certain threshold.

Also, I've been reading and think I need a pullup resistor between signal and vin.

Also, I was originally using 5 volts, but when the magnet was present, I was seeing like 3 volts at the output. When magnet not present, I was seeing 1.8 volts. I was trying to widen my window, however it didn't seem to matter so I will most certainly change back to supplying with 5 volts.

What's confusing me is that if I put the signal terminal to arduino analog, where's it getting its voltage from? The other side of the "switch" is a ground, and the voltage input only runs the regulator, from what I see in the datasheet.

Or is that not right?

If not, how do I wire for Arduino analog to see voltage?

It is not an analogue output so why feed it into an analogue input?

I'm doing this because when magnet is not present, I'm still seeing 0.5 volts. I didn't think this would work digitally, like i thought it was supposed to work.

Would be wonderful if i could make it work digitally.

Well, If I was doing this... I would attach it like this:

I did up a quick drawing...