Mturk Jobs

Mturk Jobs
Mturk Jobs

Tank

Wednesday, May 2, 2018

How to use ArduDroid App - Control Arduino from Android via Bluetooth

In this post we'll learn how to use ArduDroid to control Arduino board in two way communication via Bluetooth using Android smartphone.

This Android App uses Bluetooth to connect Arduino to Android phone using serial Bluetooth Module HC-05 or HC-06.

Using this App, you can read and write to and from all Arduino board pins and ports.

You can read and write to digital ports, you can control PWM ports to write Analog signals, read Analog values from Analog ports and read/write serial data to the Arduino board.



Picture of ArduDroid: a Simple 2-Way Bluetooth-based Android Controller for Arduino


By connecting Arduino board to the Bluetooth module you can gain full control of it.

Normally, the code is opensource so the solution can be customized to your needs and configuration.

Components
Arduino Board
Bluetooth Module HC-05 or HC-06
Android Phone
ArduDroid App

Connection
Connect Arduino to the Bluetooth module as the author has chosen or use your own configuration by changing the Arduino code.


Picture of ArduDroid: a Simple 2-Way Bluetooth-based Android Controller for Arduino


Picture of Wiring the Circuit


Circuit








Code


/*
 PROJECT: ArduDroid 
 PROGRAMMER: Hazim Bitar (techbitar at gmail dot com)
 DATE: Oct 31, 2013
 FILE: ardudroid.ino
 LICENSE: Public domain
*/

#define START_CMD_CHAR '*'
#define END_CMD_CHAR '#'
#define DIV_CMD_CHAR '|'
#define CMD_DIGITALWRITE 10
#define CMD_ANALOGWRITE 11
#define CMD_TEXT 12
#define CMD_READ_ARDUDROID 13
#define MAX_COMMAND 20  // max command number code. used for error checking.
#define MIN_COMMAND 10  // minimum command number code. used for error checking. 
#define IN_STRING_LENGHT 40
#define MAX_ANALOGWRITE 255
#define PIN_HIGH 3
#define PIN_LOW 2

String inText;

void setup() {
  Serial.begin(9600);
  Serial.println("ArduDroid 0.12 Alpha by TechBitar (2013)");
  Serial.flush();
}

void loop()
{
  Serial.flush();
  int ard_command = 0;
  int pin_num = 0;
  int pin_value = 0;

  char get_char = ' ';  //read serial

  // wait for incoming data
  if (Serial.available() < 1) return; // if serial empty, return to loop().

  // parse incoming command start flag 
  get_char = Serial.read();
  if (get_char != START_CMD_CHAR) return; // if no command start flag, return to loop().

  // parse incoming command type
  ard_command = Serial.parseInt(); // read the command
  
  // parse incoming pin# and value  
  pin_num = Serial.parseInt(); // read the pin
  pin_value = Serial.parseInt();  // read the value

  // 1) GET TEXT COMMAND FROM ARDUDROID
  if (ard_command == CMD_TEXT){   
    inText =""; //clears variable for new input   
    while (Serial.available())  {
      char c = Serial.read();  //gets one byte from serial buffer
      delay(5);
      if (c == END_CMD_CHAR) { // if we the complete string has been read
        // add your code here
        break;
      }              
      else {
        if (c !=  DIV_CMD_CHAR) {
          inText += c; 
          delay(5);
        }
      }
    }
  }

  // 2) GET digitalWrite DATA FROM ARDUDROID
  if (ard_command == CMD_DIGITALWRITE){  
    if (pin_value == PIN_LOW) pin_value = LOW;
    else if (pin_value == PIN_HIGH) pin_value = HIGH;
    else return; // error in pin value. return. 
    set_digitalwrite( pin_num,  pin_value);  // Uncomment this function if you wish to use 
    return;  // return from start of loop()
  }

  // 3) GET analogWrite DATA FROM ARDUDROID
  if (ard_command == CMD_ANALOGWRITE) {  
    analogWrite(  pin_num, pin_value ); 
    // add your code here
    return;  // Done. return to loop();
  }

  // 4) SEND DATA TO ARDUDROID
  if (ard_command == CMD_READ_ARDUDROID) { 
    // char send_to_android[] = "Place your text here." ;
    // Serial.println(send_to_android);   // Example: Sending text
    Serial.print(" Analog 0 = "); 
    Serial.println(analogRead(A0));  // Example: Read and send Analog pin value to Arduino
    return;  // Done. return to loop();
  }
}

