<< return to Pixycam.com

Incompatibility with sonar HC-SR04

Hello,

I am triying to use the Pixy2 cam to do a rover that recognises the color from some objects and then go to different places depending of the color. The project has also a HC-SR04 sonar to detect a object during the movements.

Mi code worked perfectly without the camera and when I put the camera to select where to go the sonars measure is always 0.

I have tryied a lot of different things and I don´t know what happens. Could be some type of incompatibility?

I connect the camera to the arduino MEGAs ICSP pins. The sonar ir connected to the digital pins 50 and 48 pins.

Thanks.

Hello,
What type of communication do the sonar sensors use with the Arduino? If they use SPI, or if they use the same I/O signals as the SPI port, you may need to introduce some workarounds.

Can you try using different pins on your Arduino?

Edward

Hello,
I have the sonar connected to the pin 48 and 50. And the Pixy to the ICSP pins. To use the sonar y use this code:

pinMode (trig, OUTPUT);
pinMode(echo, INPUT);
}
void loop() {
digitalWrite(trig, HIGH);
delay(1);
digitalWrite(trig, LOW);
tiempo = pulseIn(echo, HIGH);
distancia = tiempo / 58.2;
Serial.println(distancia);
}

I think that 48 and 50 pin are not in the ICSP pins

You were right, the problem was on the pins that I connect the sonar, they where blocked by the Pixy2 with the ICSP.

Thanks

1 Like