Jump to content
Sign in to follow this  
earthbound

MSP430F5529 fails to show output of SHARP IR sensor

Recommended Posts

Hi,

 

I'm trying to read analog values from a SHARP IR sensor GP2Y0A41SK0F using the MSP430F5529 launchpad. There was not any error when I verified and uploaded the codes in Energia. However, when I clicked on the Serial Monitor, nothing showed up. But when I chose the MSP430G2452 from the "Tools" menu, the monitor successfully showed the analog values.

 

I connect Vcc (red wire) to 5 V pin, the ground (black wire) to GND pin, and the analog output (white wire) to P6.4 pin/A4 pin. 

 

The same thing also happened to the MSP430G2553 launchpad. It only works when MSP430G2452 is selected. 

 

I looked at the codes very thoroughly but I couldn't see any mistakes:

 
 
const int IR = A4;
 
void setup() 
{
    Serial.begin(9600);
}
 
void loop()
{
    int maxVal = 0, minVal = 1024, n=200;
    float x_i, total=0, mean;
    
    for (int i=1; i <= n; i++)
    {  
        x_i  = analogRead(IR);   
        total  += x_i;
        Serial.println(x_i);
        
        if (x_i < minVal)
       {
           minVal = x_i;
       }
       if (x_i > maxVal)
       {
           maxVal = x_i;
       }    
    }
    mean = total  / n;
    
    Serial.print("minimum = ");
    Serial.print(minVal);
    Serial.print(", maximum = "); 
    Serial.print(maxVal);
    Serial.print(", total = "); 
    Serial.print(total);
    Serial.print(", mean = ");
    Serial.println(mean);
   
    delay(100);
}
 
 
    
 
 

 

 

 

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×