Offline
Jr. Member
Karma: 0
Posts: 77
|
 |
« on: February 18, 2013, 12:52:02 pm » |
Kindly, my circuit is (Sensor===>Arduino===>Relay) the relay still switching ON/OFF rapidly ...i tried to calibrate the input voltage range and made delay time to read the new value ....but the problem not solved ... any idea about how to solve this problem?
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15309
Measurement changes behavior
|
 |
« Reply #1 on: February 18, 2013, 12:59:03 pm » |
Kindly, my circuit is (Sensor===>Arduino===>Relay) the relay still switching ON/OFF rapidly ...i tried to calibrate the input voltage range and made delay time to read the new value ....but the problem not solved ... any idea about how to solve this problem?
You probably need to post your code. Probably a lack of using a software hysteresis in your switch command. Lefty
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 77
|
 |
« Reply #2 on: February 18, 2013, 01:04:45 pm » |
int analog_in = A0; int dig1_out = 9; int dig2_out = 10;
void setup () { Serial.begin (9600); pinMode(dig1_out, OUTPUT); pinMode(dig2_out, OUTPUT); DDRD=0xFF;
PORTD=0;
delay (5000); }
void loop () { int value=analogRead(analog_in); //value= 1024 * voltage / 5
if ((value >= 380) && (value <= 656)) // refrence range (2.8v - 3.2v) {
digitalWrite(dig1_out,LOW); digitalWrite(dig2_out,LOW); }
else if ((value >= 710) && (value <= 860)) { //up range (3.8v - 4 v)
digitalWrite(dig1_out,LOW); digitalWrite(dig2_out,HIGH); }
else if (value <= 260) { //down range (2v - 2.2v) digitalWrite(dig1_out,HIGH); digitalWrite(dig2_out,LOW); } else { // for none of the above states
digitalWrite(dig1_out,LOW); digitalWrite(dig2_out,LOW); }
delay(20); }
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 27
Posts: 1539
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #3 on: February 18, 2013, 01:15:30 pm » |
What sensor are you using?
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 77
|
 |
« Reply #4 on: February 18, 2013, 01:39:40 pm » |
AD620 instrumentation amplifier
|
|
|
|
|
Logged
|
|
|
|
|
Rome, Italy
Offline
Sr. Member
Karma: 20
Posts: 442
|
 |
« Reply #5 on: February 18, 2013, 01:40:15 pm » |
You have "holes" in your range, so if V = 3.3 you set the pins to LOW. This may be what you want, but why then define a reference range?
More importantly, when the reading is close to a threshold it may oscillate above and below it. You need overlapping ranges and some way to keep track of the previous state.
|
|
|
|
|
Logged
|
|
|
|
|
New Jersey
Offline
Edison Member
Karma: 24
Posts: 2345
|
 |
« Reply #6 on: February 18, 2013, 01:45:23 pm » |
Some serial.print calls in that code to tell you what "value" is would be a good start in tracking down what's going wrong. Killing some of that whitespace wouln't be a bad idea either.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 77
|
 |
« Reply #7 on: February 18, 2013, 01:48:18 pm » |
i removed the reference range and defined the up state with 3.8 volt and above and down state with 2.2 volt and below....and the problem is still
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 27
Posts: 1539
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #8 on: February 18, 2013, 01:50:40 pm » |
Did you include a transistor and a feedback preventing diode on the relay?
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
New Jersey
Offline
Edison Member
Karma: 24
Posts: 2345
|
 |
« Reply #9 on: February 18, 2013, 01:51:47 pm » |
Please post the new code and the results of the debugging prints you (hopefully) added.
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15309
Measurement changes behavior
|
 |
« Reply #10 on: February 18, 2013, 01:54:21 pm » |
And it's possibly an electrical problem. How are you wiring up the relay? How much voltage and current does the relay coil require?
Lefty
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 77
|
 |
« Reply #11 on: February 18, 2013, 01:59:15 pm » |
it is 5v relay and no transistor nor diode included , the arduino output connected directly to the relay ....
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 27
Posts: 1539
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #12 on: February 18, 2013, 02:03:07 pm » |
it is 5v relay and no transistor nor diode included , the arduino output connected directly to the relay ....
NO! You can NOT power it directly from the arduino ESPECIALLY with no diode.
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 77
|
 |
« Reply #13 on: February 18, 2013, 02:06:40 pm » |
int analog_in = A0; int dig1_out = 9; int dig2_out = 10;
void setup () { Serial.begin (9600); pinMode(dig1_out, OUTPUT); pinMode(dig2_out, OUTPUT); DDRD=0xFF;
PORTD=0;
delay (5000); }
void loop () { int value=analogRead(analog_in); //value= 1024 * voltage / 5
if (value >= 710) { //up range 3.8v
digitalWrite(dig1_out,LOW); digitalWrite(dig2_out,HIGH); }
else if (value <= 260) { //down range (2v - 2.2v) digitalWrite(dig1_out,HIGH); digitalWrite(dig2_out,LOW); } else { // for none of the above states
digitalWrite(dig1_out,LOW); digitalWrite(dig2_out,LOW); }
delay(20); }
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15309
Measurement changes behavior
|
 |
« Reply #14 on: February 18, 2013, 02:07:51 pm » |
it is 5v relay and no transistor nor diode included , the arduino output connected directly to the relay ....
Well the key thing is what is the relay coils current demand? So post a link to your specific relay as some can be driven directly by a output pin but most cannot. Also the diode across the relay coil terminals is an important safety component, you should add it. Lefty
|
|
|
|
|
Logged
|
|
|
|
|
|