Skill Dev IV - weiliang

Made by Wei Liang

Created: December 18th, 2020

0

Intention

In this project, we would like to build the connection between information, or data, and actuation. We will use the actuators we studied in this course to create an ambient alert or alarm.

0

Approach and Process

There are tons of data sources. In this project, we can respond to a stock price change, an hourly outside temperature, or email notifications. Also, there are enormous ways to achieve data. In the previous lab, we learned how to use IFTTT to achieve data from Google Calendar. By exploring IFTTT, we can find many accessible data sources to trigger our Particle functions by using IFTTT API.

However, I decided to generate the data myself. I choose the fan as my actuator, so I started my design with a temperature sensor - I tried to read the temperature in my room and trigger the fan by a set point. However, the temperature sensor TMP36 I have is not stable, so I decide to use the ultrasound sensor for another temperature-related situation - to see if there is anything blocking the vent of my Macbook so that it gets overheated.

The diagram is as follows:

The ultrasound sensor HC-SR04 will be placed next to the vent of the Macbook, and so is the brushless DC fan. They will need an external 5V power source. When the HC-SR04 gets small readings, that means there are some objects in front of it and therefore the vent is blocked. Then the DC fan will be triggered and start to run to vent the heat and alert the user to move stuff away.

Please note that the diagram of DC fan is different from the tutorial - I tested the sample diagram of the solenoid on the course website, but it does not work for DC fan. So I searched the internet and found this post (https://www.instructables.com/Arduino-Fan-Controller/). Then I connect the transistor as follows:

Fan Ground - Collector

Digital Control pin - Base

Common Ground - Emitter

The circuit worked after this

0

Code

The code is shown as follows. I modified the loop to fit in the ultrasound sensor. Also, I simplified the doSolenoid function - the fan will just be turned on for 5 seconds instead of doing a loop for 0.5 second on/off five times.

0
int solPin = D4;
int trigPin = D2;    // Trigger
int echoPin = D3;    // Echo
long duration, cm, inches;

bool shouldActivate = false;

void setup()
{
    Particle.function( "activate", activateSolenoid );

    pinMode(solPin, OUTPUT);
    //Define inputs and outputs
	pinMode(trigPin, OUTPUT);
	pinMode(echoPin, INPUT);
}

void loop()
{
    int counter = 0;
    for(int i = 0; i <= 10; i++) {
        // The sensor is triggered by a HIGH pulse of 10 or more microseconds.
	    // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
	    digitalWrite(trigPin, LOW);
	    delayMicroseconds(5);
	    digitalWrite(trigPin, HIGH);
	    delayMicroseconds(10);
	    digitalWrite(trigPin, LOW);

	    // Read the signal from the sensor: a HIGH pulse whose
	    // duration is the time (in microseconds) from the sending
	    // of the ping to the reception of its echo off of an object.
	    pinMode(echoPin, INPUT);
	    duration = pulseIn(echoPin, HIGH);

	    // Convert the time into a distance
	    cm = (duration/2) / 29.1;     // Divide by 29.1 or multiply by 0.0343
	    inches = (duration/2) / 74;   // Divide by 74 or multiply by 0.0135
	    Particle.publish("inches", String(inches)); // This will publish the distance that the Ultrasonic Sensor reads every second
	    if (inches > 10) {
	        counter++;
	    }
	    delay(2000);
    }
    
    if (counter < 2){
        shouldActivate = true;
    }
    
    if( shouldActivate ){
        doSolenoid(  );
        shouldActivate = false;

    }
    delay( 100 );

}

void doSolenoid(  ){
    digitalWrite(solPin, HIGH);
    delay( 5000 ) ;
    digitalWrite(solPin, LOW);
    delay( 100 );
}


int activateSolenoid( String command ){
    shouldActivate = true;
    return 1;
}
Click to Expand
0

Reflection

The demonstration video is shown below. Through this project, I learned how to use diode and transistor to safely control an actuator and know different types of actuators.

0
Skil Dev IV
Wei Liang - https://youtu.be/-XybLqvWz74
x