Pages: 1 2 [3]   Go Down
Author Topic: Loop question  (Read 4324 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18794
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void digital_4(void)
{
  digitalWrite(a,LOW);
  digitalWrite(d,LOW);
  digitalWrite(e,LOW);
  digitalWrite(dp,LOW);
  digitalWrite(b,HIGH);
  digitalWrite(c,HIGH);
  digitalWrite(f,HIGH);
  digitalWrite(g,HIGH);   
}

Just out of curiosity, are you planning to use all 4 digits on the display? I am guessing they all come on together right now (with the same number), or do they?

If they do, what are your plans for having different digits (eg. player 1 score, player 2 score)?
Logged


Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, yes that light on the sensor is a "on" light but when something passes in front of the sensor then the light gets brighter. Also for now that's the only LED I have smiley...I will be ordering 1 digit LED because I only need 0 to 9 score. Here is the info on that sensor. Thanks!!

Edit: Yes all the digits are showing the same number for now.

Edit2: Actually that light is the signal light on pin 12. If there is not signal then the light goes off. But when the wire it connected the signal comes on and when I put my hand in the front of the sensor the light goes brighter.

Quote
Model: E18-D80NK

Features :
- Adjustable Infrared Sensor Switch is a set of transmitter and receiver in one of the photoelectric switch sensor. The detection distance can be adjusted according to the demand. The sensor has a detection range of 3cm-80cm. The switching signal output differs in accordance to the obstacles. It remains high when no obstacles and remains low when there are obstacles.
- Useful for robot, interactive media, industrial assembly line, etc.
Specification
- Voltage:DC 5V
-Current: 100mA
- Sensing Distance :3 - 50 CM
-NPN Normal Open Type
- Sensor diameter: 18mm
-Sensor Length: 43mm
-Lead Length: 45mm
-Pin Definition: red (power "+" ) and green(power "-" ), yellow (signal date).
« Last Edit: November 30, 2011, 05:41:35 pm by jat421 » Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4807
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You might have another problem, it says "Current: 100mA" and when the sensor is not receiving the light gets brighter may be an indication that the unit is draining more power than you got to spare. Are you by any chance running on a 9V battery?

Here is a different code that will only show you changes in state and no delay, no miss action.

Code:
int inputPin = 13;
int val, was;

void setup()
{
  Serial.begin(9600);           
  val = was = 0;
}

 void loop()
{
  val = digitalRead(inputPin);
  if (val != was) 
  {
     Serial.println(val);
     was = val;
   }
}
Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey, you might be right, I just calculated the amount of current pulled. It is connected through USB cable and getting 500mA. But I have 4 digit LED that is taking 640 mA plus the sensor and arduino. Damit I don't know how I overlooked that. I will have to get a power adapter that can provide enough juice. Thanks for all the help. I will report back on the finding.
Logged

Wageningen,The Netherlands
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have this sensor too. To test it I used this code:
Quote
/*
E18-D50NK IR distance sensor]

RED to arduino 5v
GREEN to arduino GND
YELLOW to Arduino pin 13.
Output: 1 no obstacle
            0 object detected
       
To adjust the sensitivity use the potentiometer screw at the back of the sensor.
Sensitivity in the sense of at which distance obstacles can be detected.

By Mario de Deugd.
*/

#define SignalPin 13

void setup() {
  Serial.begin (9600);
  pinMode(SignalPin, INPUT);
}

void loop() {
  int Signal = 0;

  Signal = digitalRead(SignalPin);
  
  if (Signal == 1){
    Serial.print (Signal);
    Serial.println("  no obstacle");
  }
  else {
    Serial.print (Signal);
    Serial.println("  object detected");
  }
  delay(500);
}


So far it seems possible to detect objects at about 75 cm distance.


Regards,
Mario.
« Last Edit: November 15, 2012, 02:57:55 pm by marionet » Logged

Pages: 1 2 [3]   Go Up
Jump to: