Guard House prototype

Now it was time for our final project in this course.

Part I: planning

Our (Hannu&Rami) original plan was to make a “demon” guard for my PC to keep my 1 year old son away from it.

But as we went from our drawing board to actually putting all the components together. We noticed that it was nearly impossible to make a working demon with our time and resources . So instead we ended up making a house.

The plan was to make a Guard House that had a ping sensor couple of leds a piezo and a servo with an arm/wheel attached to it. (We also thought of adding a vibrating motor from a PS3 pad but the broken game pad which I had at home didn’t have one so that idea was also thrown out.)

The idea was that the house would react to anything creeping closer to my PC by letting out a warning sound and lighting up the leds and if the threat continued coming the arm would start swinging.

Next obstacle we came up against was the servo not working together with the piezo. No matter what we tried with different component arrangements or different lines of code we couldn’t get them working at the same time.

Both the servo and piezo worked just fine on their own but not together. So we ended up ditching the servo in favor of the piezo.

 

Part II: building & testing

I built the house from a cardboard box which I cut into pieces and put together with some duct tape.

House with a servo and breadbord + piezo inside.

Then we arranged all the components and the Arduino board inside the house and started testing.

 

Part III: finished house

And a video of the house in action:

The house has a function as seen in the youtube clip where you can type a command into the serial monitor. 1 = Sleep mode and 2 = Active mode.

Here is the source code for the project:

/*

Piezo

 

This example shows how to run a Piezo Buzzer on pin 9

using the analogWrite() function.

 

It beeps 3 times fast at startup, waits a second then beeps continuously

at a slower pace

 

*/

 

// Buzzer example function for the CEM-1203 buzzer (Sparkfun’s part #COM-07950).

// by Rob Faludi

// http://www.faludi.com

//modified by Rami Tähtinen and Hannu Holopainen

 

const int pingPin = 7;

const int ledPin = 8;

const int speakerPin = 9;

int limitCm = 100;

 

int halfLimitCm = 50;

 

int lowerLimitCm = 25;

long int duration, distanceInches, distanceCm;

 

void beep(unsigned char delayms){

analogWrite(speakerPin, 145);

delay(delayms);

analogWrite(speakerPin, 0);

delay(delayms);

}

 

void buzz(int targetPin, long frequency, long length) {

long delayValue = 1000000/frequency/2; // calculate the delay value between transitions

//// 1 second’s worth of microseconds, divided by the frequency, then split in half since

//// there are two phases to each cycle

long numCycles = frequency * length/ 1000; // calculate the number of cycles for proper timing

//// multiply frequency, which is really cycles per second, by the number of seconds to

//// get the total number of cycles to produce

for (long i=0; i < numCycles; i++){ // for the calculated length of time…

digitalWrite(targetPin,HIGH); // write the buzzer pin high to push out the diaphram

delayMicroseconds(delayValue); // wait for the calculated delay value

digitalWrite(targetPin,LOW); // write the buzzer pin low to pull back the diaphram

delayMicroseconds(delayValue); // wait againf or the calculated delay value

}

}

 

void setup(){

 

Serial.begin(9600);

pinMode(ledPin, OUTPUT);

pinMode(speakerPin, INPUT);

 

beep(50);

beep(50);

beep(50);

delay(1000);

}

 

void loop()

{

 

if(Serial.available()) {

char kytkin = Serial.read();

 

if(kytkin==’2′) {

while(true) {

 

delay(100);

pinMode(pingPin, OUTPUT);

digitalWrite(pingPin, LOW);

delayMicroseconds(2);

digitalWrite(pingPin, HIGH);

delayMicroseconds(5);

digitalWrite(pingPin, LOW);

 

pinMode(pingPin, INPUT);

duration = pulseIn(pingPin, HIGH);

 

distanceInches = microsecondsToInches(duration);

distanceCm = microsecondsToCentimeters(duration);

 

checkLimit();

Serial.print(distanceInches);

Serial.print(“in, “);

Serial.print(distanceCm);

Serial.print(“cm”);

Serial.println();

 

char kytkin=Serial.read();

if(kytkin==’1′) {

break;

}

 

}

}

 

delay(200);

}

}

 

void checkLimit()

