Showing posts with label Arduino Projects. Show all posts
Showing posts with label Arduino Projects. Show all posts

Using HCSR04 - Ultrasonic Sensor


How the Ultrasonic Sensor works:
Ultrasonic sensors work by emitting sound waves at a frequency too high for humans to hear. They then wait for the sound to be reflected back, calculating distance based on the time of the journey. This is similar to how radar measures the time it takes a radio wave to return after hitting an object.While some sensors use a separate sound emitter and receiver, it’s also possible to combine these into one package device, having an ultrasonic element alternate between emitting and receiving signals. This type of sensor can be manufactured in a smaller package than with separate elements, which is convenient for applications where size is at a premium.
Requirements:

Hardwares
  • Arduino Uno
  • HCSR04 Module
  • Jumper wires
  • LED series with 200 ohm resister(here we will use in-built led on 13 pin)
Softwares
Circuit Diagram

Code to be run:
//In this project, if a object appears in front of Ultrasonic Sensor with in the range 30-50 cm, the led will glow for 5 seconds.

#include <HCSR04.h>

HCSR04 hc(2,3);//initialisation class HCSR04 (trig pin , echo pin)
const int led= 13;
const int uplimit= 50, lowlimit= 30; //Any object between 30cm to 50cm to trigger led//

void setup()
  Serial.begin(9600); 
  pinMode(13,OUTPUT);
}

void loop()
  int distance = hc.dist();
  Serial.println(distance); 
  if( (distance>=lowlimit) && (distance<= uplimit))//OBJECT IN RANGE=LED ON FOR 5 SECS
  {
    digitalWrite(led, HIGH);
    delay(5000);
    digitalWrite(led, LOW);
  }
}


IOT Robot with NodeMCU and Arduino using Blynk.

Introduction:

Controlling robots wirelessly is great fun. There are many methods available through which you can control your robot wirelessly.
They are:
  1.  RF remote controller
  2.  Bluetooth signal
  3.  IR signal
  4.  Wifi or IOT etc...
Here I have made a project of robot controlled over IOT using blynk app,arduino and nodemcu.

Things needed

  • Arduino
  • Nodemcu(Esp8266)
  • 2 DC motors and Motor driver
  • LCD display(may or may not added)
  • Batteries or any other power source
  • Blynk Application 
  • Jumper wires etc.

Step 1: Building the Body of Robot

I Build the robot with Sun-board and card board gluing them with super glue. I used old mobile batteries as source and stick them to body. here are some pictures of my build.


Step 2: Connection of different elements

  • Connect two dc motors to the motor driver. for more about motor drivers follow this:https://www.ganeshgadgets.co.in/2017/09/line-follower-part-2-motor-driver.html
  • Connect arduino to the motor driver. use enable of motor driver with PWM inputs of arduino.
  • Power up nodemcu with arduino from 5v pin. Here the idea is when arduino receives digital output from nodemcu at its input pins it would do certain actions.
  • 5 outputs from nodemcu(D0-D4) is fed to 5 pins of arduino(A0 toA5 -here digital pins are used so pin 14 to pin 19).
  • Example when D0 of nodemcu is high, Arduino receives signal and command noter driver to go forward. 
