Hello there,
I'm kinda new to all of this, but after searching for a solution to my problem for weeks I can't find it.
I'm using IR sharp sensor g2py0a41 and g2py0a51 with arduino nano and I get false reading all the time and I can't figure out what's wrong.
Equipment:
arduino nano 33ble
x2 arduino nano 2040 rp connect
arduino duemilanove diecimila (fake)
IR Sharp g2py0a41
IR Sharp g2py0a51
47uF Electrolytic
External Supply is DC 5V 1A
Using gp2y0a41 with some fake arduino duemilanove or diecimila works perfectly fine both with arduino 5v supply and with external 5v supply.
I did have problem with the fake arduino when it was connected to the external supply. I added a capacitor of 47uF and it worked fine, but then when I also removed the capacitor to test it and it worked fine without it too. That's the first thing that confuses me. - Keep in mind the sensor worked perfectly from the start on fake arduino when connected to arduinos 5v supply.
I have also arduino nano rp2040 connect and 33ble.
An object is at 9cm distance and arduino tells me that it is on 6.1 to 6cm distance always and I dont know why, because it works on fake arduino due....
I have a multimeter I tested the voltage between A0 and grnd and I get 1.4 V on all 3 arduinos which is indeed 9cm(from datasheet) but on arduino nanos it prints it as 6.1cm, keep it mind I'm using the same code.
I tried connecting it to the rp 2040s 5v and it still doesn't work. I tried adding capacitors to the external power supply ( tried x1 x2 and even x3 47uF in parallel) and nothing works. I thought the problem is in the sensor so I order also gp2y0a51 and it also doesn't behave on nanos as it should. I tested on 2 different laptops one with ubuntu one with windwos 11. I tried making a low pass filter with 94uF and 10ohms (saw suggested somewhere) it didn't help either. Everything that I saw on forums I've tried but can't figure it out. I measured the current it was around 28mA which is fine(<30mA is normal).
Multimeter shows 1.4 V(9cm) and my arduino nano shows2.1V when i print voltage ( 6cm) while due is fine 1.4v same as multimeter shows.So i thought about shifting the whole table by 0.7V. So whatever Voltage i get i did -0.7 and it works fine for the 9cm but after a certain distance error is simply too great. I also tried 1.4/2.1 and multiply it by whatever voltage I had and again the same problem it works fine 9cm but the more I move from it the greater the error. Even if it did work it doens't explain why the voltage on multimeter is different to the one on nanos while its corrent on due.
So the problem is somewhere between arduino and laptop.The code works on due so it must work, sensor works on due so it must work, nanos work for motors so they are working too but
even if one doesnt work, its hard for me to belive that x2 rp2040 and a 33 ble are false.I'm assuming it can't be anything to do with external power supply,because it works with fake adruino.
The only thing that comes to my mind right now is the usb cable, I didnt have a usb cable that is USBa and micro for ble33 and rp2040 so I went to some store and bought one that is micro and USBa but didnt take care of V and A on it. The duecimila/duemilanove fake arduino uses different cable that I've gotten with it. I am already using arduino nanos to control the motors so I dont think its the problem but I'm just clueless at this point.
If anyone has any ideas even if you're not sure please let me try it out.
I'm also attaching a picture of how I connected it( maybe I connected it wrong) when I used Low pass filter.Without resistor is the case how I connected the bypass capacitors.
Here is the code that I'm using:
#define sensor A0 // Sharp IR GP2Y0A41SK0F (4-30cm, analog)
int dir_z = 8;
int step_z = 7;
int dir_xy = 10;
int step_xy = 9;
int n =50;
void setup() {
Serial.begin(9600); // start the serial port
}
void loop() {
// 5v
delay(2000);
pinMode(dir_xy, OUTPUT);
pinMode(step_xy, OUTPUT);
pinMode(dir_z, OUTPUT);
pinMode(step_z, OUTPUT);
double distance;
distance=measure_distance_and_write_to_SDcard();
Serial.println(distance); // print the distance
}
double measure_distance_and_write_to_SDcard(){
double data[n];
double average=0;
int i=0;
while(i<n){
float volts = analogRead(sensor)*0.0048828125; // value from sensor * (5/1024)
data[i]= 13*pow(volts, -1); // worked out from datasheet graph
average+=data[i];
++i;
}
average/=n;
return average;
}