ir lightbarrier

Hello,

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?

Stanley

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(led,OUTPUT);
pinMode(sensor1Pin , INPUT);
Serial.begin(9600);
}

void loop() {

sensor1 = analogRead(sensor1Pin);
Serial.println(sensor1);
if(sensor1Pin>50) //
{
digitalWrite(sensor1,0); //
}
else
{
digitalWrite(sensor1,1); //
}
delay(500);

}

sensor1 = analogRead(sensor1Pin);  //          sensor1 will be a value 0 to 1023
Serial.println(sensor1);
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?
}

@groundFungus

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.

TCST2x.JPG

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

(deleted)

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

Syntax

digitalWrite(pin, value)
Parameters

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

@groundFungus

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() {

Serial.begin(9600);

}

void loop() {

// if(startKnop = 1);
for(int i = 0; i<5; i++){
myStepper.step(1);
Serial.print(“steps:”);
Serial.println(stepCount);
stepCount++;
delay(500);
}
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.

@groundFungus

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?