Showing posts with label Projects. Show all posts
Showing posts with label Projects. Show all posts
How To Make A Voltmeter Using Arduino || 0v - 30v ||

How To Make A Voltmeter Using Arduino || 0v - 30v ||

How To Make A Voltmeter Using Arduino 

In order to measure voltages greater than the 5 V reference voltage, you need to divide the input voltage so that the voltage actually input to the Arduino is 5 V or less. in this experiment, we will use a 90.9 kohm resistor and a 10 kohm resistor to create a 10:1 divider. This will allow us to measure voltages up to 50 V.



Hardware Required
  • 1x Arduino UNO
  • 1x 90.9 kohm resistor
  • 1x 10 kohm resistor
  • 1x LCD (Liquid Crystal Display)
  • 1x 5k potentiometer
  • 1x breadboard
  • female connector
  • jumper wires

Wiring Diagram




Code


#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

float input_voltage = 0.0;
float temp=0.0;
float r1=90900.0;
float r2=10000.0;


void setup()
{
   Serial.begin(9600);     //  opens serial port, sets data rate to 9600 bps
   lcd.begin(16, 2);       // set up the LCD's number of columns and rows: 
   lcd.print("DIGITAL V METER");
}
void loop()
{
   
//Conversion formula

   int analog_value = analogRead(A0);
    temp = (analog_value * 5.0) / 1024.0; 
   input_voltage = temp / (r2/(r1+r2));
   
   if (input_voltage < 0.1) 
   {
     input_voltage=0.0;
   } 
    Serial.print("v= ");
    Serial.println(input_voltage);
    lcd.setCursor(0, 1);
    lcd.print("Voltage= ");
    lcd.print(input_voltage);
    delay(300);
}




How To Make Multifunction LED Chaser With Arduino ||5 in 1||

How To Make Multifunction LED Chaser With Arduino ||5 in 1||

LED Chaser With Arduino

Hello friends. What's up? Hope doing well. Today we are going to make a simple but very interesting LED Chaser with Arduino.

So let's started............



Required Components:


1. Arduino 

2. LED * 4 Pcs { you can take more }
3. Push Button
4. 100 ohm Resistor [ 1/4 watt ] * 4 Pcs
5. Breadboard
6. Some jumper wires.
7. 10k ohm Resistor 



Circuit Diagram:


Here is the circuit diagram.......






Code:




int buttonstate = 0;
int led1 = 3;
int led2 = 5;
int led3 = 6;
int led4 = 9;
int button = 8;
int brightness = 0;

void setup()
{
  pinMode(button, INPUT);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  
  Serial.begin(9600); 
  
}

void mode1(){
  digitalWrite(led1,HIGH);
  digitalWrite(led2,HIGH);
  digitalWrite(led3,HIGH);
  digitalWrite(led4,HIGH);
  delay(100);
  digitalWrite(led1,LOW);
  digitalWrite(led2,LOW);
  digitalWrite(led3,LOW);
  digitalWrite(led4,LOW);
  delay(100);
  }
  
void mode2(){
  digitalWrite(led1,HIGH);
  delay(100);
  digitalWrite(led2,HIGH);
  delay(100);
  digitalWrite(led3,HIGH);
  delay(100);
  digitalWrite(led4,HIGH);
  delay(100);
  digitalWrite(led1,LOW);
  delay(100);
  digitalWrite(led2,LOW);
  delay(100);
  digitalWrite(led3,LOW);
  delay(100);
  digitalWrite(led4,LOW);
  delay(100);
  }

void mode3(){
  digitalWrite(led4,HIGH);
  delay(100);
  digitalWrite(led3,HIGH);
  delay(100);
  digitalWrite(led2,HIGH);
  delay(100);
  digitalWrite(led1,HIGH);
  delay(100);
  digitalWrite(led4,LOW);
  delay(100);
  digitalWrite(led3,LOW);
  delay(100);
  digitalWrite(led2,LOW);
  delay(100);
  digitalWrite(led1,LOW);
  delay(100);
  }

