Offline
Newbie
Karma: 0
Posts: 16
|
 |
« on: January 27, 2013, 12:34:05 pm » |
hi, im having troubles regarding the serial monitor cause it shows infinite outputs of high and low
i have this simple code:
int forwardPin = 12;
void setup() { Serial.begin(9600); pinMode(forwardPin, INPUT); }
void loop() { int forwardState = digitalRead(forwardPin); if (forwardState == HIGH) { Serial.println("HIGH"); delay(1000); } else { Serial.println("LOW"); delay(1000); } }
but when i look at the serial monitor for its output, it shows infinite loops of high and low.
i also tried it for outputing Serial.write for my project, but still it doesn't work
hope u could help me. im trying this code for my robotics project so im glad if anyone here could help
thanks in advance
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #1 on: January 27, 2013, 12:36:16 pm » |
Second floating pin question in under 24 hours. A new record? http://arduino.cc/forum/index.php/topic,145168.0.html
|
|
|
|
« Last Edit: January 27, 2013, 12:38:58 pm by AWOL »
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35519
Seattle, WA USA
|
 |
« Reply #2 on: January 27, 2013, 12:37:06 pm » |
but when i look at the serial monitor for its output, it shows infinite loops of high and low. Does the value change from HIGH to LOW only when you press the switch? Or does it change randomly? How is the switch wired?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 16
|
 |
« Reply #3 on: January 27, 2013, 02:00:31 pm » |
thanks for the reply PaulS.
no...it shows high and low outputs randomly immediately after i turned on the serial monitor.
actually, im using a device which outputs digital signals...and it is connected in pin 12 of my arduino. (it is an infrared device with a remote as its controller).
again, thanks for the reply. i really appreciate it.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 16
|
 |
« Reply #4 on: January 27, 2013, 02:01:53 pm » |
Hi AWOL...
i read the thread that u gave with the link...so that could be the reason?
so what to do with the floating pin?
yes sir im a noob, so could u please help me? ty
|
|
|
|
|
Logged
|
|
|
|
|
California
Offline
Edison Member
Karma: 41
Posts: 1872
|
 |
« Reply #5 on: January 27, 2013, 02:08:23 pm » |
Sounds like floating pin syndrome.
Enable the internal pull-up resistor on the pin.
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 277
Posts: 25517
Solder is electric glue
|
 |
« Reply #6 on: January 27, 2013, 02:15:59 pm » |
actually, im using a device which outputs digital signals...and it is connected in pin 12 of my arduino. And is the ground of this device connected to the ground of the arduino. If not then it floats.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 16
|
 |
« Reply #7 on: January 27, 2013, 02:28:04 pm » |
how to do that enabling the pull up resistor? sorry for the question guys T_T thanks
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 316
Posts: 35519
Seattle, WA USA
|
 |
« Reply #8 on: January 27, 2013, 02:29:38 pm » |
pinMode(forwardPin, INPUT); digitalWrite(forwardPin, HIGH); // Turn on the pullup resistor.
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 277
Posts: 25517
Solder is electric glue
|
 |
« Reply #9 on: January 27, 2013, 06:00:11 pm » |
how to do that enabling the pull up resistor?
If the grounds are not connected then enabling the internal pull ups is not going to help. You only need to enable the internal pull up if you have an open collector output on your other device. This is written for power supplies but it applies equally to signals:- http://www.thebox.myzen.co.uk/Tutorial/Power_Supplies.html
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 16
|
 |
« Reply #10 on: January 27, 2013, 10:09:12 pm » |
i really appreciate ur help guys...
with regards to connecting grounds, we connected the ground of the supply of our input device to the ground of our arduino... but yet there's also a ground near the outputs of our input device...and i assume the 2 grounds are connected, so we did not connect it
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 16
|
 |
« Reply #11 on: January 27, 2013, 11:03:03 pm » |
i keep researching about this guys..so, could the pull down resistors be the perfect solution?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #12 on: January 27, 2013, 11:05:30 pm » |
Is there a device connected to pin 12? Is it turned on? Is it wired correctly? Perhaps a photo or schematic?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #13 on: January 27, 2013, 11:06:36 pm » |
actually, im using a device which outputs digital signals...and it is connected in pin 12 of my arduino. (it is an infrared device with a remote as its controller).
A link to the device please. All this talk about "a device" when you could have specified a part number, and a link to it, is simply wasting time.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 16
|
 |
« Reply #14 on: January 27, 2013, 11:09:56 pm » |
Is there a device connected to pin 12? Is it turned on? Is it wired correctly? Perhaps a photo or schematic?
i don't have a photo or a schematic sir, but it is an infrared device which is controlled by a remote in which when a corresponding button in the remote is pressed, it has digital output, which is connected to pin 12. my problem is, even though i'm not pressing a button, the serial monitor outputs infinite loop of high and low, which really confuses me if this is a pull down resistor issue.
|
|
|
|
|
Logged
|
|
|
|
|
|