Go Down

Topic: Auto gate (Read 309 times) previous topic - next topic

Wizard234

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
Many of us started out knowing nothing

jremington

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

PaulS

Quote
I have attached the code as a reference
Attached it to what? There is no code in your post.
The art of getting good answers lies in asking good questions.

Wizard234

See the other post.. had some errors attaching the post
Many of us started out knowing nothing

PaulS

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 art of getting good answers lies in asking good questions.

Wizard234

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
Many of us started out knowing nothing

Wizard234

Here is the code. My apologies
Many of us started out knowing nothing

PaulS

Code: [Select]
        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.
The art of getting good answers lies in asking good questions.

Wizard234

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
Many of us started out knowing nothing

Wizard234

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
Many of us started out knowing nothing

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 .

Wizard234

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..
Many of us started out knowing nothing

Wizard234

I would still want to work on this code though
Many of us started out knowing nothing

Wizard234

Can someone help me with this pls? I wouldn't be asking this question if I wasn't interesting in learning how this works
Many of us started out knowing nothing

slipstick

#14
Aug 13, 2017, 11:35 am Last Edit: Aug 13, 2017, 11:36 am by slipstick
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

Go Up