void mode4(){
 
  for (brightness = 0; brightness <= 255; brightness += 5) {
    analogWrite(led1, brightness);
    analogWrite(led2, brightness);
    analogWrite(led3, brightness);
    analogWrite(led4, brightness);
    delay(30); // Wait for 30 millisecond(s)
  }
  for (brightness = 255; brightness >= 0; brightness -= 5) {
    analogWrite(led1, brightness);
    analogWrite(led2, brightness);
    analogWrite(led3, brightness);
    analogWrite(led4, brightness);
    delay(30); // Wait for 30 millisecond(s)
  }

  digitalWrite(led4,HIGH);
  delay(100);
  digitalWrite(led3,HIGH);
  delay(100);
  digitalWrite(led2,HIGH);
  delay(100);
  digitalWrite(led1,HIGH);
  delay(100);
  digitalWrite(led4,LOW);
  delay(100);
  digitalWrite(led3,LOW);
  delay(100);
  digitalWrite(led2,LOW);
  delay(100);
  digitalWrite(led1,LOW);
  delay(100);
  }

 void mode5(){
  mode1();
  mode2();
  mode3();
  mode4();
  }  

void loop()
{
  int value = digitalRead(button);
 
  if(value == 1){
    delay(1000);
  buttonstate = buttonstate + 1 ;
  }
  Serial.println(buttonstate);
  if(buttonstate > 5){
     buttonstate = 0;
  }
  
  if(buttonstate == 1){
     mode1();
  }

  if(buttonstate == 2){
     mode2();
  }

  if(buttonstate == 3){
     mode3();
  }
  if(buttonstate == 4){
     mode4();
  }
  if(buttonstate == 5){
  
  mode5();
  }  


}




Hurray...Our chaser is ready.
This has 5 different function. Pressing the button you can change the chasing style.
 Enjoy : )



Rock Paper Scissor Game With Python

Rock Paper Scissor Game With Python

Rock Paper Scissor Game With Python

Hello friends. What's up? Hope doing well. Today we are going to make a simple but very interesting game with python. It is a childhood game called " Rock Paper Scissor ". So let's start this.......


First of all trust me this is very easy. Just you should have the basic knowledge about python or any other programming language, and that's it!!!!!!

At first you have to install Python on your computer. For that click HERE, download and install python. This is very easy to install python. 

Then I am using PyCharm to edit the code and also run the code. You can use Visual Code Studio, Sublime Text Editor or Python IDLE etc.. as your wish...
You can download and install PyCharm from HERE ... :)

Now let's come to the coding part.
First I have imported random module. It is preinstalled with python. Then I have taken two variables called comp_score, player_score which initial values are 0. And then I have just welcomed the player with print() function.



import random

comp_score = 0
player_score = 0

print("WELCOME")

Then I have made a function called Choose_option() which will take input from user. I have used only if else and elif condition to take inputs from user.


def Choose_Option():
    user_choice = input("Choose Rock, Paper or Scissors: ")
    if user_choice in ["Rock", "rock", "r", "R", "ROCK"]:
        user_choice = "r"
    elif user_choice in ["Paper", "paper", "p", "P", "PAPER"]:
        user_choice = "p"
    elif user_choice in ["Scissors", "scissors", "s", "S", "SCISSORS"]:
        user_choice = "s"
    else:
        print("I don't understand, try again.")
        Choose_Option()
    return user_choice

Then I have made an another function called Computer_option() which will take input from computer. I have used only if else and elif condition to take inputs from computer. In this case computer will generate a random number from 1 to 3. And then the generated number will be the input from computer.


def Computer_Option():
    comp_choice = random.randint(1, 3)
    if comp_choice == 1:
        comp_choice = "r"
    elif comp_choice == 2:
        comp_choice = "p"
    else:
        comp_choice = "s"
    return comp_choice

Then I have created an infinite while loop. Here I have taken inputs from user and computer and then compared the inputs. Then with sum condition I have started to find out if there is a tie or computer win or player win. Then I have distributed the scores among player and computer.

