Learn Arduino With TinkerCad - Day 2 PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

Learn Arduino with

TinkerCad
Day 2

Mohd.Ruhul Ameen
ameensunny242@gmail.com
Mobile: +880 1521 300 804
Buzzer

A buzzer or beeper is an audio signalling


device, which may be mechanical,
electromechanical, or piezoelectric.
Typical uses of buzzers and beepers
include alarm devices, timers, and
confirmation of user input such as a
mouse click or keystroke.
BUZZER BLINK

void setup(){

pinMode(13, OUTPUT);

void loop(){

digitalWrite(13, HIGH);

delay(1000); // Wait for 1000 millisecond(s)

digitalWrite(13, LOW);

delay(1000); // Wait for 1000 millisecond(s)

}
tone();

Syntax

tone(pin, frequency)

tone(pin, frequency, duration)

https://www.arduino.cc/reference/en/language/functions/advanced-io/tone/
Play a Melody using the tone() function
void setup() {}

void loop() { আপনাদের কাজঃ (এখন


tone(8, 256);
delay(1000); করদেন) ট ান ও ডিদে েযোার
tone(8, 512); কদর ৮ া ডিদকাদেডি ডিগুন
delay(1000);

tone(8, 1024, 2000);


কদর টে করদে থাকদেন।
}
#include "pitches.h"

// notes in the melody:


int melody[] = {
NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};

// note durations: 4 = quarter note, 8 = eighth note, etc.:


int noteDurations[] = {
4, 8, 8, 4, 4, 4, 4, 4
};

void setup() {

void loop() {

// iterate over the notes of the melody:


for (int thisNote = 0; thisNote < 8; thisNote++) {

// to calculate the note duration, take one second divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / noteDurations[thisNote];
tone(8, melody[thisNote], noteDuration);

// to distinguish the notes, set a minimum time between them.


// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(8);
}

}
https://gist.githubusercontent.com/mikeputnam/2820675/raw/bbe995aa22826
a8fbbb6b56ccd56513f9db6cb00/pitches.h

https://github.com/ameenruhul/ArduinoBuzzer/blob/master/Arduino
HBDTone/ArduinoHBDTone.ino
Use Pin 9 Or change in the code

Home Work :
1) https://github.com/ameenruhul/AmarSonarBangla/blob/master/AmarSonarBangla.ino
2) https://github.com/munem-shahriar/Tone-RomjanerOiRojarSheshe-
Arduino/blob/master/RomjanerOiRojarShesheEloKhushirEid/RomjanerOiRojarShesheEloKhushi
rEid.ino
Pushbuttons
int buzzPin = 13;

int inputPin = 7;

void setup(){

Serial.begin(9600);

pinMode(buzzPin, OUTPUT); // declare LED as output

pinMode(inputPin, INPUT); // declare push button as input

void loop(){

int pushed = digitalRead(inputPin); // read input value

Serial.println(pushed);

if (pushed == HIGH) // check if the input is HIGH

digitalWrite(buzzPin, HIGH);

digitalWrite(buzzPin, LOW);

}
টাামওোকক ঃ ডমউডজকাে কীদোিক
Potentiometer
int sensorValue = 0;

void setup()
{
pinMode(A0, INPUT);
pinMode(9, OUTPUT);
Serial.begin(9600);
}

void loop()
{
// read the value from the sensor
sensorValue = analogRead(A0);
Serial.println(sensorValue);
// turn the LED on
analogWrite(9, sensorValue);
}
টেিদরর জগৎ
Tmp36
2^10 = 1024
Arduino ADC (analog to digital converter) is 10 bit
Can Show values upto 0 - 1023

Voltage at pin in milliVolts = (reading from ADC) * (5000/1024)

Centigrade temperature = [(analog voltage in mV) - 500] / 10


int sensorPin = 0;
void setup(){
Serial.begin(9600);
}

void loop()
{
int reading = analogRead(sensorPin);

float voltage = reading * 5.0;


voltage /= 1024.0;

Serial.print(voltage); Serial.println(" volts");

float temperatureC = (voltage - 0.5) * 100 ;


Serial.print(temperatureC); Serial.println(" degrees C");

}
H/W : LDR
আদোর উপডিডেদে এেইডি েন্ধ াদে যাদে
আদো না থাকদে এেইডি জ্বদে যাদে
Servo Motor
#include <Servo.h>

Servo myservo; // create servo object to control a servo


// twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position

void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}

void loop() {
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in
variable 'pos'
delay(15); // waits 15ms for the servo to
reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in
variable 'pos'
delay(15); // waits 15ms for the servo to
reach the position
}
}

You might also like