This week on Let’s Make It we have some sensor fun. We play with 5 different sensors connected to the arduino. And you get to watch as we have a colossal failure with one of the sensors. We did not edit it out so you get to see the problems we had. Funny how things stop working when it is show time.
We show you the Virtuabotix DHT11 Digital Temperature / humidity sensor, The Virtuabotix MMA7361 Three Axis Accelerometer, the HC-SR501 Human Sensor Module (motion detector), The Ultrasonic HC-SR04 Distance Sensor, and our big failure this week, the SainSmart Color Recognition / Discrimination Sensor TCS3200d / TCS230D.
Downloads
http://elecfreaks.com/store/download/HC-SR04.pdf
http://www.dfrobot.com/wiki/index.php/TCS3200_Color_Sensor_%28SKU:SEN0101%29
https://www.virtuabotix.com/feed/?attachment_id=1790
http://www.lctech-inc.com/Hardware/Detail.aspx?id=053796b3-3b90-4fe5-8588-7b5d14bc0512
Accelerometer
/*############### VIRTUABOTIX BASIC ACCELEROMETER CODE #########################
This code enables the accelarometer and reads in the values via analog pin
and outputs the values to the serial monitor.
Below is a pinout layout that I took from the sample code header.
######################################################
TO PIN A0 # # To 5 Volts
###### ######
# # X Axis 5 Volt # #
###### ######
TO PIN A1 # #
###### ######
# # Y Axis 3.3 Volt # #
###### ######
TO PIN A2 # # To Ground
###### ######
# # Z Axis Ground # #
###### ######
TO PIN 4 # #
###### ######
# # Sleep GS (Sensitivity Select) # #
###### ######
# #
###### ######
# # 0G ST (Self Test) # #
###### ######
# #
######################################################
Author: Mike Myers (http://mikemyers.me) @netnutmike
Let's Make It Episode 6 (http://tech-zen.tv/index.php/shows/let-s-make-it/episodes/59-sensor-fun-with-arduino-1-massive-failure-but-4-successes-let-s-make-it-episode-6)
http://tech-zen.tv
For the sample code, show notes, contact information and many more videos, visit the show page at
http://tech-zen.tv/letsmakeit
Please subscribe to our YouTube channel or our netcasts at any of your favorite netcast / podcast outlets.
We normally record Let's Make It live on Tuesday evenings around 7pm eastern. You can watch it live by
going to tech-zen.tv and clicking the live link at the top of the page.
We also have a community setup for our viewers and listeners. You can join the community by going to
community.tech-zen.tv.
We love input on what you would like to know or if you have an idea for a new Let's Make it episode,
you can contact us via email or phone at the show information page.
################################################################################*/
int sleepPin= 4; // Turning sleep high turns on the Accelerometer
int HiPrecision=5; // This pin sets the precision. Play with the values by setting it HIGH and LOW
int xpin= A0; // Anolog pin for reading the X value
int ypin = A1; // Analog pin for reading the Y value
int zpin = A2; // Analog pin for reading the Z value
void setup()
{
// Setup serial port for outputting to the serial monitor. Be sure your seial monitor is set to 115200
Serial.begin(115200);
//##########################################
// Setup our pins
//##########################################
//Set the sleep pin as output and set it high to turn on the acceleromiter
pinMode(sleepPin,OUTPUT);
digitalWrite(sleepPin, HIGH);//turns off sleep mode and activates device
//Set the Precision pin to output and set it low. This seems to get the most variation in value.
pinMode(HiPrecision,OUTPUT);
digitalWrite(HiPrecision, LOW);
//Setup each analog pin as input and set the internal pull-up resitor to on.
pinMode(xpin, INPUT);//input mode
digitalWrite(xpin, HIGH);//turn on pull up resistor
pinMode(ypin, INPUT);//input mode
digitalWrite(ypin, HIGH);//turn on pull up resistor
pinMode(zpin, INPUT);//input mode
digitalWrite(zpin, HIGH);//turn on pull up resistor
}
// Time to do the actual work
void loop()
{
delay(2000); //Delay for readability on the serial monitor
/output a title and pin value for X, Y and Z
Serial.print("X Reading: ");
Serial.println(analogRead(xpin), DEC);
Serial.print("Y Reading: ");
Serial.println(analogRead(ypin), DEC);
Serial.print("Z Reading: ");
Serial.println(analogRead(zpin), DEC);
Serial.println(" ");
}
Presence and Distance
/*############### PRESENCE AND DISTANCE SENSORS SAMPLE #########################
This code monitors 2 different sensors. One is monitored for presence and
is basically a motion sensor that turn a pin high when it senses some
motion.
The other sensor is a distance sensor that we send a trigger signal to
and then measure the amount of time it takes to get an echo. Based on
the amount of time we can calculate the distance to an object in front
of the sensor.
From: Mike Myers (http://mikemyers.me) @netnutmike
Let's Make It Episode 6 (http://tech-zen.tv/index.php/shows/let-s-make-it/episodes/59-sensor-fun-with-arduino-1-massive-failure-but-4-successes-let-s-make-it-episode-6)
http://tech-zen.tv
For the sample code, show notes, contact information and many more
videos, visit the show page at http://tech-zen.tv/letsmakeit
Please subscribe to our YouTube channel or our netcasts at any of
your favorite netcast / podcast outlets.
We normally record Let's Make It live on Tuesday evenings around
7pm eastern. You can watch it live by going to tech-zen.tv and clicking
the live link at the top of the page.
We also have a community setup for our viewers and listeners. You can
join the community by going to community.tech-zen.tv.
We love input on what you would like to know or if you have an idea for
a new Let's Make it episode, you can contact us via email or phone at
the show information page.
################################################################################*/
int MovementPin= 5; // Define the pin we will use to read the presense state
int TriggerPin=13; // Define the pin that we use to set off the trigger
int EchoPin= 12; // Define the pin that we will use to read the echo response
void setup()
{
// Start the serial port for the seial monitor at 115200. Be sure your serial monitor is 115200
Serial.begin(115200);
// Setup the pins for INPUT and OUTPUT
pinMode(TriggerPin,OUTPUT); // output Mode
pinMode(EchoPin, INPUT); // input mode
pinMode(MovementPin, INPUT); // input mode
}
void loop()
{
// define the 2 variables that we will use in this function
long duration, distance;
// set the pin low and wait 2 microseconds
digitalWrite(TriggerPin, LOW);
delayMicroseconds(2);
// set the trigger pin high to transmit sound for 10 microseconds
digitalWrite(TriggerPin, HIGH);
delayMicroseconds(10);
// after 10 microseconds turn off the transmitter
digitalWrite(TriggerPin, LOW);
// read the duration by timing how long it takes for the echo to stop
duration = pulseIn(EchoPin, HIGH);
distance = duration / 148; // device the duration by 148 for inches or 58 for centimeters
// output the distance calculated
Serial.print(distance);
Serial.println(" inches");
//check the pin for movement. If it is high then movment was detected, so output to serial
if (digitalRead(MovementPin)) {
Serial.println("Movement Detected");
}
// just a blank line to make the serial monitor easier to read
Serial.println(" ");
delay(2000); //Delay for readability
}