ir lightbarrier


My name is Stanley and i have a question about my intership project.
My question is that i would detect a ribbon cable but the ribbon cable will also let through a little bit light.
So on the serial monitor i see different value.
How could i program those different value to 2 value?


So, in serial monitor, you get some values which mean that the light is blocked or some higher (or lower) values when the light is not blocked?

The more information that you provide, the better the answers that you will get.

Can you post a link to the IR Led and the IR receiver you have chosen for this project ?
A light barrier IR receiver may give a binary detected/not detected output. Some, say proximity sensor types may be more flexible and allow interpretation. If you do it yourself with a photo transistor, you may have to take care of ambient light.

If i hold the ribbon cable through the detection gap of the light barrier. Then you see the value 500-570 on the serial monitor. When i don't hold the ribbon cable trough the detection gap of the light barrier then you see the value 37-40. The light barrier is connect on pin A0 of the Arduino UNO.

Use an ‘if then else’ construct in C++ to specify what happens when the range of values you get from reading the analog pin indicate that the ribbon cable is present.

This is the program what i already have so far.

int sensor1Pin = A0;
int sensor1 = 0;
int led = 13; ///

void setup() {
pinMode(sensor1Pin , INPUT);

void loop() {

sensor1 = analogRead(sensor1Pin);
if(sensor1Pin>50) //
digitalWrite(sensor1,0); //
digitalWrite(sensor1,1); //


sensor1 = analogRead(sensor1Pin);  //          sensor1 will be a value 0 to 1023
if(sensor1Pin>50)         //                sensor1Pin = A0 = 14. Do you mean sensor1 (analogRead value)?
  digitalWrite(sensor1,0);    //             digitalWrite to pin (0 to 1023).  Do you mean LED?


Yes, sensor1 is a analogRead value

No, i don't mean a LED
Its this light barrier.

Here is the wiring diagram from the datasheet.


It shows a pwm on the LED with a 5% duty cycle for the specification test circuit.
How have you got it wired ?


sensor1 = analogRead(sensor1Pin);
digitalWrite(sensor1, 1);


digitalWrite(pin, value)

pin: the pin number

i have a velleman vma03 motorshield.
also i will drive my bipolair stepper.
and i have selected the external power supply.
The coils are wired but what should i do with the jumpers dirb, dirA, PWMb and PWmA?
Could someone help me?

The jumpers select which processor pins go to the dir and enable pins of the driver. Manual For instance the jumper on SK8 connects ENA of the driver chip to pin 3, pin 5 or pin 6 of the processor (Uno).


also for driving the stepper
it doesn't matter how the jumpers are connected?
for testing the stepper.

The pins need to match what is set up in your sketch, so yes, it matters. Post your test sketch, please.

this is my sketch

#include <Stepper.h>

int startKnop = 5;
int stopKnop = 4;
const int stepsPerRevolution = 200;

Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

int stepCount = 0;

void setup() {



void loop() {

// if(startKnop = 1);
for(int i = 0; i<5; i++){
stepCount = 0;


The jumper on sk11 is connected to pin 8
The jumper on sk9 is connected to pin 9.
The jumper on sk10 is connected to pin 2.
and the last jumper on sk8 is connected to pin 3.

A couple of links with information on driving bipolar stepper with that shield.

And a library written for that shield.

See the example for how to set up pins.


I have the motor shield connected to two DC motors and it works.
But the stepper motor will not rotate.
The stepper motor shocks.
And the leds of the motor shield will shine first yellow and then red.
At the same time the leds will shine.

Could someone help me?