{if (distanceCm < limitCm)

{digitalWrite(ledPin, HIGH);

 

if(distanceCm <(limitCm*0.8) && distanceCm > halfLimitCm){

buzz(9, 5500, 200);

 

delay(1000);

}

 

else if (distanceCm < halfLimitCm && distanceCm > lowerLimitCm){

buzz(9, 5500, 100);

delay(500);}

 

else if (distanceCm < lowerLimitCm){

buzz(9, 5500, 100);}

else{

digitalWrite(speakerPin, LOW);

}

 

}else{

digitalWrite(ledPin, LOW);

 

}

}

 

long microsecondsToInches(long microseconds)

{

 

return microseconds / 74 / 2;

}

 

long microsecondsToCentimeters(long microseconds)

{

 

return microseconds / 29 / 2;

}

Deeper in to the world of sensors

My task this time was to delve deeper in to sensors and find an interesting one that could work with Arduino.  I don’t remember all the sensors that we had at class but I’m pretty sure sure I haven’t seen this one there yet.

The sensor that I found is a Memsic 2125 Dual-axis Accelerometer. As the name suggests it’s an accelerometer with y- and x-axises. I found it on this website: http://www.makershed.com/product_p/mkpx7.htm

Just under 30$ it’s not that expensive but not really cheap either.

The data sheet can be found here: http://www.parallax.com/Portals/0/Downloads/docs/prod/acc/memsickit.pdf

You can also find some example projects and source code from the data sheet.

Here are the main points from the data sheet:

Memsic 2125 dual-axis accelerometer for acceleration, 
tilt and rotation measurement. 
It's a low cost thermal accelerometer capable of  
measuring dynamic acceleration (vibration)
and static acceleration (gravity) with a range  of  ±2  g.

Features:
 Measure 0 to ±2 g on either axis; less than 1 mg resolution
 Fully temperature compensated over 0 to 70 C range
 Simple, pulse output of g-force for X and Y axis ñ direct 
 connection to BASIC Stamp
 Analog output of temperature (TOut pin)
 Low current operation: less than 4 mA at 5 vdc

Connecting the  Memsic 2125 to the  BASIC Stamp is a 
straightforward operation, requiring just two IO pins.

Internally, the Memsic 2125 contains a small heater.
This heater warms a "bubble" of air within the device.  
When gravitational forces act on this bubble it moves.  
This movement is detected by very sensitive thermopiles 
(temperature sensors) and the onboard electronics convert 
the bubble position [relative to g-forces] into pulse 
outputs for the X and Y axis.

I also found this tutorial for the sensor: http://www.mohacks.com/diy-arduino-interfacing-memsic-2125-tutorial

Testing out a sensor with Arduino Duemilanove

Hi, again.

This time its about testing a sensor with my Arduino board. All of us received different sensors from our teacher and I landed with a potentiometer or “potikka” as my teacher first called it. Now I didn’t have much of a clue what a “potikka” was so I googled it and found out that its something called a potentiometri or as its known in English potentiometer.

Then I searched if there was a tutorial of some sort for testing this sensor out with my Arduino board. As it happens there was: http://arduino.cc/en/Tutorial/Potentiometer

int potPin = 2;
int ledPin = 13;
int val = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop() {
val = analogRead(potPin);
digitalWrite(ledPin, HIGH);
delay(val);
digitalWrite(ledPin, LOW);
delay(val);
}

I read the tutorial and followed the instructions to the letter.  I also uploaded the code to my Arduino board and saw that the led was blinking when I inserted the delays in to the code.

Then I wanted to find out if I could alter the current flowing trough the potentiometer by turning the shaft in the middle of the sensor. I did this with a small sharp kitchen knife that happened to be at hand. (my teacher assured me that these sensors didn’t cost too much so I wasn’t too worried about the possible damage it might cause.)

Turning the shaft all the way counter clockwise did… absolutely nothing to the led, and the results were the same vice versa.

I was a bit puzzled as to why this was. Either there was something in the code or something in the sensor. Or maybe both were at fault…

I decided it was time for a different type of approach to see if the potentiometer was reacting to the shaft turning at all.

I followed the example I found here: http://arduino.cc/en/Tutorial/AnalogReadSerial

void setup()
 {
Serial.begin(9600);
}
 void loop() {
int sensorValue = analogRead(A3);
Serial.println(sensorValue);
}

I altered the code a bit as I changed the analogRead(A0) into (A3). For some reason when the wire was plugged into A0 I couldn’t get any reading out of the potentiometer.

