Arduino Geeks http://arduinogeeks.blavery.com/ard A 2014 U3A Class (Sunshine Coast) Wed, 26 Nov 2014 04:06:41 +0000 en-US hourly 1 http://wordpress.org/?v=4.0.1 7 — Nov 27 — Ultrasonic Sonar http://arduinogeeks.blavery.com/ard/27-nov-ultrasonic-sonar/ http://arduinogeeks.blavery.com/ard/27-nov-ultrasonic-sonar/#comments Wed, 19 Nov 2014 05:09:52 +0000 http://arduinogeeks.blavery.com/ard/?p=96 ↓ Read the rest of this entry...]]> Our sonar device has 4 pins:

  • +5 (Vcc)
  • Trigger
  • Echo
  • Gnd

 

We apply a very short positive-going pulse to Trigger pin.

The device sends an ultrasonic “ping” and waits for an echo to return.

Then the Echo pin will send us back a pulse, as long as the echo took to return.

So if we measure the echo pulse length, then, knowing speed of sound through air, we can determine how far away the echoing object was.

 

TRIGGER PIN – pin 4

ECHO PIN – pin 6

 

Paste the script below into a blank arduino edit window, and SAVE AS        “sonar”

 

 

 

Script:

 

 

#define TRIGGER_PIN  4
#define ECHO_PIN     6
#define LED         13

void setup()
  {
  Serial.begin(9600);
  Serial.println("Ultrasonic - Sonar - HC-SR04");
  pinMode(TRIGGER_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(LED, OUTPUT);
  }

void loop()
  {
  int cm;
  long microsec = USonic_timing();
  cm = microsec / 70;   // sound speed about 35 uSec/cm in air - Round path 35x2 = 670
  Serial.print("Dist (cm): ");
  Serial.println(cm);

  delay(1000);
  }

long USonic_timing()
    {
    // 0. just be sure we start from low:
    digitalWrite(TRIGGER_PIN, LOW);
    delayMicroseconds(2);

    // 1. pulse the trigger pin high for 10 usec:
    digitalWrite(TRIGGER_PIN, HIGH);
    delayMicroseconds(10);
    digitalWrite(TRIGGER_PIN, LOW);

    // 2. now measure the length of pulse on echo pin:
    digitalWrite(LED, HIGH);
    long puls = pulseIn(ECHO_PIN, HIGH);
    digitalWrite(LED, LOW);
    return puls;
    }


]]>
http://arduinogeeks.blavery.com/ard/27-nov-ultrasonic-sonar/feed/ 0
6 — Nov 20 — InfraRed Remotes http://arduinogeeks.blavery.com/ard/6-nov-20-infrared-remotes/ http://arduinogeeks.blavery.com/ard/6-nov-20-infrared-remotes/#comments Wed, 19 Nov 2014 05:01:02 +0000 http://arduinogeeks.blavery.com/ard/?p=88 ↓ Read the rest of this entry...]]> We will use the tiny infrared receiver to read the codes sent by TV or DVD remotes.

HOMEWORK:

2 things to download to your laptop’s desktop:

(1)

“IRREMOTE” library. Use the “download ZIP” button at bottom right on:
https://github.com/shirriff/Arduino-IRremote

 

(2)

The following sketch file:

(CTRL-C copy it, then CTRL-V paste it into either a new arduino “sketch” or into a blank text file in NotePad (& save it as something on desktop for now).

 

 

#include <IRremote.h>
#define DEBUG 1

int RECV_PIN = 8;
IRrecv irrecv(RECV_PIN);

decode_results results;

int LED_PIN = 13;

void setup()
{

  Serial.begin(9600);
  Serial.println("Hello");
  delay(200);
  irrecv.enableIRIn(); // Start the receiver
  Serial.println("IR start");
  digitalWrite(LED_PIN, LOW);
}

void loop() {
  if (irrecv.decode(&results)) {
    if (results.value != 0xFFFFFFFF) {
      digitalWrite(LED_PIN, HIGH);
      Serial.println("Addr / Key:");
      Serial.print(0xff & (results.value >> 16), HEX);   // address 
      Serial.print("    /  ");
      Serial.println((0xFF & results.value), HEX);   // function code
      Serial.println();
      delay(100);
      digitalWrite(LED_PIN, LOW);
    }

    irrecv.resume(); // Receive the next value
  }

}

 

]]>
http://arduinogeeks.blavery.com/ard/6-nov-20-infrared-remotes/feed/ 0
5 — Nov 14 — RC Servo Motor http://arduinogeeks.blavery.com/ard/5-nov-14-rc-servo-motor/ http://arduinogeeks.blavery.com/ard/5-nov-14-rc-servo-motor/#comments Wed, 19 Nov 2014 04:59:50 +0000 http://arduinogeeks.blavery.com/ard/?p=86 ↓ Read the rest of this entry...]]> Here is the short sketch we used to allow keyboard to control servo position

 

#include <Servo.h>
// includes the required LIBRARY

Servo myservo;
// Create an object of type Servo, calling it by the name of myservo

void setup()
{
  Serial.begin(9600);  // serial terminal at 9600 baud
  myservo.attach(6);   // assign pin 6 (d6) for servo.  (or pin you used)

}