// 2a) select the requested pin# for DigitalWrite action
void set_digitalwrite(int pin_num, int pin_value)
{
  switch (pin_num) {
  case 13:
    pinMode(13, OUTPUT);
    digitalWrite(13, pin_value);  
    // add your code here      
    break;
  case 12:
    pinMode(12, OUTPUT);
    digitalWrite(12, pin_value);   
    // add your code here       
    break;
  case 11:
    pinMode(11, OUTPUT);
    digitalWrite(11, pin_value);         
    // add your code here 
    break;
  case 10:
    pinMode(10, OUTPUT);
    digitalWrite(10, pin_value);         
    // add your code here 
    break;
  case 9:
    pinMode(9, OUTPUT);
    digitalWrite(9, pin_value);         
    // add your code here 
    break;
  case 8:
    pinMode(8, OUTPUT);
    digitalWrite(8, pin_value);         
    // add your code here 
    break;
  case 7:
    pinMode(7, OUTPUT);
    digitalWrite(7, pin_value);         
    // add your code here 
    break;
  case 6:
    pinMode(6, OUTPUT);
    digitalWrite(6, pin_value);         
    // add your code here 
    break;
  case 5:
    pinMode(5, OUTPUT);
    digitalWrite(5, pin_value); 
    // add your code here       
    break;
  case 4:
    pinMode(4, OUTPUT);
    digitalWrite(4, pin_value);         
    // add your code here 
    break;
  case 3:
    pinMode(3, OUTPUT);
    digitalWrite(3, pin_value);         
    // add your code here 
    break;
  case 2:
    pinMode(2, OUTPUT);
    digitalWrite(2, pin_value); 
    // add your code here       
    break;      
    // default: 
    // if nothing else matches, do the default
    // default is optional
  } 
}








Source: Instructables








Check our books on Amazon:





Learn By Making: Embedded Systems Tutorial for Students and Beginners









Embedded Systems, Electronics: My Projects Collection From Instructables





Tuesday, May 1, 2018

Bluetooth Arduino RGB Mood Light

In this post, I'll show you how to make a beautiful Arduino RGB Mood Light that can be controlled via Bluetooth.



The circuit is very simple.

You only connect Arduino to the Bluetooth module.

Most popular are HC-05 and HC-06 modules.

They are inexpensive and easy to use.

You can use them to send and receive data to and from Arduino like any serial device.




They have reliable Bluetooth connection with phones and there are many Apps out there that can be used with Arduino projects.


Components



• 1x Arduino uno 
• 1x Bluetooth module (HC-05) or HC-06
• 4x RGB LEDs 
• 1x 9v Battery 
• 4x 100 ohm resistor 
• 1x 9v Battery clip 
• Female-Male jumper wires
• Rainbow cable 
• Perfboard


Connections

Connect the BT module to Arduino
Vcc ---- Arduino 3.3v or 5v (according to your module)
Gnd ---- Arduino gnd
Rx ---- Arduino Tx

Tx ---- Arduino Rx


Picture of Connect the Bluetooth Module to Arduino

LED Connection to Arduino






Code


Android Software

The post says that there is a link for the Android App that controls the Bluetooth module.

But unfortunately, I couldn't find any link to the App.

Thus I searched and found many applications on Google play and Amazon that can make the function of controlling the Bluetooth module and Arduino board.

You can download any of them and start your own Arduino Application.

Here are some of them

