Go Down

Topic: Loop question (Read 10159 times) previous topic - next topic


Code: [Select]
void digital_4(void)

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)?
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics


Nov 30, 2011, 11:36 pm Last Edit: Nov 30, 2011, 11:41 pm by jat421 Reason: 1
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 :)...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.


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.
- 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).


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: [Select]
int inputPin = 13;
int val, was;

void setup()
  val = was = 0;

void loop()
  val = digitalRead(inputPin);
  if (val != was) 
     was = val;

Nick Gammon on multitasking Arduinos:
1) http://gammon.com.au/blink
2) http://gammon.com.au/serial
3) http://gammon.com.au/interrupts


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.


Nov 15, 2012, 08:54 pm Last Edit: Nov 15, 2012, 08:57 pm by marionet Reason: 1
I have this sensor too. To test it I used this code:

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");

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


Go Up