Project I: Y-Axis Magnetic Field to Wheel of Color

Images of Final Project

  1. Overall photo for proportion and scale

Sumayya Syeda’s overall picture

Tiana Porwanto’s overall picture

2. Details of part to highlight

This is the 3-axis compass/magnetometer. It is attached to a a breadboard which is elevated using paddlepop sticks. Adjusting to the group who acts as our input, we are only reading magnetic field in the Y-axis.

This is Tiana’s LED and photoresistor. Tiana’s photoresistor is poorly soldered to the protoboard, which leads to problems such as the code not running through the circuit. The green LED is directly touching the photoresistor to make sure the photoresistor gets the light.

This is our wheel of color with a servomotor as its pointer. The servomotor is supposed to move its handle and choose a color based on the light received by the photoresistor.

This is Sumayya’s LED and photoresistor attached to the protoboard. Her pieces are nicely soldered, creating a great connection through the circuit. Her photoresistor is not touching the LED, but it does face the LED directly.

3. Brief movie in mp4 format

Simple Narrative Description

This double transducer measures a magnet’s strength. Then it converts that measurement to a brightness level for an LED. The LED is brighter when there is more strength, and dimmer when there is less. Then a photoresistor measures how bright the LED is and sends that information to the servo. The servo reads how bright the LED is from the photoresistor and moves its arm accordingly to point to a color on the color wheel. 

Four Progress Images

This is Sumayya’s rough wiring before soldering or gluing any components. It is the rough structure Sumayya had before finalizing the placements of all my sensors.

Sumayya realized she had not added a photoresistor to her circuit. This is the image before she redid her soldering of the LED and photoresistor components.

This is Tiana’s circuit before she soldered or glued any components to the cardboard. At this point, she was still testing whether the code would work on her circuit.

Reading the grading rubric, Tiana realized she needed to solder her middle step (LED -> photoresistor). Professor recommended she use a protoboard and solder both LED and photoresistor to it. This is a picture before the soldering process.

Discussion

While planning for the project, our team decided on a very simple concept: a servomotor pointing a color on a color wheel. However, we later realized that this project was more complicated than planned. It took us some time to understand how the components should be wired and placed on the board while maintaining its aesthetics. We also learned that soldering was hard, since we needed to make sure we had the right circuit before permanently attaching it. This whole process helped us understand the importance of planning and double checking schematics before diving into the hands on work.

While dealing with the software of the project, we realized that we could not code according to theory. For example, mapping did not work great when we inserted min and max value as the input. We went through a lot of trials and errors to understand which interval best suited the mapping. We also realized that hardware issues can happen during the software process. Some pieces may be knocked over and lose their connection, leading us to think it was our software that had problems. By the end of the project, we were still proud of our accomplishments and learned a lot in a short period of time. 

Functional Block Diagram and Schematic

Code Submission

/**
 * @Title: Magnetometer to Color Double Transducer
 * @author: Sumayya Syeda
 * @co-author: Tiana Porwanto
 * 
 * This program measures the magnetic field measured by the QMC5883LCompass to turn a servo motor a certain angle 
 * and point at a certain color
 * The magnetic measurement sets the brightness of an LED. This brightness is measured by a photoresistor. The reading 
 * of the photoresistor sets the angle of the servo motor. 
 */
#include <QMC5883LCompass.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>


QMC5883LCompass Magnet;
LiquidCrystal_I2C lcd(0x27, 20, 4);
Servo servo;

int LED_PIN = 5;
int PHOTORESISTOR_PIN = 3;
int SERVO_PIN = 6;


void setup() {
  pinMode (LED_PIN, OUTPUT);
  pinMode (PHOTORESISTOR_PIN, INPUT);
  
  Magnet.init();
  lcd.init();

  servo.attach(SERVO_PIN);

  lcd.backlight();
  lcd.home();

  lcd.setCursor(16,  .0);

  Serial.begin(9600);
  lcd.println("Program Started!");
}


void loop() {
  // put your main code here, to run repeatedly:

  int avg_m_field
  int brightness;
  int lightVal;
  int servoVal;
  lcd.setCursor(0, 0);


  Magnet.read();
  delay(100);

  //read magnetic field 
  int y = Magnet.getY();
  avg_m_field = abs(y);
  int lcd_mag = map(avg_m_field, 1300, 10000, 0, 99);
  lcd.print("i:");
  lcd.print(abs(lcd_mag));


  //map magnetic field to led brightness
  brightness = map(avg_m_field, 1200, 10000, 0, 255);
  int lcd_brightness = map(brightness, 0, 255, 0, 99);
  lcd.setCursor(9, 0);
  lcd.print("m1:");
  lcd.print(lcd_brightness);
  analogWrite(LED_PIN, brightness);

  //photoresistor reads led brightness
  lightVal = analogRead(PHOTORESISTOR_PIN);
  int lcd_lightVal = map(lightVal, 60, 100, 0, 99);
  lcd.setCursor(0, 1);
  lcd.print("m2:");
  lcd.print(lcd_lightVal);

  //servo maps photoresistor values to servo values
  servoVal = map(lightVal, 60, 100, 10, 170);
  lcd.setCursor(8, 1);
  int lcd_servo = map(servoVal, 10, 170, 0, 99);
  lcd.print("o:");
  lcd.print(lcd_servo);
  servo.write(servoVal);

  delay(500);
  lcd.clear();



}