To make the motor run forward and backwards is not a problem.
Also I am not concerned about the speed of the motor.
The H Bridge configuration is also not a problem.
But, to time the motor on and off seems not to be a regular discussion on the net.
I need to open and close a security gate simply by using a push button (like those tiny square ones always used with arduino diagrams and tutorials).
If the button is pressed momentarily, the motor needs to run one direction for e.g. five seconds and stop in its tracks and must wait for my next button press.
If I press the button again, the motor must reverse direction to its default position (same timing span ) and stop in its tracks again. So, it is purely timed on and off in either direction.
On the net are lots of code available for the control of the H bridge including the button state. But with all of those codes the motor directions are not timed. They simply forward or reverse continuously.
With my limited knowledge of coding in C (Arduino), I some how feel the delay instruction is not the way to resolve the issue (or can it be possible?), but rather to make use of the timer of the Arduino. Either options put me in the dark.
Can you advise?
Absolutely!
Rather then trying to time the Arduino to successfully open and close you gate, I would recommend using limit switches such as these. Use two, one to let the Arduino know that the gate is open, and the other to let it know the gate is closed. Then use a weatherproof pushbutton to tell the Arduino to “turn the motor CCW until the limit switch trips, indicating the gate is open” or “turn the motor CW until other limit switch trips, indicating the gate is closed.”
The other problem I see is that your security gate might run on AC rather then DC. In order for your Arduino to control the direction of an AC motor, you will need more complicated circuitry and it is considerably more dangerous. An option would be to use a AC Reversing Solid State Relay as it can be directly controlled by the microcontroller. Unless you are a trained electrician, I would NOT recommend interfacing your Arduino to an AC source.
Below is a rough schematic for your circuit and a bit of code that should get you started!
Code:
const int activate = 2; //set up our button constants
const int gateOpen = 3;
const int gateClosed = 4;
const int bridgeOneA = 5;
const int bridgeTwoA = 6;
const int enable = 7;
const int statLED = 13;
unsigned long currentTime = 0;
boolean gateState = false; //false = closed true = open
void setup() {
Serial.begin(9600);
pinMode(activate, INPUT); //set up I/O
pinMode(gateOpen, INPUT);
pinMode(gateClosed, INPUT);
pinMode(bridgeOneA, OUTPUT);
pinMode(bridgeTwoA, OUTPUT);
pinMode(enable, OUTPUT);
digitalWrite(enable, LOW); //make sure H-Bridge is off
pinMode(statLED, OUTPUT); //setup our status LED
}
void loop() {
if (digitalRead(activate) == HIGH && gateState == false) { //check to see if the button is pressed and the gate is closed
digitalWrite(enable, HIGH); //enable h-bridge
digitalWrite(bridgeOneA, HIGH); //configure for CW rotation
digitalWrite(bridgeTwoA, LOW);
while(1){ //run motor until switch is tripped
if (digitalRead(gateOpen) == LOW) { //check switch state
gateState = true;
digitalWrite(statLED, LOW); //turn off LED
digitalWrite(enable, LOW); //disable h-bridge
digitalWrite(bridgeOneA, LOW); //reset h-bridge config
break;
}
if (millis() > currentTime + 500) { //flash status LED once
digitalWrite(statLED, HIGH);
delay(500);
currentTime = millis();
}
else {
digitalWrite(statLED, LOW);
}
}
}
if (digitalRead(activate) == HIGH && gateState == true) { //check to see if the button is pressed and the gate is open
digitalWrite(enable, HIGH);
digitalWrite(bridgeOneA, LOW); //configure for CCW rotation
digitalWrite(bridgeTwoA, HIGH);
while(1){
if (digitalRead(gateOpen) == LOW) {
gateState = false;
digitalWrite(statLED, LOW);
digitalWrite(enable, LOW);
digitalWrite(bridgeTwoA, LOW);
break;
}
if (millis() > currentTime + 500) { //flash status LED once
digitalWrite(statLED, HIGH);
delay(500);
currentTime = millis();
}
else {
digitalWrite(statLED, LOW);
}
}
}
}
I haven’t tried out the code, but it should get you started in the right direction. The idea is that when the button is pressed, the Arduino configures and activates the h-bridge, moving the gate until the “open” limit switch trips and stops the motor. Then when the button is pressed again, the Arduino configures and activates the h-bridge, moving the gate until the “closed” limit switch trips and stops the motor again. There is a also small bit of code that flashes the LED during the time the motor is in motion using the mills() counter.
I hope this has helped to steer you in the right direction and good luck with your project!
Don’t forget, everyone is invited to ask a question!
“Ask an Educator” questions are answered by Adam Kemp, a high school teacher who has been teaching courses in Energy Systems, Systems Engineering, Robotics and Prototyping since 2005.
Decisions, decisions. Who needs ’em? Why should you have to choose what to make with your iLog? Collect sounds right out of the air, listen to the sound of the light all around you. The iLog touch display has stereo ambient light sensors that automatically detect “Amplitude Modulation” and the brightness of the of ambient light in your surroundings.
This log synth is half Buddha Machine, Half Bleep Labs, Half Wood
Founded in February 2012, Girls Who Code is working to educate, inspire, and equip underserved girls aged 13-17 with the skills and resources to pursue careers in science, technology, engineering and math (STEM).
The Girls Who Code program is an eight-week summer program in New York City designed to introduce high school girls to basic software development skills and is accompanied by yearlong outreach initiatives, mentorship programs, and internship opportunities to realize each participant’s potential.
A new configuration utility for Digi International’s XBee radios is available for Macintosh, Windows and Linux platforms from Moltosenso in Italy, and it’s free. According to their web site,Moltosenso Network Manager™ IRON enables the following tasks:
• full support to any API Operation mode (with and without escaped characters)
• get/set of the parameters of Digi International® modules plugged to the PC, both in API and AT mode
• get/set of the parameters of Digi International® modules remotely addressable
• an effective graphic test for RSSI parameter, especially tailored for XBEE™ modules
• firmware upload (local and – where available – remote) for many supported Digi International® modules.
The computer was invented in the 30s: not the 1930s, but the 1830s. British mathematician Charles Babbage designed and prototyped a fully functional mechanical computer he called the Analytical Engine, but it was never completed. Now a team in Britain plans to build the machine for display at London’s Science Museum before the 2030s come around.
A three-week old robot at the MIT Media Lab is weaving a cocoon-like structure with a little programming help from humans. Eventually it will be autonomous.
“The traditional hierarchical org structure was developed to control, and steward fixed assets,” Whitehurst told me. The traditional hierarchies do not tend to innovate. “When information is your primary product, hierarchy isn’t the best way to drive.”
To illustrate how the open source culture influences everything at Red Hat, Whitehurst told me a story about an early experience as the company’s CEO. When he started, the company had — to his mind — a rather weak mission statement. Coming from a traditional management background, Whitehurst’s first reaction was to do what CEOs all around the world do: gather the executive team, have an off-site retreat with a paid facilitator, and develop a new mission statement. This new statement would then be broadcast to the employees.
“Hold on, sparky,” was effectively what his executive team told him. “You need internal buy-in,” he was told. An internal collaboration site was established — mailing list, wiki, blog — to discuss the mission statement with staffers who were passionate about that issue. Once the infrastructure was put in place, the discussion was entirely self-organized, and about 15 to 20 people really dug in. “Iterate, iterate, iterate” is how Whitehurst described the process.
The weekly show-and-tell is SATURDAY NIGHT 4/28/12 at 9:30pm ET!
NEW INSTRUCTIONS ON HOW TO BE ON THE SHOW AND TELL. If you are on Google+ and want to join, post a message/comment on Limor’s post on Google+ and say you want to show off a project and she will add you the “Show and Tell” circle. Then just look for the hangout announcement on the very same page later for your invite. There’s an 8 to 10 (at the same time) people limit per hangout, so if it’s full try later or just pop by next week same time. Some weeks are packed!
At 9:30pm ET you will see a link to the hang out. Just keep your mics muted until we call on you and have your project ready.
Google is allowing some accounts to broadcast and record – Ladyada is trying this out, with your help
Previously we broadcasted the hangouts on Google to Ustream using their Producer tool to capture the hangout. We’re still using Ustream for “ASK AN ENGINEER”.
So if anything goes wrong, it’s all very new, but that’s also part of the fun
What is “Ask an engineer”? From the electronics enthusiast to the professional community – “Ask an Engineer” has a little bit of everything for everyone. If you’re a beginner, or a seasoned engineer – stop in and see what we’re up to! We have demos of projects and products we’re working on, we answer your engineering and electronics questions and we have a trivia question + give away each week. Mosfet the cat stops by too. Previous chats can be viewed at http://www.adafruit.com/ask
And don’t forget, 30 minutes before the show we’re doing our weekly show-and-tell. If you are on Google+ and want to join, just add/follow +Limor Fried’s (Ladyada) page and post a comment so you can be added to the show and tell circle. At 9:30pm ET you will see a link to the hang out. Just keep your mics muted until we call on you and have your project ready.
For those who just want to watch, you’ll be able to watch it live on Ustream here and we usually have a recorded version posted later.