Pages: [1]   Go Down
Author Topic: Arduino with 10 times CNY70 sensors  (Read 2271 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello guys,

I am bussy with an project where i have to read out 10 sensors(CNY70)
they just have to give a 1 are a 0.
it's already working, the sensors give a one when the sensor is 4,5V and a zero when my is sensor is about 0,6V.
*I use the digital inputs for this project.
* the sensor works on 5V from arduino.
here is a example how i do it with the sensors:
 
http://www.google.nl/imgres?imgurl=http://2.bp.blogspot.com/-DgKjxBA_j5s/Tk5kDuqXU5I/AAAAAAAAA5Q/U7fgmawtphQ/s1600/CNY70.jpeg&imgrefurl=http://recreationalrobotics.blogspot.com/2011/08/rotary-encoder-based-on-cny70.html&h=789&w=534&sz=79&tbnid=KcDXQidMHaHFbM:&tbnh=90&tbnw=61&prev=/search%3Fq%3Dcny%2B70%2Barduino%26tbm%3Disch%26tbo%3Du&zoom=1&q=cny+70+arduino&docid=flp8E7pkl1oudM&hl=nl&sa=X&ei=BqpyT_DeHYqfOq3CicYO&ved=0CD4Q9QEwAw&dur=594

and then 10 times .
i already wrote this:

int D1 = 1;
int D2 = 2;
int D3 = 3;
int D4 = 4;
int D5 = 5;
int D6 = 6;
int D7 = 7;
int D8 = 8;
int D9 = 9;
int D10 = 10;
int D11 = 11;
int D12 = 12; // select the input pin for the Sensor

// variable to store the value coming from the sensor
int sensorValue1=0;int sensorValue2=0;  int sensorValue3=0; int sensorValue4=0;int sensorValue5=0;int sensorValue6=0;int sensorValue7=0;int sensorValue8=0;int sensorValue9=0;int sensorValue10=0;

void setup() {
  // declare the sensorpins as an input:
pinMode(D1, INPUT);pinMode(D2, INPUT);pinMode(D3, INPUT);pinMode(D4, INPUT);pinMode(D5, INPUT);pinMode(D6, INPUT);pinMode(D7, INPUT);pinMode(D8, INPUT);pinMode(D9, INPUT);pinMode(D10, INPUT);

Serial.begin(9600); 
}

void loop() {
 


  // read the value from the sensor:
sensorValue1=digitalRead(D1);sensorValue2=digitalRead(D2);sensorValue3=digitalRead(D3);sensorValue4=digitalRead(D4);sensorValue5=digitalRead(D5);sensorValue6=digitalRead(D6);sensorValue7=digitalRead(D7);sensorValue8=digitalRead(D8);sensorValue9=digitalRead(D9);sensorValue10=digitalRead(D10);             
  // turn the ledPin on
   


Serial.println ("D1"); Serial.println(sensorValue1);Serial.println ("D2"); Serial.println(sensorValue2);Serial.println ("D3"); Serial.println(sensorValue3); Serial.println ("D4"); Serial.println(sensorValue4);Serial.println ("D5"); Serial.println(sensorValue5);Serial.println ("D6"); Serial.println(sensorValue6);Serial.println ("D7"); Serial.println(sensorValue7);Serial.println ("D8"); Serial.println(sensorValue8);Serial.println ("D9"); Serial.println(sensorValue9);Serial.println ("D10"); Serial.println(sensorValue10); 
 
delay (1500);
 }
but i think it can be done easyer does somebody know a solution?
Thanks  already!
(sorry for my english)

greets stefan (nl)
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 159
Posts: 2916
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

http://arduino.cc/en/Reference/Array

http://arduino.cc/en/Reference/For
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 216
Posts: 13664
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


because you worked so hard smiley-wink
Code:
//
//    FILE: .pde
//  AUTHOR: Stefan
//    DATE: 
//
// PUPROSE:
//

int PIN[12];

int sensorValue[10];

void setup()
{
  for (uint8_t i=0; i< 10; i++)
  {
    PIN[i] = i+1;
  } 
  for (uint8_t i=0; i< 10; i++)
  {
    pinMode(PIN[i], INPUT);
  }
  Serial.begin(115200);
}

void loop()
{
  for (uint8_t i=0; i< 10; i++)
  {
    sensorValue[i] = digitalRead(PIN[i]);
  } 

  for (uint8_t i=0; i< 10; i++)
  {
    Serial.print("D");
    Serial.print(PIN[i]);
    Serial.print(": \t");
    Serial.println(sensorValue[i]);
  } 
  delay (1500);
}

Rob
PS, if English is not your native language you better set it in your profile than other people will understand it directly,
By the way your English is not bad, visit the forum often and you will learn more than only Arduinese smiley-wink
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


because you worked so hard smiley-wink
Code:
//
//    FILE: .pde
//  AUTHOR: Stefan
//    DATE: 
//
// PUPROSE:
//

int PIN[12];

int sensorValue[10];

void setup()
{
  for (uint8_t i=0; i< 10; i++)
  {
    PIN[i] = i+1;
  } 
  for (uint8_t i=0; i< 10; i++)
  {
    pinMode(PIN[i], INPUT);
  }
  Serial.begin(115200);
}

void loop()
{
  for (uint8_t i=0; i< 10; i++)
  {
    sensorValue[i] = digitalRead(PIN[i]);
  } 

  for (uint8_t i=0; i< 10; i++)
  {
    Serial.print("D");
    Serial.print(PIN[i]);
    Serial.print(": \t");
    Serial.println(sensorValue[i]);
  } 
  delay (1500);
}

Rob
PS, if English is not your native language you better set it in your profile than other people will understand it directly,
By the way your English is not bad, visit the forum often and you will learn more than only Arduinese smiley-wink

Thank You very much!
This is exactly what i ment.
and thanks for the tip btw;)
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 216
Posts: 13664
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

welcome
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: