Project I: Y-Axis Magnetic Field to Wheel of Color
Images of Final Project
- Overall photo for proportion and scale
2. Details of part to highlight
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
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(); }