Saturday, August 5, 2023

dc motor with encoder arduino


How to control dc motor with encoder:

Arduino DC Motor Speed Control with Encoder- I have been using different types of stepper motors, Servo motors, and DC Motors for quite a long time in different intermediate and advanced level projects. DC motors are more frequently used than Stepper Motors and Servo Motors. If you have watched my videos and read my articles then you should know DC motors are quite different from Stepper Motors and servo Motors. These three types of motors have a different construction. The stepper motors and servo motors are designed in a way that we can control their position. We can control the steps in the forward and reverse directions. Servos can move from 0 to 180 degrees, so you can move to any position between 0 and 180. Likewise, in stepper motors, you can control the steps precisely and this is the reason stepper motors are used in CNC machines, 3d printers, etc. On the other hand, when a dc motor is powered up it immediately starts rotating, it continuously rotates, you can’t exactly control its position until you use a specific technique.  You can’t 100% control a DC motor like Stepper motor and Servo, but if you add an encoder it can really change the whole game. With an encoder being added, you can keep track of the motor revolutions, the amount of distance it has covered, and this way you can make a nice feedback system that can be used to control the DC motor. Then you can stop the DC motor at the position where you want it to stop. The control of a DC motor using an encoder is not that simple, you just simply can’t start by adding an encoder with the DC Motor and start controlling the DC motor, to use an encoder you will need a controller, the controller will read the encoder and then will accordingly control the DC motor as per the pre-defined instructions written by the programmer.  for this project, you will need a microcontroller board like the Arduino Uno or Arduino Nano, or Arduino Mega, or Arduino pro mini, etc. I know beginners are more comfortable with Arduino Uno, Arduino mega, and Arduino Nano, so I will start with the Arduino Uno, the same connections and programs you can also try on  Arduino Nano and Arduino Mega. To get started, you will need Arduino Uno, a Motor driver, a DC Motor, and of course an Encoder. To read the Encoder, we will connect the encoder output pins with Arduino’s pins 2 and 3 which are the interrupt pins. The power wires of the encoder will be connected with the Arduino’s 5V and GND. To keep things simpler, I will start with the simple example code in which I will use pins 2 and 3 as the normal digital pins, we won’t activate the interrupts and then in the second example code, we will use the interrupts.  Without any further delay, let’s get started!!!

ARDUINO CODE BELOW 

#include<LiquidCrystal.h> //insere a biblioteca Liquid Crystal

LiquidCrystal lsd(6, 7, 8, 9, 10, 11); //define o objeto lsd com as funções da biblioteca Liquid Crystal e suas entradas


#define M1       4 //define a porta de uma entrada do motor

#define M2       3 //define a outra porta da entrada do motor

#define Control  5 //define a saída que controlará a velocidade do motor

#define Pot          A0 //define a entrada do potenciometro

#define Encoder      2 //define a entrada dos pulsos que o motor envia


int vel; //cria a variável que dará o valor da velocidade

volatile float ripple; //define a variável que contará a quantidade de pulsos

unsigned long tempo, //define a variável que receberá o valor de millis()

TheWorld = 1000; //determina o tempo que ocorrerá a contagem 


float RPM, //define a variável que receberá o valor do rpm

ppv = 611, //define a quantidade de pulsos por volta

voltas = 0; //define a variável que receberá a quantidade de voltas


void hamon() { //cria a função que contará os pulsos

  ripple++; //incrementa 1 na variável ripple

}


void setup() //função principal que ocorre apenas uma vez

{

  lsd.begin(16, 2); //incia o lcd informando que é do tipo 16x2

  

  pinMode(M1, OUTPUT); //define uma entrada do motor como saída

  pinMode(M2, OUTPUT); //define a outra entrada do motor como saída

  pinMode(Control, OUTPUT); //define a porta que controlará a velocidade como saída

  pinMode(Encoder, INPUT); //define que a porta que receberá os pulsos será de entrada

  pinMode(Pot, INPUT); //define que a porta do potenciometro será de entrada


  attachInterrupt(0, hamon, RISING); //define a interrupção na porta 2, na função hamon e na subida do pulso

  tempo = 0; //inicia o contador para o millis()

  

  lsd.setCursor(0, 0); //insiro o cursor na coluna 0 e linha 0

  lsd.print("RPM: loading..."); //escrevo a mensagem no lcd

  lsd.setCursor(0, 1); //insiro o cursor na coluna 0 e linha 1

  lsd.print("Voltas: 0.00"); //escrevo a mensagem no lcd

}



void loop()//função principal que acontece repetidas vezes

