Translate

ARDUINO PROJECTS

AUTOMATIC DINO GAME

here's a little game made by google chrome when the computer is offline.  thanks to arduino it possible to play it automatically without pressing a key. It based on an arduino uno, a photoresistor(LDR),a 1K resistor, and a servo motor.
The photoresistor detect the light from obstacle which are trees in the game and send to arduino a value different then before, if this value is equal or greater than a defined value in arduino then the servo motor rotates  90 degree and presses the space button on the keyboard for 250 milliseconds, after this the dino jump the obstacle.

This is the schematic



















here is the code:

#include <Servo.h>
int pot=A0;
int val;
Servo myservo;
void setup() {
  Serial.begin(9600);
  myservo.attach(9);
}

void loop() {
  myservo.write(90);                         
  val=analogRead(pot);
  Serial.println(val);
  if(val>=730){
   myservo.write(0);
   delay(250);
   myservo.write(90);
  }                                                   
}

a video that show how it works:




A SMALL PIANO

In this project we are going to learn how to make sound with Arduino. We are going to build a simple Micro Piano in order to demonstrate the capabilities of the tone function. Let's start! Playing back sound is great for adding audio feedback to our projects. So far we were using displays or LEDs in order to provide feedback to the user of the project. Today we will learn how to make sound with Arduino and as you are going to find out, it is very easy. In order to demonstrate the sound capabilities of the Arduino Uno, I have built a simple project, a micro Piano. Each time I press a button, Arduino makes a sound of a specific frequency for each button. The frequencies correspond to specific music notes, we have 7 buttons, so we can have 7 notes! So, let's try it. I am going to play a simple song using the available notes.
In this project I used :
-7 keys
-1 a blue LED
-1 resistor(220)
-1 passive buzzer

the code is below🔽

#define T_C 262
#define T_D 294
#define T_E 330
#define T_F 349
#define T_G 392
#define T_A 440
#define T_B 493

const int C = 10;
const int D = 9;
const int E = 8;
const int F = 7;
const int G = 6;
const int A = 5;
const int B = 4;

const int Buzz = 3;
const int LED = 13;

void setup()
{
  pinMode(LED, OUTPUT);
  pinMode(C, INPUT);
  digitalWrite(C,HIGH);
 
  pinMode(D, INPUT);
  digitalWrite(D,HIGH);
 
  pinMode(E, INPUT);
  digitalWrite(E,HIGH);
 
  pinMode(F, INPUT);
  digitalWrite(F,HIGH);
 
  pinMode(G, INPUT);
  digitalWrite(G,HIGH);
 
  pinMode(A, INPUT);
  digitalWrite(A,HIGH);
 
  pinMode(B, INPUT);
  digitalWrite(B,HIGH);

   digitalWrite(LED,LOW);
}

void loop()
{
  while(digitalRead(C) == LOW)
  {
    tone(Buzz,T_C);
    digitalWrite(LED,HIGH);
  }

  while(digitalRead(D) == LOW)
  {
    tone(Buzz,T_D);
    digitalWrite(LED,HIGH);
  }

  while(digitalRead(E) == LOW)
  {
    tone(Buzz,T_E);
    digitalWrite(LED,HIGH);
  }

  while(digitalRead(F) == LOW)
  {
    tone(Buzz,T_F);
    digitalWrite(LED,HIGH);
  }

  while(digitalRead(G) == LOW)
  {
    tone(Buzz,T_G);
    digitalWrite(LED,HIGH);
  }

  while(digitalRead(A) == LOW)
  {
    tone(Buzz,T_A);
    digitalWrite(LED,HIGH);
  }

  while(digitalRead(B) == LOW)
  {
    tone(Buzz,T_B);
    digitalWrite(LED,HIGH);
  }

  noTone(Buzz);
  digitalWrite(LED,LOW);

}


Aucun commentaire:

Enregistrer un commentaire

automatic dino game offline

here's a little game made by google chrome when the computer is offline.  thanks to arduino it possible to play it automatically without...