Go Down

Topic: Interfacing sensors with arduino using a decoder & pnp transistors (Read 1 time) previous topic - next topic

Jasmeet

Hi all,
We are trying to interface 4 sensors with arduino, using a 2 to 4 decoder HS74LS139, and pnp transistors in order to save pins. The decoder circuit works individually, and so does the Arduino board. But when we connect both together, the sensors connected with the transistors donot work. Can anyone help?

runaway_pancake

Could you please be more specific?
In other words: Post Your Schematic
"Who is like unto the beast? who is able to make war with him?"
When all else fails, check your wiring!

Jasmeet

The schematic is attached, though a little bad. We successfully used got 2 sensors working, but as soon as the 3rd is attached, it creates problems. I think the problem lies with the current, 15 mA is required, but we can get only about 5 mA, but then how do the other 2 work? The code is as below: (This is driving us crazy!)
#define echoPin 2 // Echo Pin
#define trigPin 3 // Trigger Pin
#define decoderI1 4  // decoder select line 1
#define decoderI2 5  // decoder select line 2


int safeRange = 30; // Safe range needed
long duration,distance; // Duration used to calculate distance

void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(decoderI1, OUTPUT);
pinMode(decoderI2, OUTPUT);
}

void loop() {
/* The following trigPin/echoPin cycle is used to determine the
distance of the nearest object by bouncing soundwaves off of it. */


// AHEAD
digitalWrite(decoderI1, LOW);
digitalWrite(decoderI2, HIGH);
delay(500);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

digitalWrite(trigPin, HIGH);
delayMicroseconds(20);

digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);

//Calculate the distance (in cm) based on the speed of sound.
distance = duration/58.2;

  if (distance <= safeRange)
   {Serial.println(distance);
Serial.println('ua');} // obstacle ahead

//Delay 500ms before next reading.
delay(500);

// RIGHT
digitalWrite(decoderI1, HIGH);
digitalWrite(decoderI2, LOW);
delay(500);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

digitalWrite(trigPin, HIGH);
delayMicroseconds(20);

digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);

//Calculate the distance (in cm) based on the speed of sound.
distance = duration/58.2;

  if (distance <= safeRange)
   {Serial.println(distance);
        Serial.println('ur');} // obstacle on right

//Delay 500ms before next reading.
delay(500);


// BEHIND
digitalWrite(decoderI1, LOW);
digitalWrite(decoderI2, HIGH);
delay(500);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

digitalWrite(trigPin, HIGH);
delayMicroseconds(20);

digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);

//Calculate the distance (in cm) based on the speed of sound.
distance = duration/58.2;

  if (distance <= safeRange)
   {Serial.println(distance);
Serial.println('ub');} // obstacle behind
delay(500);   
// LEFT
digitalWrite(decoderI1, HIGH);
digitalWrite(decoderI2, HIGH);
delay(500);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

digitalWrite(trigPin, HIGH);
delayMicroseconds(20);

digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);

//Calculate the distance (in cm) based on the speed of sound.
distance = duration/58.2;

if (distance <= safeRange)
   {Serial.println(distance);
Serial.println('ul');} // obstacle on left

//Delay 500ms before next reading.
delay(500);
}

dc42

I've no objection to hand-drawn schematics (I often post them myself), but it would help if you posted your schematic the right way up.

Where in that schematic are the sensors? What sort of sensors are they?
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Jasmeet

Sorry for that! I have connected the Vcc of ultrasonic sensors to the output of the transistors, the trigger, echo and ground pin of all 4 sensors are connected together. The trigger & echo are then connected to arduino; the select lines are also connected to two pins of Arduino. I hope I'm clear now.

dc42


Sorry for that! I have connected the Vcc of ultrasonic sensors to the output of the transistors, the trigger, echo and ground pin of all 4 sensors are connected together.


That isn't going to work well because the ultrasonic sensor modules are not designed to be wired like that. I suggest you power the Vcc pins of all sensors permanently, use demultiplexers to drive the trigger pins (e.g. 74HC138 if they are active low, or 74HC238 if they are active high), and  multiplexers to select the echo pin (if it is a digital signal then use 74HC151, if it is an analog signal then use 74HC4051). All these chips will let you multiplex 8 sensors.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Go Up