ArduDroid
Arduino Bluetooth Control
Ardroid


//pins for the LEDs:
const int redPin = 3;
const int greenPin = 5;
const int bluePin = 6;

const int redPin2 = 9;
const int greenPin2 = 10;
const int bluePin2 = 11;

#define REDPIN 3
#define GREENPIN 5
#define BLUEPIN 6

#define FADESPEED 5

void setup() {
// initialize serial:
Serial.begin(9600);

// make the pins outputs:
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);

pinMode(redPin2, OUTPUT);
pinMode(greenPin2, OUTPUT);
pinMode(bluePin2, OUTPUT);

Serial.print("Arduino control RGB LEDs Connected OK ( Sent From Arduinno Board )");
Serial.print('\n');
}

void loop() {

// if there's any serial available, read it:
while (Serial.available() > 0) {

 // look for the next valid integer in the incoming serial stream:
 int red = Serial.parseInt();
 // do it again:
 int green = Serial.parseInt();
 // do it again:
 int blue = Serial.parseInt();

 int red2 = Serial.parseInt();
 // do it again:
 int green2 = Serial.parseInt();
 // do it again:
 int blue2 = Serial.parseInt();

 // look for the newline. That's the end of your
 // sentence:
 if (Serial.read() == '\n') {
           
   // constrain the values to 0 - 255 and invert
   // if you're using a common-cathode LED, just use "constrain(color, 0, 255);"
   
   // This is for COMMON ANODE
   //red = 255 - constrain(red, 0, 255);
   //green = 255 - constrain(green, 0, 255);
   //blue = 255 - constrain(blue, 0, 255);
  
   red = constrain(red, 0, 255);
   green = constrain(green, 0, 255);
   blue = constrain(blue, 0, 255);
  
   red2 = constrain(red2, 0, 255);
   green2 = constrain(green2, 0, 255);
   blue2 = constrain(blue2, 0, 255);

   // fade the red, green, and blue legs of the LED:
   analogWrite(redPin, red);
   analogWrite(greenPin, green);
   analogWrite(bluePin, blue);
  
   analogWrite(redPin2, red2);
   analogWrite(greenPin2, green2);
   analogWrite(bluePin2, blue2);

   // print the three numbers in one string as hexadecimal:
    Serial.print("Data Response : ");
   Serial.print(red, HEX);
   Serial.print(green, HEX);
   Serial.println(blue, HEX);
 }
}

}




Source: Instructables








Check our books on Amazon:





Learn By Making: Embedded Systems Tutorial for Students and Beginners









Embedded Systems, Electronics: My Projects Collection From Instructables






Sunday, April 29, 2018

Arduino Mosquito Repellent - How you can generate high frequency sounds with Arduino

It's a good practice(and it's a hobby of mine)to see a simple Arduino project that can be easily built from time to time.


Picture of Arduino Mosquito Repeller




Being busy makes us in need to manage our times efficiently to do many things we want to do.

He is a simple Arduino project that I wanted to share with you.

When I first started to learn microcontroller I used to blink that LED as a very primitive embedded software project.



I also wanted to make those signals make sense other than just blinking the LED.

So I used those microcontroller generated signals to drive speakers and buzzers to make sounds with different frequencies.

One of those reasons to make these projects was to make an electronic Mosquito Repellent.

As the legend says, high audio frequencies keep Mosquitoes away from you.

Of course, this turned out to be a hoax and you can try it for yourself. This simply cannot keep pests nor dogs away from you.

This only represents sound for them.

I've tried many circuits and Android App that generated high frequencies to repel Mosquitoes with no use.

However, the project is so easy and can be modified to be used as an Ultrasonic Ranging device.

I thought of modifying the code to make one piezoelectric transducer act as a transmitter and the other to act as a reciever.

I have many trnasducers of them so I want to try that project someday.

Components


Picture of Tools and Components

Arduino Uno
PCB
Piezoelectric Disk
Header Pins
A breadboard (optional)
Wires
Soldering Iron

