Week 4: Colour Sensor

This week we decided that we should give everyone tasks at the start of the class so that everyone isn’t working on the same things, so my job was to make sure the circuit worked and write code for colour sensor, Davids job was to test the colour sensor and make any changes to it, Nathans job was to look up and make a design for the robot for the “Race to The Wall” challenge in a few weeks and Seans job was to research future problems or ideas that’ll help us in the road ahead.
So I started off testing the switching motor circuit as last week it would switch by itself occasionally so I started troubleshooting with the multi-meter and found that there was a floating voltage on the switch pin connected to the micro-controller so even when the switch was off, so to fixed this I rewired the switch so the floating voltage would be on the ground pin, Nathan resoldered the switch and after this the the circuit worked and the motor only switched direction when the switch was pressed.
By this time David had done some calculations and and decided to change the resistor connecting between the LED on the colour sensor to ground from a 220 ohm to a 100 ohm to increase the sensitivity of the colour sensor. The two of us tested the colour sensor by measuring the voltage on the signal pin and seen we were getting the full range on the sensor when moving from black to white. After this David took on the task of recording what everyone was doing so we had something to reference when writing the blog.
14907_10200306845030488_1918393772004189605_n
Nathan decided that our robot should be light and sleek for the “Race to The Wall” challenge and had drawn up his design for the robot as well as making a facebook page for us to write ideas and share information with each other. Also he took up the responsibility of constructing the robot, but the rest of us would offer any help he needs it.
Next I started the code for the colour sensor which we had an example of that we would change around for our project. The example code would light an LED when the sensor read anything higher than 514, which is the half way point between white and black for the colour sensor, and like the other circuits we’ve done it didn’t work for time. After troubleshooting we found that again the resistor that was connected across Vcc and test was in the wrong place, this time it was P1.0 and test and the LED was connected to P1.0 so when a voltage was outputted on that pin it was dropped across the resistor. After changing that for hopefully the last time the circuit worked, LED on for bright surfaces and off for dark. The code we used is shown below.

//
// Analog input example for MSP430G2553
//
// Voltage on A3 is converted to 10-bit unsigned int (i.e. between 0-1023).
// An LED is switched on or off, depending whether the measured voltage
// exceeds a threshold value (512).
//
// Written by Ronan Byrne - 13-02-2015
//
 
#include <msp430.h>
 
// Function prototypes
unsigned int read_analog_channel(unsigned int);
 
int main( void )
{
    // Watchdog timer
    WDTCTL = WDTPW + WDTHOLD; // Disable watchdog timer
     
    // Digital i/o
    P2DIR = 0b00000000; // P2.0-7 are inputs
    P1DIR = 0b00000001; // P1.0 is an output, P1.1-7 are inputs
 
    // Analog inputs
    ADC10AE0 = 0b00111000; // A3,A4,A5 (pins 5-7) are analog inputs
    ADC10CTL0 = ADC10ON;   // Turn on the ADC
     
    int voltage;
     
    while(1)
    {
        // Read voltage from analog input A3 (pin 5)
        voltage = read_analog_channel(3);
        
        // If voltage is greater than threshold, light LED
        if (voltage >= 512) P1OUT = 1; // LED on
        else P1OUT = 0;          // LED off
    }
     
    return 0;
}

//
// This function performs a single analog to digital conversion,
// converting the voltage on analog input pin ANx into a 10-bit
// unsigned integer. Execution time for this function is of the
// order of 100us.
//
unsigned int read_analog_channel(unsigned int x)
{
    ADC10CTL0 &= ~ENC;            // disable conversion
    ADC10CTL1 = x << 12;          // select channel
    ADC10CTL0 |= ENC;             // enable conversion
    ADC10CTL0 |= ADC10SC;         // start conversion
    while(ADC10CTL1 & ADC10BUSY); // wait until complete
    return ADC10MEM;              // return digital value
}

At the end of the class me and David rummaged through a box of scraps and found bits and pieces we could use for our robot like a motor and wheels. It was the end of the class so we finished up for the day and would make a start on the code and build of the robot for the challenge next week.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s