domenica 22 settembre 2013

Arduino ultrasonic distance measurement

Hi guys' today I'm here with a tutorial about interfacing arduino with ultrasonic distance meter like the HC-SR04.
First of all, the theory:

If we know that the sound take a time to reach the obstacle and come back and that
speed s is equal to s=d/t where d is the distance then d=s*t .
We consider that speed of sound is 340.29 meters/seconds that is equal to
0.034029 centimeters/microseconds.

Now let's see the hardware parts, which is very simple:



To start measuring distance you just have to upload this code to the arduino
int trigPin = 2;
int echoPin = 4;

void setup() {
  Serial.begin(9600);
}

void loop(){
  long duration;
  float cm;
  pinMode(echoPin, INPUT);
  pinMode(trigPin, OUTPUT);
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  cm = microsecondsToCentimeters(duration);
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  delay(100);
}
float microsecondsToCentimeters(long microseconds){
  return (microseconds*0.034029)/2;
}


Here is a video of me testing this project:


I hope you like this post, if you have any question please comment or send me an email to damianoandre@gmail.com

Bye,Dami

mercoledì 4 settembre 2013

Use Arduino with RF Modules

Hi guys, today I'm here with a really cool project.
If you have ever wondered how to make 2 arduinos communicates without using expensive shield, here is the solution: there are some RF modules sold for about 2$ (transmitter + receiver)  that offer one way, easy-to-use communication with a range of about 150 meters.
In this post I'll explain how to use this modules.

First of all you'll need:
-2 arduinos
-a rf transmitter
-a rf receiver

STEP 1: the transmitter
Connect the transmitter to arduino this way:




Upload this code to the arduino connected to the transmitter:
 
#include <VirtualWire.h>
void setup(){
  vw_setup(2000); // bps
  }
void loop(){
  send("hello world"); //your message
  delay(1000);
  }
void send (char *message){
  vw_send((uint8_t *)message, strlen(message));
  vw_wait_tx();
  }

STEP 2: the receiver
Connect the receiver to the arduino this way:





Upload this code to the arduino connected to the receiver:

#include <VirtualWire.h>
byte message[VW_MAX_MESSAGE_LEN];
byte messageLength = VW_MAX_MESSAGE_LEN;
void setup(){
  Serial.begin(9600);
  Serial.println("Device is ready");
  vw_setup(2000); //bps
  vw_rx_start();
  }
void loop(){
  if (vw_get_message(message, &messageLength)){
    Serial.print("Received: ");
      for (int i = 0; i < messageLength; i++){
        Serial.write(message[i]);
        }
      Serial.println();
    }
  }

STEP 3: test ;)
Connect the 2 arudino and check with the serial monitor if it works


I hope you like this post, if you have any question please comment or send me an email to damianoandre@gmail.com

Bye, Dami

martedì 3 settembre 2013

Where to buy electronic parts for cheap

Hi guys Today I'm here with a tip about where to buy electronic parts(Arduino boards, LED, ICs, Arduino Shields, RF modules ecc...) for cheap.
 It's an ebay store located in Hong Kong, here is the link to the ebay page, I think it's a good seller beacuse it offers:
-really low prices
-good quality items
-more than 3000 items
-free shipping
The just thing I found not perfect is the slow shipping, but it's free so however it's good.
I hope you like this post,

Bye, Dami