Sunday, March 12, 2017

Arduino - Interface with HC-SR04 Ultrasonic Sensor

Ultrasonic sensors are used to measure distances from obstacles. We can say that they are like mini-radars. We are using the sensor: HC-SR04

We are building the circuits based on schematics in the following blog:
http://arduinobasics.blogspot.in/2012/11/arduinobasics-hc-sr04-ultrasonic-sensor.html




Step 1: Connect the Ultrasonic Sensor to the Jumper Cable (Ground + VCC)




Step 2: Connect the corresponding Jumper Cable ends to Arduino UNO R3 board at pins referring to 5V and GND.




Step 3: Connect Pins Tr1g and Echo on the Ultrasonic sensor with Jumper Cables




Step 4: The other end of the jumper cables connect to Pin 7 and Pin 8 Respectively on the Arduino.





Step 5: Ultrasonic measures the nearby distance:





Step 6: Measurement displayed on Graph in cm:




Step 7: Ultrasonic measuring farther object:





Step 8:
Measurement displayed on Graph in cm. We can observe the shift in readings:




Code for running the Ultrasonic sensor:

/*
 HC-SR04 Ping distance sensor:
 VCC to arduino 5v 
 GND to arduino GND
 Echo to Arduino pin 7 
 Trig to Arduino pin 8

 This sketch originates from Virtualmix: http://goo.gl/kJ8Gl
 Has been modified by Winkle ink here: http://winkleink.blogspot.com.au/2012/05/arduino-hc-sr04-ultrasonic-distance.html
 And modified further by ScottC here: http://arduinobasics.blogspot.com.au/2012/11/arduinobasics-hc-sr04-ultrasonic-sensor.html
 on 10 Nov 2012.
 */


#define echoPin 7 // Echo Pin
#define trigPin 8 // Trigger Pin
#define LEDPin 13 // Onboard LED

int maximumRange = 200; // Maximum range needed
int minimumRange = 0; // Minimum range needed
long duration, distance; // Duration used to calculate distance

void setup() {
 Serial.begin (9600);
 pinMode(trigPin, OUTPUT);
 pinMode(echoPin, INPUT);
 pinMode(LEDPin, OUTPUT); // Use LED indicator (if required)
}