Code example:
if ( digitalRead(a0) == HIGH ) //forward//
 {
  lcd.setCursor(0, 1);
  lcd.print("FORWARD ");
  digitalWrite(af, HIGH);
  digitalWrite(ar, LOW);
  digitalWrite(bf, HIGH);
  digitalWrite(br, LOW);
 }

                   Step 3: Programming Nodemcu and Arduino

                  Code:
                  #include <LiquidCrystal.h>
                  LiquidCrystal lcd(8, 9, 10, 11, 12, 13); //16x2 lcd interface

                  int en = 3;//a-right motor  b-Left motor //
                  int af = 6;int ar = 7;
                  int bf = 5;int br = 4;

                  int a0=14 , a1=15 , a2= 16 ,a3= 17, a4= 18;//from nodemcu D0 to D4//

                  void setup() {
                  lcd.begin(16, 2); 

                   pinMode(en,OUTPUT);
                   pinMode(ar,OUTPUT);pinMode(af,OUTPUT);
                   pinMode(bf,OUTPUT);pinMode(br,OUTPUT);

                   pinMode(a0,INPUT); pinMode(a1,INPUT); pinMode(a2,INPUT);
                   pinMode(a3,INPUT); pinMode(a4,INPUT);

                   digitalWrite(en,HIGH);
                  // loading();
                  }

                  void loop() {
                    
                    if ( digitalRead(a0) == HIGH ) //forward//
                   {
                    lcd.setCursor(0, 1);
                    lcd.print("FORWARD "); 
                    digitalWrite(af, HIGH);
                    digitalWrite(ar, LOW);
                    digitalWrite(bf, HIGH);
                    digitalWrite(br, LOW);
                   }
                     if (digitalRead(a1) == HIGH) //backward//
                      {
                    lcd.setCursor(0, 1);
                    lcd.print("BACKWARD"); 
                    digitalWrite(af, LOW);
                    digitalWrite(ar,HIGH);
                    digitalWrite(bf, LOW);
                    digitalWrite(br, HIGH);
                      }
                    if (digitalRead(a2) == HIGH)  //RIGHT
                      {
                    lcd.setCursor(0, 1);
                    lcd.print("RIGHT     ");     
                    digitalWrite(af, LOW);
                    digitalWrite(ar,HIGH);
                    digitalWrite(bf, HIGH);
                    digitalWrite(br,LOW);
                        } 
                    if (digitalRead(a3) == HIGH)//LEFT
                      {
                    lcd.setCursor(0, 1);
                    lcd.print("LEFT      ");        
                    digitalWrite(af, HIGH);
                    digitalWrite(ar,LOW);
                    digitalWrite(bf, LOW);
                    digitalWrite(br, HIGH);
                      }
                    if (digitalRead(a4) == HIGH)//STOP
                      {
                    lcd.setCursor(0, 1);
                    lcd.print("STOP      ");        
                    digitalWrite(af, HIGH);
                    digitalWrite(ar, HIGH);
                    digitalWrite(bf, HIGH);
                    digitalWrite(br, HIGH);
                      }  
                    else
                    {
                    lcd.setCursor(0, 1);
                    lcd.print("        ");          
                    digitalWrite(af, HIGH);
                    digitalWrite(ar, HIGH);
                    digitalWrite(bf, HIGH);
                    digitalWrite(br, HIGH);
                     }

                  Conclusion:

                  You can easily build this. you can add lights to the robot and also other features using nodemcu. here is working video of the robot.
                  https://youtu.be/UsY_pJP5PVc

                  Also like and subscribe the channel.

                  “SOLAR TRACKER” USING ARDUINO


                  Solar power is renewable energy source and Solar panel helps in converting the solar power to electric power.
                  Solar tracker is a device which is used to sense solar intensity and rotate the solar panel in that respective direction. It would help in getting maximum solar energy through the solar panel and to its electrical conversion.

                  #wiki_stuffs: Orientation and inclination

                  A solar cell performs the best when its surface is perpendicular to the sun's rays, which change continuously over the course of the day and season. It is a common practice to tilt a fixed PV module (without solar tracker) at the same angle as the latitude of array's location to maximize the annual energy yield of module. For example, rooftop PV module at the tropics provides highest annual energy yield when inclination of panel surface is close to horizontal direction.
                  #wiki_stuffs: A solar tracker is a device that orients a payload toward the Sun. Payloads are usually solar panelsparabolic troughsfresnel reflectorslenses or the mirrors of a heliostat.
                  Things we need!!
                  • 1.      Solar panel (not necessarily a big one a mini could be better)
                  • 2.      DC motor(servo better if you know coding it)
                  • 3.      Motor driver
                  • 4.      Board, Wood piece or panel holding structure.
                  • 5.      Arduino and jumper wires
                  • 6.      Two IR (Infrared) sensors and resistor and diodes.
                  • 7.      Power source (12V or a power bank might work great)
                  • 8.    Incandescent bulb for testing purpose
                  Whats the Idea??
                  The idea is mounting two sensors and two ends of the solar panel and measuring the solar intensity via Arduino and then Arduino commands to tilt the panel toward that direction in which there is more intensity until the intensity of both the sensors became nearly equal. The tilting action can be done by motor and driving circuit.


                  Concept diagram for solar tracker.



                  Build IR Sensor!!


                  • You can easily find IR Receivers near by electronics store and build the above circuit.
                  • Don't forget to place diodes at output it will decrease interference.
                  • SEE REF:http://www.ganeshgadgets.co.in/2017/08/


                  How it looks when it is built!!





                  Coding!!!
                  Coding is simple one. That is the tilting process going on until the difference between the sensor values become less than desired value.
                  ////////////////////////////Code Solar tracker////////////////////////////////////
                  int br = 3;//motor output reverse
                  int bf = 2;//motor output forward //you can use enable at pwm output or make iy short to 5v.

                  int a4=0,a5=0; //analog sensor input
                  int approx=10; //difference limit
                  void setup() {

                    pinMode(bf,OUTPUT);
                    pinMode(br,OUTPUT);
                    pinMode(A4,INPUT);
                    pinMode(A5,INPUT);
                    Serial.begin(9600);

                  }

                  void loop() {
                   a4=analogRead(A4);
                   a5=analogRead(A5);

                   Serial.print(a4);
                    Serial.print(' ');
                    Serial.print(a5);
                    Serial.print(' ');
                    Serial.print(a5-a4);
                    Serial.println(' ');


                  if(a4>a5)
                  {
                  int diff=a4-a5;
                      if(diff > approx)
                      {
                         digitalWrite(bf,HIGH);
                         digitalWrite(br,LOW);
                      }
                      else{digitalWrite(bf,HIGH);
                           digitalWrite(br,HIGH);}
                   }

                  if(a4<a5)
                  {
                  int diff=a5-a4;
                      if(diff > approx)
                      {
                         digitalWrite(bf,LOW);
                         digitalWrite(br,HIGH);
                      }
                       else{digitalWrite(bf,HIGH);
                           digitalWrite(br,HIGH);}
                    } 
                   delay(50);
                   }
                  //////////////////////////////end//////////////////////////////////////

                  Its a good project for students to start with hope you like it.

                  Codes for adding letters to 8X5 leds

                  Codes for Adding letters to 8X5 LEDs

                  From the last blog we have written codes to On/Off a LED individually. So here I gonna explain how to display letters on leds.
                  The trick is simple and that is by blinking a LED each time. The speed is so fast that it appears that all LEDs are ON at same time.

                  I have used the alphabet patterns or you can say fonts as similar to 16x2 LCD display. So letters will be in 7X5 LEDs matrix.

                  Example:
                  So you can blink LEDs row wise(rows first) or column wise. here shows how can you blink LEDs one by one.
                  Code for Writing 'G' is given below:
                  void Gi()
                  {
                   int a=timel;//duration for which letter will be displayed
                   while( a > 0){
                   onled(1,2); onled(1,3); onled(1,4);
                   onled(2,1); onled(2,5);
                   onled(3,1);
                   onled(4,1); onled(4,3); onled(4,4); onled(4,5);
                   onled(5,1); onled(5,5);
                   onled(6,1); onled(6,5);
                   onled(7,2); onled(7,3); onled(7,4); onled(7,5);
                   a--;
                  }}
                  This code can be used in the last blog I posted using as a function.

                  For the complete code click on link... and thanks for visiting.

                  DIY 8x5 LED Matrix display

                  DIY 8x5 LED Matrix display

                  If you want to make a 8X5 led matrix display without using any other MUX with arduino,then this article is for you.
                  Things you needed:
                  1. bunch of LEDs(check before use)
                  2. PCB Board(Brown board)

                  3. Jumper Wires(Male to female)

                  4. Arduino
                  5. 100 ohms resistors
                  6. Soldering Instrument and Hot glue gun

                  Wiring up/ Circuit connections:
                  Before you start have brief idea about leds:

                  • choose healthy LEDs only
                  • do check before soldering on the PCB.
                  • these needs min 1.5V and a few mA current. So accompany them with 200 or 100 ohm resistance.
                  All you need is connect all Anode of leds in a row together and connect all cathode of leds in a column together. The circuit diagram will clear your thoughts.

                  From the above diagram if the row-x is given Low state and column-y is given High state then the LED belongs to (x,y) will glow.
                  But in programming or using arduino the state of all other leds should be in opposite in order to Switch them off.
                  So the idea is to ON one led at a time and make all other leds OFF that time.

                  Here are some pictures while making the circuit:


                  •  Do add resistances(100 ohm or 200 ohms) otherwise the leds may damage due to over current flow. Add female header pins for make it arduino friendly.

                  CODING:

                  here is the code:

                  int row=0,col=0;
                  int time1=5;
                  int timex=1;
                  void onled(int x,int y)//PASSING ROW AND COLUMN VARIABLES TO ON THE RESPECTIVE LED
                  {
                   reset();
                   if(x==1){row=2;} if(x==2){row=3;} if(x==3){row=4;} if(x==4){row=5;} if(x==5){row=6;} if(x==6){row=7;} if(x==7){row=8;} if(x==8){row=9;}
                   if(y==5){col=19;} if(y==4){col=18;} if(y==3){col=17;} if(y==2){col=16;} if(y==1){col=15;}
                   digitalWrite(row,LOW);
                   digitalWrite(col,HIGH);
                   delay(timex);
                  }
                  void reset()//THIS FUNCTION USED TO SUPPLY ANODE WITH gnd AND CATHODE WITH +5V
                  {
                   digitalWrite(2,HIGH);digitalWrite(3,HIGH);digitalWrite(4,HIGH);digitalWrite(5,HIGH);digitalWrite(6,HIGH);digitalWrite(7,HIGH);digitalWrite(8,HIGH);digitalWrite(9,HIGH);
                   digitalWrite(15,LOW);digitalWrite(16,LOW);digitalWrite(17,LOW);digitalWrite(18,LOW);digitalWrite(19,LOW);
                  }

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

                  pinMode(2,OUTPUT);pinMode(3,OUTPUT);pinMode(4,OUTPUT);pinMode(5,OUTPUT);pinMode(6,OUTPUT);pinMode(7,OUTPUT);pinMode(8,OUTPUT);pinMode(9,OUTPUT);
                  pinMode(16,OUTPUT);pinMode(17,OUTPUT);pinMode(18,OUTPUT);pinMode(19,OUTPUT);pinMode(15,OUTPUT);
                  }

                  void loop() {
                   onled(1,1);//on led of row-1 col-1    
                  }
                  The result will look like this:







                  Displaying letters on this will be in the next blog,till then you can use loops for different new patterns.

                  16X2 LCD Interface with Arduino

                  16x2 LCD Interface with Arduino

                  Its quite inconvenience to use serial monitor of Arduino IDE to display data or any message when a wireless display is needed. Thus a on-board display will be helpful for solving this issue. 16x2 LCD is one of the simplest & cheapest display one can use for this purpose.

                  Things needed:
                  - Arduino
                  -16x2 lcd 
                  - Connecting wires

                  About 16x2 LCD :
                  The LCDs have a parallel interface, meaning that the microcontroller has to manipulate several interface pins at once to control the display.
                  The interface consists of the following pins:
                  ·         A register select (RS) pin that controls where in the LCD's memory you're writing data to. You can select either the data register, which holds what goes on the screen, or an instruction register, which is where the LCD's controller looks for instructions on what to do next.
                  ·         Read/Write (R/W) pin that selects reading mode or writing mode
                  ·         An Enable pin that enables writing to the registers
                  ·         data pins (D0 -D7). The states of these pins (high or low) are the bits that you're writing to a register when you write, or the values you're reading when you read.
                  ·         There's also a display constrast pin (Vo), power supply pins (+5V and Gnd) and LED Backlight (Bklt+ and BKlt-) pins that you can use to power the LCD, control the display contrast, and turn on and off the LED backlight, respectively.
                  The process of controlling the display involves putting the data that form the image of what you want to display into the data registers, then putting instructions in the instruction register. The LiquidCrystal Library simplifies this for you so you don't need to know the low-level instructions.

                  Circuit Diagram
                  There are generally 16 pin slots on 16x2 LCD module. Here I have used 12 as shown in the figure. After wiring the module connect it and see if the back light is glowing.

                  Coding Part:
                  Write or past this code in arduino IDE

                  // include the library code:
                  #include <LiquidCrystal.h>
                  char str1[]="GaneshGadgets";
                  char str2[]=".blogspot.com";

                  LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

                  void setup() {
                    // set up the LCD's number of columns and rows:
                    lcd.begin(16, 2);
                  }
                  void loop() {
                  lcd.setCursor(0, 0);//cursor position
                  lcd.print("Ganeshgadgets ");
                  lcd.setCursor(3, 1);
                  lcd.print(".blogspot.com ");
                  }
                  The result will be like this:



                  How to burnt Arduino and repaired it.

                  It is quite harsh and sad if your arduino stops working. It a heart breaking experience because it's your project's heart. I am discussing how one can burnt arduino.
                  Can it be repairable !!! Yes or No?? and if yes HOW!!!











                  How to break/burn/damage Arduino.

                  1. Overvoltage 

                  Though arduino have voltage regulator it works between 5-20V and 7-12 V be the desirable ones. Giving more than that is risky.

                  2. Shorting Input/output pins or overvoltage them.

                       I was once working with a motor driver circuit and one of 12v terminal got connected with input and that damage the AtMega328 IC. Later I was able to replace that one and made my arduino work again.From my experience I suggest that you never short you input or put high volts through them.

                  3. Unwanted connections

                       Recently I damaged my arduino by an unconventional way that is unrepairable. I had a open wire of 12v that came contact with 6pins of FDTI (don't know particular).So this result in damaging the FDTI permanently and the arduino board is shorted. Atmega chip was damaged and when I tried replacing it with another chip....I lost both of them. I have no idea how to repair.

                  4. Over load operations 

                       Another case its not damaged actually,it happen when u tried to switch on and after working a bit it stop suddenly. It may be the supply isn't up to the demand of load connected to arduino. This can be resolved using power source having more ampere power.

                  So up above are the cases one can damage arduino. Now its repairing time.
                  Make sure if it is repairable...
                  First remove the atmega chip from board. For nano,mega and other non removable chip users...RIP...
                  For UNO users remove it. Then plug it up and see if the led of rx/tx and pin-13 blink once or more. If yes then your board is healthy. Replace the Atmega chip with new one with arduino UNO bootloader. It is available in online shopping sites. Most of the Atmega 328 used in arduino comes with uno bootloader. If you can't get a chip I can help you in later blog if I have any requests.
                  If the leds don't blink, or stays on..your board is damaged... RIP...
                  Hope You liked it. Like my blog.
                  "Never lose hope when you fail, those who don't fail haven't tried anything new."
                      

                  First Blink Arduino ;)

                     HOW TO BLINK A LED ON ARDUINO;   

                  Before starting I can say that I am a beginner in Arduino Projects but I am quite fascinated about all these stuffs.

                  "www.arduino.cc" --This is the official website that will be helpful to you if you want to learn all kind of arduino stuffs.


                  Arduino Uno R3
                  Before start we need to have following things.

                  1- Arduino Uno Board(or any other arduino board may      be helpful)
                  2- Serial cable uno-PC connector
                  3- led (or there is an in built led in the board        itself)
                  4- Arduino ide software(download link



                  It is the simplest code for the beginner to begin with.

                  -Install the arduino ide software, its free but you may donate if you have a lot of money.

                  -Then connect the arduino to the PC using the cable.the PC will detect the Arduino uno if you are using win7 or more. For xp or less users you may install the drivers.

                  -then open the software open file>examples>basic>blink
                  -compile the code.
                  -open tools>board>arduino UNO(or any other board you are using)
                  -open tools>ports>"com 3"(or any other port that arduino is connected)
                  - then dump or Upload the code using "=>" right arrow key on the top.
                  -Wait till the code is Uploaded.
                  - Finally you can see a small light blinking on the board.

                  CONGRATES !!!!
                  You have done your first arduino code.
                  And many more to come.