assistance please with ACS712 sensor

Good Morning all, can someone please assist me with a small problem I have in my code,
I need to get a reading from a ACS712 Sensor module connected to pin A0 and stop a roller door if the value gets to high I need to compare max load with the reading from lm and if its to high the motor must stop. I’m not sure where in my code this must fit in and what statement exactly I should use.
I would also like to print the values for later changes (bigger motor)

Please help?

here is my current code:

#include <PCM.h> //Include the voice Lib

//The purpose of this code is to be able to open and close
//a roller door with limit switches and remote signals(12V)
//it must also have a safety feature to stop the door if the load gets to high

int spkr = 11; //Speaker is connected to pin 11

//Define a Relay to open Door and a Relay to close door

int ro = 10; //Relay to open door connects to pin 11
int rc =9; //Relay to close door connects to pin 10

//Define a Limit Switch for open pos and close pos

int cp = 7; //Closed pos switch connects to pin 7
int op = 8; //Open pos switch connects to pin 8

//Define 1 test button and one remote trigger button

int tb = 3; //Test button connects to pin 2
int trig = 4; //Remote trigger connects to pin 4

//Define status Led pin

int led = 13; //Led connects to pin 13

// Declare amp Meter

int lm = A0; //Load meter ic connected to pin A0

// Declare max load

int MaxLoad = 25;

//This is the recording that is played before the door close

void setup() {

Serial.begin(9600);

// Define output pins:

pinMode(led , OUTPUT); //Led is an output
pinMode(ro , OUTPUT); //Relay to open is an output
pinMode(rc , OUTPUT); //Relay to close is an output

// Define input pins:

pinMode(tb , INPUT); //Test button is an input
pinMode(trig , INPUT); //Remote trigger button is an input
pinMode(cp , INPUT); //Close pos switch is an input
pinMode(op , INPUT); //Open pos switch is an input
pinMode(lm , INPUT); //Load meter is an input

digitalWrite(led, LOW); //Turn off Led
digitalWrite(ro, LOW); //Turn off relay open
digitalWrite(rc, LOW); //Turn off relay close

//Define reset command to open door if no limit switch is triggered

if(digitalRead(cp) == LOW && digitalRead(op) == LOW){ //If none of the limit switches are triggered the door must open
Serial.println(“ERROR”); //Print the error message
digitalWrite(ro , HIGH); //Trigger open relay
}

if(digitalRead(op) == HIGH){ //Check when the door is open
digitalWrite(ro , LOW); //Stop the opening relay

}

}

void loop() {

OPENING_TEST_BUTTON:

if(digitalRead(cp) == HIGH && digitalRead(tb) == HIGH){ //Trigger the door to open

delay(1); //Buffer
digitalWrite(led , HIGH); //Turn the Led on
delay(2); //Buffer
digitalWrite(ro, HIGH); //Start opening door

Serial.println(digitalRead(tb)); //Print data
Serial.println(“The LED is ON”); //Print message
Serial.println(“The Door Is Opening”); //Print message

}

if(digitalRead(op) == HIGH){ //Trigger limit switch on open pos
digitalWrite(led , LOW); //Turn Led off
digitalWrite(ro, LOW); //Turn opening relay off

Serial.println(digitalRead(tb)); //Print data
Serial.println(“The LED is OFF”); //Print message
Serial.println(“The Door Is Opened”); //Print message

}

CLOSING_TEST_BUTTON:

if(digitalRead(op) == HIGH && digitalRead(tb) == HIGH){ //Trigger the door to close
delay(1); //Buffer

startPlayback(warning, sizeof(warning)); //Paly the warning message before door starts closing
delay(5000); //Delay before message is repeated
startPlayback(warning, sizeof(warning)); //Play message again
delay(5000); //Delay before door starts to close

digitalWrite(led , HIGH); //Turn Led on
delay(2); //Buffer
digitalWrite(rc, HIGH); //Turn closing relay on

Serial.println(digitalRead(tb)); //Print data
Serial.println(“The LED is ON”); //Print message
Serial.println(“The Door Is Closing”); //Print message

}

if(digitalRead(cp) == HIGH){ //Trigger limit switch on close pos
digitalWrite(led , LOW); //Turn Led off
digitalWrite(rc, LOW); //Turn closing relay off

Serial.println(digitalRead(tb)); //Print data
Serial.println(“The LED is OFF”); //Print message
Serial.println(“The Door Is Closed”); //Print message

}

OPENING_REMOTE:

if(digitalRead(cp) == HIGH && digitalRead(trig) == HIGH){ //Trigger the door to open
delay(1); //Buffer
digitalWrite(led , HIGH); //Turn Led on
delay(2); //Buffer
digitalWrite(ro, HIGH);

Serial.println(digitalRead(tb)); //Print data
Serial.println(“The LED is ON”); //Print message
Serial.println(“The Door Is Opening”); //Print message

}

if(digitalRead(op) == HIGH){ //Trigger limit switch on open pos
digitalWrite(led , LOW); //Turn Led off
digitalWrite(ro, LOW); //Turn opening relay off

Serial.println(digitalRead(tb)); //Print data
Serial.println(“The LED is OFF”); //Print message
Serial.println(“The Door Is Opened”); //Print message

}

CLOSING_REMOTE:

if(digitalRead(op) == HIGH && digitalRead(trig) == HIGH){
delay(1); //Buffer

startPlayback(warning, sizeof(warning)); //Paly the warning message before door starts closing
delay(5000); //Delay before message is repeated
startPlayback(warning, sizeof(warning)); //Play message again
delay(5000); //Delay before door starts to close

digitalWrite(led , HIGH); //Turn Led on
delay(2); //Buffer
digitalWrite(rc, HIGH); //Turn closing relay on

Serial.println(digitalRead(tb)); //Print data
Serial.println(“The LED is ON”); //Print message
Serial.println(“The Door Is Closing”); //Print message

}

if(digitalRead(cp) == HIGH){ //Trigger limit switch on close pos
digitalWrite(led , LOW); //Turn Led off
digitalWrite(rc, LOW); //Turn closing relay off

Serial.println(digitalRead(tb)); //Print data
Serial.println(“The LED is OFF”); //Print message
Serial.println(“The Door Is Closed”); //Print message

}

}

