Smart Mirror: CW 42


Electrical/Mechanical:

This is the first and well working draft of our arduino program to control the motors.

/* Connect 5V on Arduino to VCC on Relay Module
Connect GND on Arduino to GND on Relay Module
Connect Power on Arduino to the Common Terminal (middle terminal) on Relay Module.
*/

//////////////////Relay///////////////////////////
const int relay = 5;
// int relayVal;

//////////////////loadCell///////////////////////////
#include “HX711.h”
#define zero_factor 145230
#define DOUT 3 //gelb / yellow
#define CLK 2 //orange
float calibration_factor = ((200000 * 0.00045359237) + 52400);
HX711 scale(DOUT, CLK);

//////////////////Servo///////////////////////////
#include <Servo.h>
Servo myservo360; //continious rotation servo
Servo myservo180; // 180 servo
int direction = 1;
int pos3 = 0;
int pos1 = 0;
const int servPin360 = 9;
const int servPin180 = 8;

 

////////////////Button///////////////////////////////
const int butPin = 12;
int butVal;

 

void setup() {
pinMode(butPin, INPUT);
pinMode(relay, OUTPUT);

Serial.begin(9600);

scale.set_scale(calibration_factor);                    // when u open the serial monitor the value should be between -0.5 and + 0.5: for setting it to 0 we will have to mount it to the box
scale.set_offset(zero_factor);                    //Zero out the scale using a previously known zero_factor
Serial.println(“Reading: “);
close();
}

void loop() {
Serial.println(scale.get_units(), 1);

checkButton(); // function to check if the button is pressed
if (butVal == HIGH) {
myservo360.attach(servPin360);
digitalWrite(relay, LOW); //relay works inverse: LOW = connected to external powersupply

//push the toothpaste out of the cylinder
while (scale.get_units() <= 10) { // when the weight is more then 10, call the function
servo360(); // of the first servo
}
myservo360.detach();
myservo180.attach(servPin180); // connect the second servo

// open the door of the box, so that the user can grab the toothbrush
servo180(); // call the function of the second servo to open the door
myservo180.detach();
}
else {
digitalWrite(relay, HIGH); // disconnect powersupply
}
}
//——-End of Loop——————————-

//——-Start of Functions————————
int checkButton() {
butVal = digitalRead(butPin);
return butVal;
}

void servo360() {
direction = 100; // number < 90: movement clockwise; number > 90: movement counterclockwise; the actual number controles the speed of rotation
myservo360.write(direction);
//to be attached here: stop the movement when the toothpaste is empty. so we need to know the maximum
// in centimeters and calculate it back to the rotation, best is probably to measure it
}

 

void servo180() {
open(); // call function to open the box
while (scale.get_units() < 50) { // do nothing as long as the weight recognised is smaller then 50 (we still need to find out which number actually makes sense through making a few measurements when the toothbrush gets put into the bracket, thats the number we need here)
}
while (scale.get_units() > 50) { // call function close, when toothbrush gets put into the bracket / box
close();
}
}

void open() {
delay(2000); // this delay gives the toothpaste a little bit time to settle onto the toothbrush
direction = 1;
if (direction == 1) {
myservo180.write(140);
delay(100);
}
}
void close() {
delay(2000); // this delay is very important, it should be as accurate as possible and be the average time that a person needs to put the toothbrush back into the bracket, and remove his hand, so that the door doesnt close if the hand is still in the door. maybe we have to use a sensor to make it nicer
direction = 0;
if (direction == 0) {
myservo180.write(0);
delay(1000); // give to servo time to do the movement
}
}

Software:

The software side of the project is moving forward in terms of getting our program to the Raspberry Pi that will be used to provide information to the screen of our smartmirror.

Since we discovered that making a touch-interface would be to expensive, we’ve decided to control the smartmirror using simple voice-commands. User identification is done using facial recognition. The backbones for both the voice- and facial recognition are done, the remaining work for these parts are the configurations needed to get them working on the Pi. We also need to integrate them into our main program which is made in Kivy.

As a screen we have decided to port the Raspberry Pi to an iPad through the built-in VNC functionality of the Pi. Below is a video of the current concept.

 


Leave a Reply