{

  vel = map(analogRead(Pot), 0, 1023, 0, 255); //mapeio o valor recebido pelo potenciometro em 10 bits para um valor pwm de 8 bits


  analogWrite(Control, vel); //escrevo na porta de controle a velocidade do motor dependendo do potenciometro

  digitalWrite(M1, 1); //defino uma saída do motor como HIGH

  digitalWrite(M2, 0); //defino a outra saída como LOW



  if (millis() - tempo > TheWorld) { //só entra na condição a cada 1 segundo

    noInterrupts(); //interrompo as interrupções

    

    RPM = (ripple / ppv) * 60; //calculo o valor do RPM

    voltas = (voltas + (ripple / ppv)); //calculo o valor das voltas

    

    lsd.setCursor(0, 0); //insiro o cursor na coluna 0 e linha 0

    lsd.print("RPM: "); //escrevo a mensagem no lcd

    lsd.print(RPM, 1); //insiro o valor do RPM no lcd com uma casa decimal

    lsd.print("         "); //espaço em branco para apagar mensagens posteriores

    

    lsd.setCursor(0, 1); //insiro o cursor na coluna 0 e linha 1

    lsd.print("Voltas: "); //escrevo a mensagem no lcd

    lsd.print(voltas); //insiro o valor das voltas no lcd

    

    ripple = 0; //reinicio a contagem de pulsos para que contabilize a cada segundo

    tempo = millis(); //reinicio o "cronometro" para que ele entre na condição novamente daqui a 1s

    

    interrupts(); //retorno com as interrupções

  }



}


/////////////////////////////////////////////////////////////////////////////////ARDUINO CODE IS END 

Sunday, May 29, 2022

Arduino Digital Voltmeter 0V to 30V

 




Here is a useful circuit for Arduino lovers and experimenters. It is a simple digital voltmeter, which can safely measure input dc voltages in 0 to 30V range. The Arduino board can be powered from a standard 9V battery pack, as usual.

As you may well know, Arduino’s analog inputs can be used to measure DC voltage between 0 and 5V (when using the standard 5V analog reference voltage) and this range can be increased by using two resistors to create a voltage divider. The voltage divider decreases the voltage being measured to within the range of the Arduino analog inputs. Code in the Arduino sketch is then used to compute the actual voltage being measured.

The





analog sensor on the Arduino board senses the voltage on the analog pin and converts it into a digital format that can be processed by the microcontroller. Here, we are feeding the input voltage to the analog pin (A0) using a simple voltage divider circuit comprising resistors R1 (100K) and R2 (10K). With the values used in the voltage divider it is possible to feed voltage from 0V to 55V into the Arduino board. The junction on the voltage divider network connected to the the Arduino analog pin is equivalent to the input voltage divided by 11, so 55V ÷ 11 = 5V. In other words, when measuring 55V, the Arduino analog pin will be at its maximum voltage of 5V. So, in practice, it is better to label this voltmeter as “0-30V DVM” to add a safety margin!


Arduino Code: Click Here




Friday, April 29, 2022

GAS INDICATOR USING LCD ARDUINO



detect LPG Gas. When LPG gas leakage sensed, it will give a HIGH pulse on its DO pin and Arduino constantly reads its DO pin.

When Arduino receives a HIGH pulse from the LPG Gas sensor module it displays the“LPG Gas Leakage Alert” message on 16x2 LCD and stimulates buzzer which beeps again until the gas detector module doesn't recognize the gas in the environment. 

When Arduino gets a LOW pulse from the LPG Gas detector module, then LCD will show the“No LPG Gas Leakage” alert message.

Arduino manages the complete process of this system like reading LPG Gas sensor module output, sending a message to LCD and stimulating buzzer. We can set the sensitivity of this sensor module by inbuilt potentiometer located on it.



CIRCUITS DIAGRAM : CLICK HERE


                                                               BOMCLICK HERE



ARDUINO CODE: CLICK HERE

YouTube: https://www.youtube.com/channel/UCcwnTKWxSlkv_iarGQ_zbPg/featured



Instagram:
https://www.instagram.com/?hl=en



Facebook:

https://www.facebook.com/Creative-ideas-EEE-110709481470623/?ref=pages_you_manage


 


Tuesday, April 19, 2022

Automatic Room Temperature Controller

 

Automatic Room Temperature Controller







The project maintains the temperature of a room in [20, 25] degree Celsius.

Story

Sunday, April 10, 2022

ultrasonic sensor with led

 

Step 1: Build the LED Circuit

Build the LED Circuit