Start learning the basics:

Learn to use Code Tags </> to present code.
Learn what’s the purpose of delay(), and how to omit it.
Learn to read buttons, debounce and state change detection.
Learn to write loops for opening and closing.
Learn to use subroutines for open and close.
Learn to do several things at the same time (top topic).
Learn to use multiple constants for multiple messages.

at the top of every forum is a sticky post called how to use this forum

item #7 tells you about code tags and how to use them.

you can edit your post by selecting modify on the bottom right at the end of your post.

also, please read about subject lines. imagine if every title of every book in the library was 'book for reading'

I'm still new at this, given my limited knowledge I think I'm not doing too bad, I know I still have a lot to learn and that is why I'm asking for help. This is my first project so I appreciate the help but you just told me what I still need to learn instead of helping me to get the project to work. This is my base program from witch I'm learning, Ill obviously rewrite it while learning better methods. please don't stone me for trying to learn?

dave-in-nj: at the top of every forum is a sticky post called how to use this forum

item #7 tells you about code tags and how to use them.

you can edit your post by selecting modify on the bottom right at the end of your post.

also, please read about subject lines. imagine if every title of every book in the library was 'book for reading'

Thank you, noted , I'll be sure go read it

Quin: I'm still new at this, given my limited knowledge I think I'm not doing too bad, I know I still have a lot to learn and that is why I'm asking for help. This is my first project so I appreciate the help but you just told me what I still need to learn instead of helping me to get the project to work. This is my base program from witch I'm learning, Ill obviously rewrite it while learning better methods. please don't stone me for trying to learn?

People here are trying to help you by showing you the correct way and pointers to where you can improve. You have no idea how to do it and when they show you the way you criticise them.

FYI, most rolladoors I've seen already have load compensation adjustments built in.

It appears from your reply you expect someone to rewrite the code for you so it now works without your having to do any study.

With an attitude like that you might be lucky to get any further assistance.

bluejets: People here are trying to help you by showing you the correct way and pointers to where you can improve. You have no idea how to do it and when they show you the way you criticise them.

FYI, most rolladoors I've seen already have load compensation adjustments built in.

It appears from your reply you expect someone to rewrite the code for you so it now works without your having to do any study.

With an attitude like that you might be lucky to get any further assistance.

Hi, not at all, I get that and I'm sorry if I come across as criticizing, it was not my intention, its just some of these guys think that people have been doing this for years and sometimes it feels like they are trying to make you feel stupid. I don't want someone to write it for me as I'm learning, basically all i wanted to know was " I'm not sure where in my code this must fit in and what statement exactly I should use.". But thank you for the advice and once again sorry for coming across rude.

Did you read this bit............????

bluejets: FYI, most rolladoors I've seen already have load compensation adjustments built in.

I do not know if there is a primer to writing code, but here are a few pointers.

C++ allows you to use words that mean something

if UpperEndStopSwitch = = 1

means more than

if USS == 1 // UpperEndStopSwitch

yes it is short hand and writing it out 20 times takes longer, but when reading it is much easier for you to come back in 6 months, or for others to read and help you.

read all pins at the start of loop()

TestButton = digitalRead(tb) CloseSwitch = digitalRead(cp) OpenSwtch = digitalRead(op)

that way you do not read them over and over and there is a possibility that some thing can change from the time the sketch starts till the time it ends. ir reailty, you will see that the next time through, but this time through, you do not want to see things changing.

===========================

as a tip, compile your code, eliminate the things that are obvious.

you comment the heck out of your work, so that is really great.