void loop()
{
    int k = Serial.available();    // check if any character(s) came?
    if (k>0)                       // if character cound above zero ...
    {   int chr = Serial.read()- '0'; // read the incoming character
        if (chr >=0 && chr <=9)       // if it is from 0 up to 9 ...
            myservo.write(chr*20);    // then set servomotor from 0 to 180
    }

}

]]>
http://arduinogeeks.blavery.com/ard/5-nov-14-rc-servo-motor/feed/ 0
4 — Nov 07 — PIR alarm http://arduinogeeks.blavery.com/ard/4-7-nov-tv-remotes/ http://arduinogeeks.blavery.com/ard/4-7-nov-tv-remotes/#comments Thu, 30 Oct 2014 08:47:40 +0000 http://arduinogeeks.blavery.com/ard/?p=81 http://arduinogeeks.blavery.com/ard/4-7-nov-tv-remotes/feed/ 0 3 — Oct 30 — Temp and Light http://arduinogeeks.blavery.com/ard/3-temp-and-light/ http://arduinogeeks.blavery.com/ard/3-temp-and-light/#comments Tue, 28 Oct 2014 05:26:08 +0000 http://arduinogeeks.blavery.com/ard/?p=76 ↓ Read the rest of this entry...]]> We want to measure temperature and light level.

Please bring

  • Laptop
  • Arduino & cables
  • Plus the kit of bits, particularly the tiny bits (which include a light-dependent resistor and a temperature dependent resistor.)

 
int led = 13;
int button = 8;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
pinMode(button, INPUT_PULLUP);            // to define how pins 5 an7 will be used
pinMode(A2, INPUT_PULLUP);
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
Serial.println(analogRead(A2));
digitalWrite(led, LOW);         // WE added.  Led on pin 5 will wink opposite to inbuilt Led on 13
delay(500);               // wait
int butPressed = digitalRead(button);
Serial.print(“Button is currently “);
Serial.println(butPressed);
if ( butPressed == LOW)
{
digitalWrite(led, HIGH);         // WE added.   Led5 keeps winking ONLY on button press
// otherwise it never gets turned on again, stays LOW
}

delay(500);               // wait
}

]]>
http://arduinogeeks.blavery.com/ard/3-temp-and-light/feed/ 0
2 — Oct 23 — Leds & Buttons http://arduinogeeks.blavery.com/ard/2-week-2/ http://arduinogeeks.blavery.com/ard/2-week-2/#comments Wed, 22 Oct 2014 13:51:16 +0000 http://arduinogeeks.blavery.com/ard/?p=68 ↓ Read the rest of this entry...]]> This week (23 Oct), you need to bring:
  • Laptop
  • Arduino & cable
  • Breadboard
  • Jumper wires

 

I will bring:

  • LED lights
  • a pushbutton
  • some resistors

 

We will see how easy it is to control leds and buttons. – WE USED EXAMPLE “BLINK” AND SAVE IT FOR OURSELVES AS “BLINK5″

 

When we added another LED (eg to pin 5) and a BUTTON (eg to pin 7), we wanted to wink the extra LED too, and to have some control by the button.

Copy and paste THIS code into the edit window on your Arduino program:

 

<<<< FROM HERE …

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// And our NEW LED on (say) pin 5:

int led5 = 5;

// And a NEW BUTTON on pin 7:
int button = 7;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);

pinMode(led5, OUTPUT);                    // Two line WE add
pinMode(button, INPUT_PULLUP);            // to define how pins 5 an7 will be used
}

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
digitalWrite(led5, LOW);         // WE added.  Led on pin 5 will wink opposite to inbuilt Led on 13
delay(500);               // wait
digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
if (digitalRead(button) == LOW)
{
digitalWrite(led5, HIGH);         // WE added.   Led5 keeps winking ONLY on button press
// otherwise it never gets turned on again, stays LOW
}

delay(500);               // wait
}

 

 

<<<<<<<< TO HERE

]]>
http://arduinogeeks.blavery.com/ard/2-week-2/feed/ 0
1 — Oct 16 — Setting Up http://arduinogeeks.blavery.com/ard/1-week-1/ http://arduinogeeks.blavery.com/ard/1-week-1/#comments Thu, 16 Oct 2014 22:30:42 +0000 http://arduinogeeks.blavery.com/ard/?p=66 So this week we got our PC “ARDUINO” program loaded and running.

On some, we needed to check serial-chip drivers (Windows) or user privileges (Linux) to get that USB-serial port on the arduino all recognised.

]]>
http://arduinogeeks.blavery.com/ard/1-week-1/feed/ 0
0 — Demo Week http://arduinogeeks.blavery.com/ard/0-demo-week/ http://arduinogeeks.blavery.com/ard/0-demo-week/#comments Wed, 08 Oct 2014 01:51:16 +0000 http://arduinogeeks.blavery.com/ard/?p=47 ↓ Read the rest of this entry...]]> Today we do:

m_yvG1_dwCUwKgGSO6MhRww

 

  • What is the Arduino? 
  • Demo – Some of what it can do: 
    • Sonar – “I can see (hear?) you 85 cm away …”
    • Reading my DVD remote – “c’mon baby change my channel …”
    • Joystick – “oooh, control me …”
    • LED lights – “light my fire …”
  • List “bits” requirements (about $40)

 

 

.

 

 

“The naked CPU chip !”

 

 

.

]]>
http://arduinogeeks.blavery.com/ard/0-demo-week/feed/ 0