Just as you’ve learned from start by wiring up your Arduino and breadboard with power and ground next to the example circuit, then add the the three red LEDs to the breadboard, as shown. These will be the "bar graph" lights for visually indicating the sensor's distance measurement.

    Drag an Arduino Uno and breadboard from the components panel to the workplane, next to the existing circuit.

    Connect the 5 volt and ground pins on the Arduino to the power (+) and ground (-) rails on the breadboard with wires. You can change the wire colors if you want to! Either use the inspector dropdown or the number keys on your keyboard.

    Drag three LEDs on the breadboard in row E, spaced 2 breadboard sockets apart. You can change the LED color using the inspector that pops up when you click on each one.

    Use a 220 Ohm resistor to connect each LED's cathode (left leg) to the ground rail (black) of the breadboard. You can change a resistor's value by highlighting it and using the dropdown menu.

    Connect the LED anodes (right legs) to digital pins 4, 3, and 2 on the Arduino. The LED anode (+) is the terminal that current flows into. This will connect to the digital output pins on the Arduino. The cathode (-) is the terminal that current flows from. This will connect to the ground rail.

    Let's measure distances with an ultrasonic rangefinder (distance sensor) and Arduino's digital input. We'll connect up a circuit using a breadboard and use some simple Arduino code to control a single LED.

    You may have already learned to read a pushbutton and PIR motion sensor with Arduino's digital input, and we'll build on those skills in this lesson.

    Ultrasonic rangefinders use sound waves to bounce off objects in front of them, much like bats using echolocation to sense their environment. The proximity sensor sends out a signal and measures how long it takes to return. The Arduino program receives this information and calculates the distance between the sensor and object.

    Find this circuit on Tinkercad

    Explore the sample circuit embedded here by starting the simulation and clicking on the proximity sensor. This will activate a highlighted area in front of the sensor with a circle "object" inside. You may need to resize the view if the circle is off screen.

    Click and drag the "object" circle closer and further away, noticing the changing distance values on screen. More LEDs will light up the closer you get to the sensor.




    please comment on youtube so that you will get the code 



    ARDUINO LCD PROJECT FOR MEASURING DISTANCE WITH ULTRASONIC SENSOR

    ABOUT THIS PROJECT

    I was using a normal LCD for this project before and then I need to add few sensors in this setup which need more digital pins, so I replace the LCD with a LCD which got I2C board soldered on it.

    Thanks UTSOURCE.net to offer electronic components for this project!

    they deal in all kinds of electronic components, for example, Arduino board, Ultrasonic sensor, and many more.


    watch the tutorial on my channel 



    Be very careful connecting the circuit. Check your work, and it helps to work with a Buddy. Have one person looking at the schematic, and one looking at the circuit. Sometimes it is easier to get it right working in pairs.

    Now the objective of this project is to measure distance using the ultrasonic sensor, and then display that value on the LCD display. You should have the skills you need from the earlier lessons. Try and do this project on your own, but if you get stuck, you can look at my code below. As always, don’t copy and paste my code, but it should be used as a guide to help you write yours if you get stuck.

    our assignment is to get this project going, and show that you can measure distance and then display it on the LCD. After showing me your work, then you need to take the project in your own unique direction. What can you make based on what you have learned in the last few lessons. You should use some combination of Ultrasonic Sensor, LCD, and Servo to make a project or product or your own invention. You have the technical skills, you have the equipment, now go be creative!





    Please Comment on Youtube so that will get the code 
    Arduino Code: Click Here to Get



    YouTube: https://www.youtube.com/channel/UCcwnTKWxSlkv_iarGQ_zbPg/featured



    Instagram:
    https://www.instagram.com/?hl=en



    Facebook:

    https://www.facebook.com/Creative-ideas-EEE-110709481470623/?ref=pages_you_manage



    Saturday, April 9, 2022

    Arduino Game using LCD

     

    Description

    Build An Arduino LCD Game

    One of the greatest things about DIY maker electronics is transforming small, cheap parts into fun and interesting finished projects. Even a 16x2 character 5V LCD screen that is usually used with an Arduino for the simplest of text-based displays (for example: numeric sensor readings) can be utilised in a fascinating way. 


    Attend our workshop this week to learn how to use this limited setup to make a graphics-based game. We’ll use an Arduino and the LCD screen to create a side-scrolling jumping game with a one-button control. For the next step, we’ll port it into a compact prototype.


    Prerequisites 

    - All hardware materials (including Arduinos, LCD screens, pushbuttons etc) will be provided

    - Bring your laptop




    Arduino Code: Here to Download
    if you want Arduino code please comment to me on youtube


    Arduino Code: Here to Download
    if you want Arduino code please comment to me on youtube


    YouTube: https://www.youtube.com/channel/UCcwnTKWxSlkv_iarGQ_zbPg/featured



    Instagram:
    https://www.instagram.com/?hl=en



    Facebook:

    https://www.facebook.com/Creative-ideas-EEE-110709481470623/?ref=pages_you_manage




    dc motor with encoder arduino

    How to control dc motor with encoder: Arduino DC Motor Speed Control with Encoder-  I have been using different types of stepper motors, Ser...