Soldering Lead



Connections


The circuit is very simple, one of the piezoelectric disk is connected to digital pin 9 and the other to digital pin 11. The left over terminal of both the disks is connected together and soldered to the ground terminal of the Arduino.




Circuit


Picture of Code

Code



int speaker = 9; int frequency = 31000; int speaker2 = 11; int frequency2 = 31000;
void setup(){ pinMode(speaker, OUTPUT); pinMode(speaker2, OUTPUT); }
void loop(){ tone(speaker, frequency, 1000); tone(speaker2, frequency2, 1000); }




Source: Instructables







Check our books on Amazon:





Learn By Making: Embedded Systems Tutorial for Students and Beginners









Embedded Systems, Electronics: My Projects Collection From Instructables



Arduino Automatic Self Powered Water Tap - Use Arduino to control your faucet

In this post, we'll see how to make an Arduino controller self powered automatic water tap.


I've thought of this many times ago. How to make a water tap that opens and closes as you put your hand under it?

This is obvious of course. It needs an infrared transmitter and sensor to track your hands movements and a controller for operation.

What is the problem then?

The only problem is the power that supplies the controller and infrared transmitter and sensor.

Would you make them powered by DC or AC? Would you power them from a battery or from a wall outlet?



In both cases you need to maintain the power source and make sure it is safe and can power the system or otherwise you'll not be able to use the water.

Here in this instructable, the author has made a brilliant idea.

He came up with a simple yet efficient idea to power the system.

He made it self powered. The water tap makes it own power.

Here the faucet system generates its own power by a small hydro-generator.

This small generator can power the system and can also store the power inside a battery to use it in all times.

So you don't need a wall outlet nor you need a battery to keep checking and recharging. The system is self powered.




Picture of Self-Powered Automatic Water Tap

Here is the hydro generator 


Picture of Bill of Materials

Components

1. 3.6V Micro Hydro Generator

2. Screw thread (G 1/2", female)

3. Thread seal tape

4. Arduino Uno

5. IR Transmitter 

6. IR Receiver

7. 56k Resistor

8. 220 ohm resistor

9. PCB board

10. Micro servo motor

11. Polymer Lithium Ion Battery

12. 1.25" diameter plastic pipe


13. Some wires


Code


#include 
int value = 0;
int avg_value = 0;
int sensorPin = A5;  //connect ir receiver output to this pin
int buttonPin = 18;  // button pin to A4
boolean buttonState = HIGH; 
boolean tapState = LOW;
int ledPin = 13; //this is for testing purpose
int tapForState = 0;
Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(buttonPin, HIGH);
  //servo motor is connected to Arduino digital pin 3
  myservo.attach(3);
}

void loop() {
  buttonState = digitalRead(buttonPin);
  delay(50);
  if(buttonState==LOW && tapState==LOW){
    digitalWrite(ledPin, HIGH);
    myservo.write(0);
    delay(7000);
    tapState = HIGH;
    tapForState = 1;  // check either tap was on for button press or not
    }
  else if(buttonState==LOW && tapState==HIGH && tapForState==1){
    digitalWrite(ledPin, LOW);
    myservo.write(80);
    delay(100);
    tapState = LOW;
    tapForState = 0;
    }
  // put your main code here, to run repeatedly:
  for(int i=0; i<20 20="" analogread="" avg_value="" check="" data="" delay="" digitalwrite="" high="" i="" if="" ledpin="" myservo.write="" on="" sensor="" sensorpin="" serial.println="" tap="" tapforstate="2;" tapstate="HIGH;" using="" value="" was="">500 && tapForState==2){
    digitalWrite(ledPin, LOW);
    myservo.write(80);
    delay(100);
    tapState = LOW;
    }
    value = 0;   
}



Source: Instructables








Check our books on Amazon:





Learn By Making: Embedded Systems Tutorial for Students and Beginners









Embedded Systems, Electronics: My Projects Collection From Instructables



Tank