void loop() {
/* The following trigPin/echoPin cycle is used to determine the
 distance of the nearest object by bouncing soundwaves off of it. */ 
 digitalWrite(trigPin, LOW); 
 delayMicroseconds(2); 

 digitalWrite(trigPin, HIGH);
 delayMicroseconds(10); 

 digitalWrite(trigPin, LOW);
 duration = pulseIn(echoPin, HIGH);

 //Calculate the distance (in cm) based on the speed of sound.
 distance = duration/58.2;

 if (distance >= maximumRange || distance <= minimumRange){
 /* Send a negative number to computer and Turn LED ON 
 to indicate "out of range" */
 Serial.println("-1");
 digitalWrite(LEDPin, HIGH); 
 }
 else {
 /* Send the distance to the computer using Serial protocol, and
 turn LED OFF to indicate successful reading. */
 Serial.println(distance);
 digitalWrite(LEDPin, LOW); 
 }

 //Delay 50ms before next reading.
 delay(500);


Ardiuno - Run Program to operate Proximity Sensor

Step 1: Connect the IR Proximity Sensor to the jumper cables:
Ground should connect with Ground on the Arduino Board
5V should connect with 5V on Arduino Board.




Step 2: We can observe in the pic below,  our Arduino UNO R3 is having all female pins:




Step 3: Hence , we need to use berg sticks to convert it to male pin. This is because, we use the jumper cable to connect to other IC's and Jumper cable are having female pins.




Step 4:  Insert the Berg Sticks into Female Pins of Arduino:






Step 5: Connect the jumper cables such that the 5V cable from the IR proximity sensor connects to the 5V on the Arduino UNO R3 board and GND from the Sensor connects to the GND on the board:




Step 6: Connect Arduino Uno R3 board to the computer using cable.





Step 7: The Red LED on the proximity sensor glows when the finger obstructs the path of the sensor.




Step 8: The Red LED stops glowing on the finger being removed from the path of the IR proximity sensor.




Reference: http://makezilla.com/2016/05/11/obstacle-avoider-robot-using-arduino-uno-and-ir-proximity-sensor/


Ardiuno - Using a Piezo Buzzer with Arduino UNO R3


To Use a Buzzer with Arduino, We have used the link: http://www.instructables.com/id/How-to-use-a-Buzzer-Arduino-Tutorial/?ALLSTEPS

Step 1: We need to make the connection as per the below circuit:





Step 2: Connect the jumper cables to the Piezo Buzzer. Connect he positive cable to the longer wire on the Buzzer.
In case of sensors, positive terminal is the longer wire.


Step 3: Connect the Positve jumper cable to Pin 9 and the negative jumper cable to ground:




Always remember, when connecting cables, positive will connect to positive and negative to negative / ground.

Step 4: Connect the Arduino UNO R3 to the computer using the USB printer cable :





Step 5: Upload the following code to Arduino: This is for providing power supply to the Arduino UNO R3 board.


/* Arduino tutorial - Buzzer / Piezo Speaker
   More info and circuit: http://www.ardumotive.com/how-to-use-a-buzzer-en.html
   Dev: Michalis Vasilakis // Date: 9/6/2015 // www.ardumotive.com */


const int buzzer = 9; //buzzer to arduino pin 9


void setup(){
 
  pinMode(buzzer, OUTPUT); // Set buzzer - pin 9 as an output

}

void loop(){
 
  tone(buzzer, 50); // Send 1KHz sound signal...
  delay(1000);
  noTone(buzzer);     // Stop sound...
  delay(1000);        // ...for 1sec
 
}



This code has sounded the buzzer for 1 second and stopped sounding the buzzer for next 1 second. This cycle in continued in a infinite loop.



Saturday, March 11, 2017

Ardiuno - Ubuntu - Setting up IDE to work with Ardiuno Uno R3 and run Blink Program

Step 1. Download Arduino IDE: https://downloads.arduino.cc/arduino-1.8.1-linux64.tar.xz


Step 2. Extract the package to: /home/sashank/Documents/Arduino_Projects/Tweak/arduino-1.8.1

Step 3. Run the install.sh:

 ~/Documents/Arduino_Projects/Tweak/arduino-1.8.1 $ ./install.sh
Adding desktop shortcut, menu item and file associations for Arduino IDE...touch: cannot touch '/home/sashank/.local/share/applications/mimeapps.list': Permission denied
mv: try to overwrite '/home/sashank/.local/share/applications/mimeapps.list', overriding mode 0644 (rw-r--r--)? y
 done!
 ~/Documents/Arduino_Projects/Tweak/arduino-1.8.1 $


Step 4. Open Arduino IDE.




Step  5. Go through Arduino UNO: https://www.arduino.cc/en/Guide/ArduinoUno

Step 6. Connect your Uno board with an A B USB cable; sometimes this cable is called a USB printer cable




The green power LED (labelled PWR) should go on.




Step 7. Open the Ardiuno IDE . Follow the path ( File -- > Examples -- > 01.Basics --> Blink ) and open the blink program.

Step 8. Click on Verify Button to Verify the program:



Step 9. On verification, we must receive message - Done Compiling in Status Bar:




Step 10. Let us now upload the program to the Ardiuno by clicking on the upload button:




Step 11. After upload we have received error message as follows:



Arduino: 1.8.1 (Linux), Board: "Arduino/Genuino Uno"

Sketch uses 928 bytes (2%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
avrdude: ser_open(): can't open device "/dev/ttyACM0": Permission denied
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
To solve this error, I have referred the below blog:

http://arduino-er.blogspot.in/2014/08/arduino-ide-error-avrdude-seropen-cant.html

Step 12: To fix it, run the following commands at terminal:

sudo usermod -a -G dialout <<username>>
sudo chmod a+rw /dev/ttyACM0


 ~/Documents/Arduino_Projects/Tweak/arduino-1.8.1 $ sudo usermod -a -G dialout sashank
 ~/Documents/Arduino_Projects/Tweak/arduino-1.8.1 $ sudo chmod a+rw /dev/ttyACM0
 ~/Documents/Arduino_Projects/Tweak/arduino-1.8.1 $


Step 13. Upload Again. This time Upload is successful - we have received the following message: Done Uploading




This time received the message:

Sketch uses 928 bytes (2%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.


The blinker is blinking every 1 second. It was already blinking. Hence let us now modify the program for making it to blink every 3 seconds.


Step 14. Make the program to blink every 3 seconds:

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(3000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(3000);                       // wait for a second
}

We find that the orange LED in Arduino is now blinking every 3 seconds:




Success.




Thursday, March 9, 2017

Ubuntu - Install Application - Google Web Designer




Step 1: Download Google Web Designer from website: https://www.google.com/webdesigner

 ~/Downloads $ wget https://dl.google.com/linux/direct/google-webdesigner_current_amd64.deb
--2017-03-09 10:40:33--  https://dl.google.com/linux/direct/google-webdesigner_current_amd64.deb
Resolving dl.google.com (dl.google.com)... 216.58.197.78, 2404:6800:4007:800::200e
Connecting to dl.google.com (dl.google.com)|216.58.197.78|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 31455488 (30M) [application/x-debian-package]
Saving to: 'google-webdesigner_current_amd64.deb'

100%[==============================================================================================================================>] 31,455,488  1022KB/s   in 26s    

2017-03-09 10:41:00 (1.14 MB/s) - 'google-webdesigner_current_amd64.deb' saved [31455488/31455488]

 ~/Downloads $

Step 2: Install
Google Web Designer using dpkg package manager:

$ sudo dpkg -i google-webdesigner_current_amd64.deb
Selecting previously unselected package google-webdesigner.
(Reading database ... 223100 files and directories currently installed.)
Preparing to unpack google-webdesigner_current_amd64.deb ...
Unpacking google-webdesigner (1.3.10.0-1) ...
Setting up google-webdesigner (1.3.10.0-1) ...
Processing triggers for gnome-menus (3.10.1-0ubuntu2) ...
Processing triggers for desktop-file-utils (0.22-1ubuntu1) ...
Processing triggers for mime-support (3.54ubuntu1.1) ...
 ~/Downloads $

Step 3: Check to confirm installation:

 ~/Downloads $ which google-webdesigner
/usr/bin/google-webdesigner
 ~/Downloads $


Ubuntu - Install / Upgrade Application - Chrome - web browser

 


Step 1: Download the latest version of Google Chrome from website: https://www.google.com/chrome/browser/desktop/

 ~/Downloads $ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
--2017-03-08 12:13:03--  https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
Resolving dl.google.com (dl.google.com)... 216.58.203.206, 2404:6800:4009:804::200e
Connecting to dl.google.com (dl.google.com)|216.58.203.206|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 45892904 (44M) [application/x-debian-package]
Saving to: 'google-chrome-stable_current_amd64.deb'

100%[==============================================================================================================================>] 45,892,904   590KB/s   in 85s   

2017-03-08 12:14:30 (530 KB/s) - 'google-chrome-stable_current_amd64.deb' saved [45892904/45892904]

 ~/Downloads $

Step 2: To upgrade Chrome: Let us use gdebi to install this package:

 ~/Downloads $ sudo gdebi "google-chrome-stable_current_amd64.deb"
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Building data structures... Done
Building data structures... Done

The web browser from Google
 Google Chrome is a browser that combines a minimal design with sophisticated technology to make the web faster, safer, and easier.
Do you want to install the software package? [y/N]:y
(Reading database ... 223107 files and directories currently installed.)
Preparing to unpack google-chrome-stable_current_amd64 (3).deb ...
Unpacking google-chrome-stable (56.0.2924.87-1) over (51.0.2704.63-1) ...
Setting up google-chrome-stable (56.0.2924.87-1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for gnome-menus (3.10.1-0ubuntu2) ...
Processing triggers for desktop-file-utils (0.22-1ubuntu1) ...
Processing triggers for mime-support (3.54ubuntu1.1) ...
 ~/Downloads $

Step 3: Check out the version of Chrome Installed:

 ~/Downloads $ google-chrome --version
Google Chrome 56.0.2924.87
 ~/Downloads $
Google Chrome is successfully Upgraded!