Go Down

Topic: using a digital pin to turn an analog sensor on and off for periods of time (Read 956 times) previous topic - next topic


Sup people

i am trying to turn on a ir sensor for a short period of time, see if anything is in its path, turn it off(no ir emitting) and move to the second ir sensor in the row and repeat down the line of sensors, hence avoiding any crosstalk.  this is what i have come up with so far, i put the positive wire (of the analog sensor) in pin 8 of the arduino to supply power to the ir sensor and not supply power when the next row is ready to send out a ir beam.  the objective is to detect an object on a grid while avoiding any crosstalk, sequentialy moving down the row of sensors.

Code: [Select]
int IRpin = 0;                                   
//int IRpin1 = 1;
int ledpin = 8;
//int ledpin1 = 9;
void setup() {
  pinMode(ledpin, OUTPUT); 

void loop() {
  digitalWrite(ledpin, HIGH);    // sets the LED off
  delay(3000); // waits for a second
  float volts = analogRead(IRpin)*0.0048828125;   
  float distance = 27*pow(volts, -1.15);
  float Inches = (distance / 2.54);
  if (Inches >= 2 && Inches <= 8){
  Serial.print("MISS...The ball stopped in ROW1");                               
  //delay(2000);     }
  digitalWrite(ledpin, LOW);   // sets the LED on
  delay(10000);                  // waits for a second
  //float volts1 = analogRead(IRpin1)*0.0048828125;   
  //float distance1 = 27*pow(volts1, -1.15);
  //float Inches1 = (distance1 / 2.54);

//else if (Inches1 >= 2 && Inches1 <= 20){
// Serial.print("MISS...The ball stopped in ROW2");                               
  //delay(2000);     }



You can supply power from an Arduino pin if the sensor requires 30 mA or less.  How much current does you sensor need?
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

Go Up