Thursday, 12 February 2015

Controlling stuff with dht11 arduino



This is a small sensor which measures humidity and temperature, when you setup this with Arduino you can control heaters, fans or what what ever you want, in this sketch I've used leds but if you replace the leds with relays you can easily control electrical stuffs. Let's see the sketch then I'll explain bit more about the sketch.

Note: You might need to install dht11 library so that this sketch can work properly. You can get it from http://playground.arduino.cc/main/DHT11Lib. When you go to the site to get the files you will find 4 things. The sketch, dht11.h file, dht11.cpp and test_dewpoint.ino but all the files are in text form and in one page so you will need to make them in different files and to do that you might need to get help from this post.

The sketch
#include <dht11.h>

dht11 DHT11;

#define DHT11PIN 2
int led = 3;
int led2 = 4;

void setup()
{
  Serial.begin(9600);
  Serial.println("DHT11 TEST PROGRAM ");
  Serial.print("LIBRARY VERSION: ");
  Serial.println(DHT11LIB_VERSION);
  Serial.println();
 
pinMode (led,OUTPUT); 
pinMode (led2,OUTPUT); 
}

void loop()
{
  Serial.println("\n");

  int chk = DHT11.read(DHT11PIN);

  Serial.print("Read sensor: ");
  switch (chk)
  {
    case DHTLIB_OK:
        Serial.println("OK");
        break;
    case DHTLIB_ERROR_CHECKSUM:
        Serial.println("Checksum error");
        break;
    case DHTLIB_ERROR_TIMEOUT:
        Serial.println("Time out error");
        break;
    default:
        Serial.println("Unknown error");
        break;
  }

  Serial.print("Humidity (%):  ");
  Serial.println((float)DHT11.humidity, 2);

  Serial.print("Temperature (*C):  ");
  Serial.println((float)DHT11.temperature, 2);


 if (DHT11.humidity >60){
   digitalWrite (led, HIGH);
 } else {
      digitalWrite (led, LOW);
 }

  if (DHT11.temperature >30){
   digitalWrite (led2, HIGH);
 } else {
      digitalWrite (led2, LOW);
 }

   delay(3000);
}


 * The light blue highlighted arrow > you can see after humidity and temperature that means if the humidity or temperature above then 60 or 30 it will turn the led 1 and 2 on otherwise off, and if you put the left arrow < that means if humidity or temperature lower then the number you put after the arrow then it turn the led 1 and 2 on otherwise off.

* "delay(3000)" As you can see delay 3000 that means it will take a measurement after every 3 seconds.

DHT22 with sound alert
Ad


How to get your micro SIM card out from samsung galaxy s5 mini?


Hi, in this small post. I'm going to show you how to take a sim card out of a Samsung Galaxy s5 mini.
I was finding this hard too. After pushing the sim card in I couldn't take it out, then I got this crazy idea. I couldn't believe how easy it was!

Just get a pin from somewhere, which is very easy to find I think. Then place the pin right on the edge of the sim. Then press a bit, not too hard you might damage your sim. Then push outwards as you can see in the picture above.

That's it, hopefully this helps you :)


Sunday, 8 February 2015

Get distance reading on command in arduino

As you might already know how to get distance reading from an ultrasonic sensor in Arduino, but in this post I want to show you a special way to get the distance reading not like you usually see the serial monitor keeps printing the distances, perhaps you will get the reading only when you ask the arduino board to show you the distance.

Ok, the code you going to see here is basically does two thing at once.
(a) it turns on a LED when the distance is more then 30cm, and
(b) it prints the distance when you send a command via serial monitor or bluetooth.

Let's see the code:
int ledPin = 4;
int trigPin = 2;
int echoPin = 3;
void setup() {
  Serial.begin (9600);
  pinMode(ledPin, OUTPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}
String str;

void loop() {
 
  if(Serial.available())
{
str = Serial.readStringUntil('\n');

if(str == "d")
{

  int duration, distance;
  digitalWrite (trigPin, HIGH);
  delayMicroseconds (10);
  digitalWrite (trigPin, LOW);
  duration = pulseIn (echoPin, HIGH);
  distance = (duration/2) / 29.1;

      Serial.print(distance);  
      Serial.print("cm");
      Serial.println();


  }   
 }

 int duration, distance;
  digitalWrite (trigPin, HIGH);
  delayMicroseconds (10);
  digitalWrite (trigPin, LOW);
  duration = pulseIn (echoPin, HIGH);
  distance = (duration/2) / 29.1;
  delay(100);
        
 if (distance > 30) {  // Change the number for long or short distances.
    digitalWrite (ledPin, HIGH);
  } else {
    digitalWrite (ledPin, LOW);
  
  }
}

What is the command code?
Well, the red letter "d" you can see in the "if(str == "d")" statement that is the code, you can change that code to what ever you want and the yellow highlighted code below does the measuring and printing job.

int duration, distance;
  digitalWrite (trigPin, HIGH);
  delayMicroseconds (10);
  digitalWrite (trigPin, LOW);
  duration = pulseIn (echoPin, HIGH);
  distance = (duration/2) / 29.1;

      Serial.print(distance);  
      Serial.print("cm");
      Serial.println();


Note: After uploading this sketch on your arduino > open your serial monitor and type the letter d and send it and the board will send you the distance measurement.
That's it, hopefully this might help you and if you want to know more about this please comment below I'll try my by best to help you. Thanks

Wednesday, 4 February 2015

Serial port 'com3' not found Arduino Nano


Have you ever seen a message like this when you tried to upload a sketch on your Arduino board? if yes then you have got the same problem that I had but luckily I have found the solution after few painful hours of finding out the problem and solve it.

Why do I see "serial port com3 not found"?
Well, when this happened to me I tried to look for the cause of the problem, I found out that I didn't have USB2.0-Serial driver for my PC as you can the screen short below.

Where can I find "USB2.0-Serial" driver?
Go to this page (http://www.driverscape.com/download/usb2.0-serial) and download which ever folder is appropriate for your PC, after downloading the folder unzip it and the go to your Device Manager and update your driver make sure after clicking on the update drive button locate the right path to the folder that you download the above site, once you have successfully update the driver you will see your USB port like the image below.
That's it, now you can upload your sketch and enjoy!!! :)