r/ArduinoProjects • • Jan 22 '17

How do I write an arduino code for this?

A spdt switch that control weather the flow of energy goes to a 5V arduino or an 12V sucking electromagnet. When the flow is stopped on the electromagnet I need it to start a timer on the arduino and when vibration is detected by Piezo Vibration Sensor the timer is to stop.

0 Upvotes

4 comments sorted by

1

u/CatzRuleZWorld Jan 23 '17

This may not be what you're looking for but based on your specification, this is the best I can think of. Also, don't know if it'll work in practice but in theory it should I think...

bool timerActive; double timer;

void setup{ timer = 0.0; }

void loop{ if (electromagnetThing){ timerActive = true; } if (vibration){ timerActive = false; } if (timerActive){ timer += 0.001; } millis(1); }

1

u/ParabolaXYZ Jan 27 '17

Thank you. How would I draw a circuit for this tho?

1

u/ejrome05 Mar 06 '17

wait, how can the arduino run this code if there is no power (5V) running to it? and what voltage is distributed from the SPDT to the arduino (5V) and the electromagnet (12V) ?

--sorry, i just came across this thread and thought i wanted to draft a diagram on the connections. but last posted 1month ago. hehe

1

u/ParabolaXYZ Mar 24 '17

I'm still open to suggestions.