Then I opened the serial monitor to see if I was getting any output from the sensor.

Again I turned the shaft left and right to see if there was any difference in the numbers I was getting. There wasn’t.

Only way I could get the numbers to change was to replug the green wire into the analog port or restart the Arduino board.  Based on the numbers turning the shaft didn’t do anything as far as I could see.

This was as far as I was going to test this sensor out today. But if I find out why the flow of the current didn’t change or if it just didn’t show in my tests for some reason I will post the reasons here later so stay tuned.

Jumping in to the world of Arduino

I recently started a course on prototype building taught by Tero Karvinen at Haaga-Helia: https://terokarvinen.com/2012/aikataulu-prototyypin-rakentaminen-bus4tn007-1#comment-7124

Our first assignment was to make our own mini project with the components we received. These included an Arduino board (the model I received was Duemilanove), 3 leds, 5 jump wires, a breadboard and an usb cable.

First thing I did at home was to plug in the Arduino board to my PC via the usb cable. I was doing this with my desktop PC so I was using Windows 7 instead of Linux which I use in my laptop (just clarifying this because I might change the OS and platform later on).

Everything went smoothly from the get-go. Windows immediately recognized the board and installed the necessary drivers. Then I downloaded the development software from: http://arduino.cc/en/Main/Software and installed it. Next logical step was to test if I could upload some “Hello world” code in to the board. I did this by testing the blink example, which you can find from the Arduino software shown in the screen shot below.

PS. remember to make sure you have the right board type selected via Tools -> Board -> model and also check that you’re using the right serial port. Tools -> Serial Port ->

Here is the source code for the blink example:

void setup() {
 
pinMode(13, OUTPUT);
}
 
void loop() {
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
}

Then I plugged in one of the leds  in to the  digital 13 slot on the Arduino board . I tinkered around with the delays to see if I could make changes and upload them to the board. I changed the delays to 500ms and uploaded the code to the board.  Everything worked as planned.

Now that I knew the board was working and that I could upload stuff into the board it was time for the next step. My first mini project.

I decided to make something pretty simple using the three leds.

1. I plugged one of the jump wires in to the GND on the digital side of the Arduino board and then 3 wires in to the slots next to it: 13, 12 and 11.

2. I plugged all the wires in to the breadboard next to each other. (order doesn’t matter)

3. And then I inserted the leds in to the breadboard so that each of them had the shorter leg above the GND wire and longer leg above one of the other wires.

I used the blink example as a basis for the code which I uploaded into my “warning light”.

void setup()
{

pinMode(13, OUTPUT);

pinMode(12, OUTPUT);

pinMode(11, OUTPUT);

}

 

void loop() {

digitalWrite(13, HIGH);

delay(100);

digitalWrite(13, LOW);

delay(100);

digitalWrite(12, HIGH);

delay(100);

digitalWrite(12, LOW);

delay(100);

digitalWrite(11, HIGH);

delay(100);

digitalWrite(11, LOW);

delay(100);

 }

Hello, world! Python vs Java

It is time to compare a couple of programming languages at their most basic. Hello, world!

First I shall test my very limited programming skills with Python.

I’ll go over this step by step:

  1. I open up terminal
  2. I’ll check if I already have python, and yes ubuntu release comes with it
  3. Then I make my first python program with nano: nano hellotest.py
  4. I write the first lines of code as follows: print “Hello, world!”
  5. I save the file and go back to terminal
  6. I write: python hellotest.py and success it prints: Hello, world!

With Python this was pretty much a walk in the park. Now its time for Java.

  1. I know I don’t have Java pre-installed so I have to get it first. I do this by first updating the software list with: sudo apt-get update and then searching for the java package that fits my needs: apt-cache search java jdk and then installing the right package with: sudo apt-get install default-jdk
  2.  And so I begin my quest to understand the enigma that is Java. First of all as a programming noobie Java doesen’t really come off as a beginner friendly language. I had to search instructions how to write hello world from google, unlike in python.
  3. I made it with nano HelloWorld.java and wrote the following lines of code:
    public class HelloWorld
    {
         public static void main(String[] args)
         {
              System.out.println("Hello, world!");
         }
    }
  4. Then I saved the file, went back to terminal and first wrote: javac HelloWorld.java and then: java HelloWorld to execute it.
  5. It worked, but it took me a while with all of my CaseSensitive mistakes and other hickups like writing javac $filename without .java etc.