For this week's topic on electronic input devices, the class experimented with various sensors like heat sensors, accelerometers, gyroscopes, hall effect magnetic sensors and much more. We then attempted to recreate one of said sensors with a capacitor approach using two contuctive sheets.
As mentioned in my final project page, I did not have an idea as to what I wanted to do. However, during this assignment, after seeing some new sensors and learning about what they could do, I got the idea of making a hand-movement accelerometer controlled overengineered car since I build a car for the microcontroller programming week of this class.
MPU 6050 (Accelerometer/Gyroscope)
Accelerometer
An accelerometer is a device that measures gravitational acceleration. An accelerometer works by sensing static forces like gravity or dynamic forces like vibrations and seeing how they change. For my final project, I will need an accelerometer to add extra controls to the car. For example, I could make it where if a user pulls their hand backwards at a certain speed, the car would break
Gyrosope
A device that uses the physics principles of angular momentum to output the orientation of an object. Gyroscopes measures rotational velocity (rad/s) which is the change of the angular position over time along the X, Y, and Z-axis (roll, pitch, and yaw). This sensor would be very useful for my final project because it would allow me to sense the direction of the user's hand and control the car accordingly.
To make the sensor have a purpose for this assignment, I carefully studied the serial plot of the values the MPU was inputing to the Arduino in order to create a program that advances the motor when leaning sensor forward and stopping it when leaning sensor backwards.
Graph for Sensor Activated Motor
The blue line indicates the tilt upwards or downwards. When the sensor is tilted up, the line goes up and when the sensor is tilted down, the line goes downwards
Code for Sensor Activated Motor
#include Adafruit_MPU6050.h
#include Adafruit_Sensor.h
#include Wire.h
Adafruit_MPU6050 mpu;
const int 3 = A1A;
const int 4 = A1B;
void setup(void) {
Serial.begin(115200);
pinMode(A1A, OUTPUT);
pinMode(A1B, OUTPUT);
digitalWrite(A1A, LOW);
digitalWrite(A1B, LOW);
while (!Serial) {
delay(10); // will pause Zero, Leonardo, etc until serial console opens
}
if (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
mpu.setAccelerometerRange(MPU6050_RANGE_16_G);
mpu.setGyroRange(MPU6050_RANGE_250_DEG);
mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
Serial.println("");
delay(100);
}
void loop() {
/* Get new sensor events with the readings */
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
if (g.gyro.x <= -8) {
digitalWrite(A1A, HIGH);
} else if (g.gyro.x >= 8) {
digitalWrite(A1A, LOW);
digitalWrite(A1B, LOW);
}
/* Print out the values */
Serial.print(a.acceleration.x);
Serial.print(",");
Serial.print(a.acceleration.y);
Serial.print(",");
Serial.print(a.acceleration.z);
Serial.print(", ");
Serial.print(g.gyro.x);
Serial.print(",");
Serial.print(g.gyro.y);
Serial.print(",");
Serial.print(g.gyro.z);
Serial.println("");
delay(10);
}
Circuit of Sensor Activated Motor
Video of Sensor Activated Motor
Other Input Devices
To further increase my knowledge and to help with the acquiring of new ideas, I decided to complete 2 other projects on input devices. My first was the car I built for the week on Microcontroller Programming. I used a piezo sensor in order to activate the car. I did however quickly realize that this method was not quite efficient as I had to physically tap the vehicle. Which is when I discovered microphones. Microphones are a more accurate was of dealing with input activated circuits that piezoelectric sensors and have the extra perk of being hands-free which could reduce wear and tear on the project since knocking on said project won't be necessary.
Circuit
Without LED
With LED
const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
unsigned int sample;
const int LED = 8;
void setup()
{
Serial.begin(9600);
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
}
void loop()
{
unsigned long startMillis= millis(); // Start of sample window
unsigned int peakToPeak = 0; // peak-to-peak level
unsigned int signalMax = 0;
unsigned int signalMin = 1024;
// collect data for 50 mS
while (millis() - startMillis < sampleWindow)
{
sample = analogRead(0); //reading DC pin from pin A0
if (sample < 1024) // toss out spurious readings
{
if (sample > signalMax)
{
signalMax = sample; // save just the max levels
}
else if (sample < signalMin)
{
signalMin = sample; // save just the min levels
}
}
}
peakToPeak = signalMax - signalMin; // max - min = peak-peak amplitude
Serial.println(peakToPeak);
if (peakToPeak >= 8) {
digitalWrite(LED, HIGH);
delay(2000);
digitalWrite(LED, LOW);
}
}
Capacitor Approach
I attempted to recreate an MPU with a capacitor based approach. I used the bottle tilt sensor example as it was the closest to my digital sensor. I then added a buzzer to create an alarm system to warn user if the bottle was spilling (certain tilt angle). Overall, I heard from some classmates that the capacitive was a better solution for the project they were doing. In my case, the capacitor technique actually worsened my project because it wasn't as acurate as an actual MPU. My bottle tilt sensor was only able to detect movement in one way and did not have the ability to mimc an accelerometer.