while True:
    #print("")

    user_choice = Choose_Option()
    comp_choice = Computer_Option()

    #print("")

    if user_choice == "r":
        if comp_choice == "r":
            print("You chose rock. The computer chose rock. You tied.")

        elif comp_choice == "p":
            print("You chose rock. The computer chose paper. You lose.")
            comp_score += 1

        elif comp_choice == "s":
            print("You chose rock. The computer chose scissors. You win.")
            player_score += 1

    elif user_choice == "p":
        if comp_choice == "r":
            print("You chose paper. The computer chose rock. You win.")
            player_score += 1

        elif comp_choice == "p":
            print("You chose paper. The computer chose paper. You tied.")


        elif comp_choice == "s":
            print("You chose paper. The computer chose scissors. You lose.")
            comp_score += 1

    elif user_choice == "s":
        if comp_choice == "r":
            print("You chose scissors. The computer chose rock. You lose.")
            comp_score += 1

        elif comp_choice == "p":
            print("You chose scissors. The computer chose paper. You win.")
            player_score += 1

        elif comp_choice == "s":
            print("You chose scissors. The computer chose scissors. You tied.")

    print("")
    print("Player score: " + str(player_score))
    print("Computer score: " + str(comp_score))
    print("")

Then at last of the loop I have Created a condition. If anyone scores 10 then this will break the loop.
Then with another condition it will find out the winner


    if player_score == 10 or comp_score == 10:
        break

print("Game end....... Let's see the result")

if player_score > comp_score:
    print("Congratulation :)\nYou won the game.")

elif player_score == comp_score:
    print("This is a tie")

else:
    print("You lost the match. Try again")


And now our game is fully ready. Enjoy the game :)

Here is the full code-


'''Created By
Zubaer Mahmud
www.screwdrvr.blogspot.com
'''
import random

comp_score = 0
player_score = 0

print("WELCOME")

def Choose_Option():
    user_choice = input("Choose Rock, Paper or Scissors: ")
    if user_choice in ["Rock", "rock", "r", "R", "ROCK"]:
        user_choice = "r"
    elif user_choice in ["Paper", "paper", "p", "P", "PAPER"]:
        user_choice = "p"
    elif user_choice in ["Scissors", "scissors", "s", "S", "SCISSORS"]:
        user_choice = "s"
    else:
        print("I don't understand, try again.")
        Choose_Option()
    return user_choice


def Computer_Option():
    comp_choice = random.randint(1, 3)
    if comp_choice == 1:
        comp_choice = "r"
    elif comp_choice == 2:
        comp_choice = "p"
    else:
        comp_choice = "s"
    return comp_choice


while True:
    #print("")

    user_choice = Choose_Option()
    comp_choice = Computer_Option()

    #print("")

    if user_choice == "r":
        if comp_choice == "r":
            print("You chose rock. The computer chose rock. You tied.")

        elif comp_choice == "p":
            print("You chose rock. The computer chose paper. You lose.")
            comp_score += 1

        elif comp_choice == "s":
            print("You chose rock. The computer chose scissors. You win.")
            player_score += 1

    elif user_choice == "p":
        if comp_choice == "r":
            print("You chose paper. The computer chose rock. You win.")
            player_score += 1

        elif comp_choice == "p":
            print("You chose paper. The computer chose paper. You tied.")


        elif comp_choice == "s":
            print("You chose paper. The computer chose scissors. You lose.")
            comp_score += 1

    elif user_choice == "s":
        if comp_choice == "r":
            print("You chose scissors. The computer chose rock. You lose.")
            comp_score += 1

        elif comp_choice == "p":
            print("You chose scissors. The computer chose paper. You win.")
            player_score += 1

        elif comp_choice == "s":
            print("You chose scissors. The computer chose scissors. You tied.")

    print("")
    print("Player score: " + str(player_score))
    print("Computer score: " + str(comp_score))
    print("")

    if player_score == 10 or comp_score == 10:
        break

print("Game end....... Let's see the result")

if player_score > comp_score:
    print("Congratulation :)\nYou won the game.")

elif player_score == comp_score:
    print("This is a tie")

else:
    print("You lost the match. Try again")

You can download the code from HERE