Pages: [1]   Go Down
Author Topic: using a digital pin to turn an analog sensor on and off for periods of time  (Read 530 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 16
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
int IRpin = 0;                                   
//int IRpin1 = 1;
int ledpin = 8;
//int ledpin1 = 9;
void setup() {
  Serial.begin(9600);
  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);
  //delay(500);
 
  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);
  //delay(1000);
 

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

}
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8958
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can supply power from an Arduino pin if the sensor requires 30 mA or less.  How much current does you sensor need?
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Pages: [1]   Go Up
Jump to: