Auto gate

Hi
I am trying to build on a project by developing a auto gate opener using arduino uno, 2 photoelectric sensors, 2 proximity sensors, a PIR sensor, a RF receiver, gsm module, a 12v dc motor and a 2 channel relay. So far I have uploaded the code to arduino uno and the result is that the motor start spinning without any input from the sensors, the rf receiver or the gsm module. The only way to stop the motor is to plug the relay from the power supply as not even the proximity sensor will stop it.
I have attached the code as a reference and wondering if someone can explain what is happening as I am kinda new to arduino. Note: there are two different code in this attachment that was taken from two different source - they were individually tested but the function was working

Please read and follow the directions in the "How to use this forum" post.

I have attached the code as a reference

Attached it to what? There is no code in your post.

See the other post.. had some errors attaching the post

Wizard234:
See the other post.. had some errors attaching the post

What other post? YOU should provide a link to it.

Better still, ask a moderator (using the report to moderator link) to merge your two threads before someone gets pissed off at your duplicate posting.

The fault wasn't mine entirely as when I submit the post it submit the post without the attachment and mentioned I should try again

Here is the code. My apologies

gate.txt (13.5 KB)

        if ( pos == 3 && strcmp(buffer, "AT+") == 0 ) {
          state = PS_IGNORING_COMMAND_ECHO;

buffer is NOT a string. You should NOT be passing buffer to functions that expect strings.

You could make buffer a string by adding a NULL terminator every time you add a character to the array.

You have WAY too much code when you are having hardware problems. Load a blank sketch on the Arduino - one that does nothing. Fire it up. Does the motor start running? If so, you need to, in the real sketch, set the state of the motor pin properly at the very beginning.

While it seems intuitive that LOW on a relay pin would mean off, that is rarely the case.

Thank you for that explanation.. the reason of the long codes is because I add the gsm module to it. I will try that and see what happen

I have uploaded a blank sketch and the motor didn't start so I presume it must be some errors in the code. the previous code I've uploaded contained the gsm module function so I will be presenting the code that only contained the ultrasonic sensors and RF receiver.can you please teach what I need to change in this code to prevent the motor from starting automatically and to only start when the ultrasonic sensor detect an object or when the RF receiver transmitter button is press. I have tried to paste the code here in this message but it wont allow me to so I have attached it as a txt file

gatecode.txt (9.35 KB)

Do this in baby steps

Write a sketch to start and stop your motor with say a digital input .
Then start adding bits ( e.g. A sensor input) and get those working building the project as you go .

hammy:
Do this in baby steps

Write a sketch to start and stop your motor with say a digital input .
Then start adding bits ( e.g. A sensor input) and get those working building the project as you go .

Thank you this sound better..

I would still want to work on this code though

Can someone help me with this pls? I wouldn't be asking this question if I wasn't interesting in learning how this works

You could start by learning a good way to post questions and code to these forums. Reading http://forum.arduino.cc/index.php/topic,148850.0.html should help here, particularly the part about posting code.

Also if you want people to help you get the code to work as you want then a CLEAR explanation of EXACTLY what it is supposed to do will probably help.

Steve

I understand how to.. I am using my mobile phone so the options are limited and whenever I post the code that way it give me "characters limited"

The 12v dc motor is connected to a 2 channel relay which is connected to pin 8, 9 of arduino uno. I am not an arduino programmer so I can't versed out where I think this error is. The problem I am having is that if I plug the relay on the power supply the motor starts in one direction and won't respond to the RF receiver or the ultrasonic sensors. The only way to stop the motor is to unplug it from the power supply. I have searched on google for a fix and found nothing. The ultrasonic sensors are pin A0 - A3 and the RF receiver is pin 12, 13. I exhausted my options and I refuse to put this problem down. Maybe I am not asking the right question but an expert can easily help with a solution instead of filling this thread teaching about how to post.

Hmm.. Im no programmer, but i might have a clue..

Is the motor a "normal" motor, a stepper motor or what? (these behave differently).

if youre using a motor controller, you might have a controller that can run in both directions.

If that is the case, you might need a ANALOG output to control the motor controller.
Or possibly pulse position modulation (PWM/PPM), this is normal for RC motor controllers.

So when youre setting your motor to STOP, you might be setting it to GO (in one direction).

Sometimes the signals are inverted too, that your logical 1 is HIGH, while the motor controller expects logic 1 to be LOW.

In other words, if you put voltage on the motor ON pin, and it stays on, try connecting ground to the pin instead.

Adding the relays on top of the motor makes it harder to identify correct signals, since you need 2x correct signals to successfully control the motor.
The first signal is between the arduino and the relay, the second is between the relay and the motor.

So you might be disabling the relay when you think you just activated it, and the activated relay may disable your motor, depending on the specifics in your case.

So my suggestion is to remove the arduino completely and try to get your circuit to work with a couple of buttons.
When your hardware is working as expected, then add the arduino and the bare essentials of a code snippet, slowly adding functions one at a time instead of uploading the whole project in one go, then try to debug.

As i said, im no programmer or electrical engineer, this is just my two cents regarding troubleshooting. :slight_smile:

Good luck m8, may the force be with you!

Thanks very much.. I will try that solution

The motor I am using is capable of bi direction.. I was using a syren 10 motor driver but it wasn't turning the motor and when I change the dip switch to analog it ran the motor as the problem I am having now