1 of 39

CODING CELEBRATION FOR ARDUINO

2 of 39

CODING CELEBRATION FOR ARDUINO

By Jawad Fadlallah

EduTech Engineer - Studio5 Qatar

3 of 39

CODING CELEBRATION FOR ARDUINO

By Jawad Fadlallah

EduTech Engineer - Studio5 Qatar

4 of 39

Who are we?

Studio 5 is an initiative by the Ministry of Communications and Information Technology. We cater to youth aged 7-24 in Qatar to facilitate the Digital Revolution within the Qatari society and community in providing the youth with knowledge and skills in digital fabrication and emerging technology. The dedicated space aims to trigger a mindset shift in the youth in Qatar from consumers to creators and innovators.

ستوديو 5 مبادرة من وزارة الاتصالات وتكنولوجيا المعلومات. نحن نلبي احتياجات الشباب الذين تتراوح أعمارهم بين 7 و24 عامًا في قطر لتسهيل الثورة الرقمية داخل المجتمع والمجتمع القطري في تزويد الشباب بالمعرفة والمهارات في مجال التصنيع الرقمي والتكنولوجيا الناشئة. تهدف المساحة المخصصة إلى إحداث تحول عقلي لدى الشباب في قطر من مستهلكين إلى مبدعين ومبتكرين.

مـن نـحــــــــــــــن؟

5 of 39

Our Team

TASNEEM HUSSAIN

Project Manager

ILARIA LA MANNA

Senior Education Specialist

ZAID ABUSINI

Senior EduTech Engineer

MOHAMMED MOHAMMED

EduTech Engineer

LEYLA TAWIFIK

Senor BioEduTech Interaction Designer

SOUMIA DEDECHE

Assistant BioEduTech

FAHEEM KHAN

EduTech Designer

AYAH ELNOUR

Assistant EduTech

JAWAD FADLALLAH

EduTech Engineer

MAHMOUD AL RAWABDEH

Technician Engineer

6 of 39

Fabrication Laboratory

مختـبـــــــر التصنـيـــــــــع

Is a place to play, to create, to learn, to mentor, to invent: �A place for learning and innovation.

هو مكان للعب، الصناعة، التعلم، التوجيه، والاختراع: �مكان للتعلم والابتكار.

What is a

ما هو

7 of 39

طباعة ثلاثية الأبعاد

القص بالليزر

آلة الحفر

بالتحكم العددي بالكمبيوتر

AND MUCH MORE…

3D PRINTING

LASER CUTTING

CNC milling machine

(Computer numerical control)

وأكثر من ذلك بكثير...

8 of 39

منطقة الإبداع

منطقة البرمجيات

منطقة التكنولوجيا

منطقة التحقيق

Creativity Zone

Software Zone

Technology Zone

Investigation Zone

9 of 39

10 of 39

What is Arduino ?

Arduino is an open-source electronics platform based on easy-to-use hardware and software.

It's intended for anyone making interactive projects.

Arduino consists of both a physical programmable circuit board and software

11 of 39

منطقة الإبداع

منطقة البرمجيات

منطقة التكنولوجيا

منطقة التحقيق

Creativity Zone

Software Zone

Technology Zone

Investigation Zone

12 of 39

How to use Google Meet

Mute/Un-mute

Share Screen

Raise your hand

Chat

13 of 39

How to use Microsoft Teams

Mute/Un-mute

Share Screen

Raise your hand

Chat

14 of 39

ما هي فوائد هذه الورشة في نظرك؟

What are the benefits of this workshop in your opinion?

لماذا نقوم بهذه الورشة؟

Why are we doing this workshop?

?

?

?

  • Learn Arduino
  • Create electronic circuits
  • Code electronic circuit
  • تعلم الاردوينو
  • إنشاء الدوائر الإلكترونية
  • برمجة الدوائر الإلكترونية

15 of 39

https://www.youtube.com/watch?v=o9-cCMDXWl8

16 of 39

Introduction to WOKWI

https://wokwi.com/

Free* website with simulator to learn and apply Arduino coding skills

موقع مجاني* مزود بجهاز محاكاة لتعلم وتطبيق مهارات برمجة Arduino

17 of 39

Sign up / Sign in

Sign up / Sign in screen using any of the available ways

شاشة التسجيل / تسجيل الدخول باستخدام أي من الطرق المتاحة

You can also use Wokwi as a Guest without creating your own account, but you will not be able to save your project

يمكنك أيضًا استخدام Wokwi كضيف دون إنشاء حساب خاص بك، ولكنك لن تتمكن من حفظ مشروعك

18 of 39

Access to My Projects

Step 1: Click on you Profile Picture

Step 2: Select “<> My Projects

الخطوة 1: انقر على صورة ملفك الشخصي

الخطوة 2: انقر على "<> My Projects"

Step 1

Step 2

19 of 39

Some Examples of What Can be done …

بعض الأمثلة على ما يمكن القيام به …

& Much More …

20 of 39

Bigger Scale Project, Piano Project in Qanat Quartier, Qatar …

21 of 39

What we will do today in this workshop

ماذا سنفعل اليوم في هذه الورشة

We will create a Happy Birthday Arduino using:

  • Arduino Uno
  • Buzzer
  • Potentiometer
  • Code

سنقوم بإنشاء عيد ميلاد سعيد لـ Arduino باستخدام:

  • Arduino Uno
  • Buzzer
  • Potentiometer
  • Code

Buzzer

Potentiometer

Arduino UNO

22 of 39

New project / Your Projects

Saved / Old projects

المشاريع المحفوظة / القديمة

Create New project

إنشاء مشروع جديد

23 of 39

Create New Arduino project

Step 1: Select Arduino

الخطوة الأولى: اختر Arduino

Step 2: Select Arduino Uno Rev3

الخطوة 2: حدد Arduino Uno Rev3

24 of 39

New blank project … Ready !

Now you have a Blank Workspace to create something with Arduino

الآن لديك مساحة عمل فارغة لإنشاء شيء ما باستخدام Arduino

Arduino Code Section

Arduino Simulation Section

25 of 39

New project - Add Your Components

Step 1: Click on the + sign to add your desired components

Step 2: Write any component name in the Search bar to find it, or just scroll down in the list.

الخطوة 1: انقر فوق علامة + لإضافة المكونات المطلوبة

الخطوة 2: اكتب اسم أي مكون في شريط البحث للعثور عليه، أو قم بالتمرير لأسفل القائمة.

Step 1

Step 2

26 of 39

New project - Add Your Components

Step 1: Search for BUZZER

Step 2: Click on the BUZZER component to add it in the simulation section.

Do the same for POTENTIOMETER

الخطوة 1: ابحث عن BUZZER

الخطوة 2: انقر على مكون BUZZER لإضافته في قسم المحاكاة.

افعل نفس الشيء بالنسبة لـ POTENTIOMETER

Step 1

Step 2

27 of 39

New project - Add Your Components

Now all your needed components are in the simulator!

Next step is to connect them all together.

الآن أصبحت جميع المكونات المطلوبة موجودة في جهاز المحاكاة!

والخطوة التالية هي توصيلها جميعًا معًا.

28 of 39

New project - Let’s connect our components!

Buzzer Connection:

Step 1: Connect the Black pole (Negative Pole) to GND

Step 2: Connect the Red pole (Positive Pole) to PIN 10

توصيل الجرس:

الخطوة 1: قم بتوصيل القطب الأسود (القطب السالب) بـ GND

الخطوة 2: قم بتوصيل القطب الأحمر (القطب الموجب) بالدبوس PIN 10

Potentiometer Connection:

Step 1: Connect the GND pin (Negative Pole) to GND

Step 2: Connect the VCC pin (Positive Pole) to 5V

Step 3: Connect the SIG pin (Positive Pole) to A0

توصيل مقياس الجهد:

الخطوة 1: قم بتوصيل دبوس GND (القطب السالب) بـ GND

الخطوة 2: قم بتوصيل دبوس VCC (القطب الموجب) بـ 5 V

الخطوة 3: قم بتوصيل دبوس SIG (القطب الموجب) بـ A0

29 of 39

Connection DONE!

Now Let’s CODE!

30 of 39

First thing to do is to Create and Define what we need!

Pins… initial values… notes… notes sequence… notes duration…

أول شيء يجب فعله هو إنشاء وتحديد ما نحتاجه!

الدبابيس... القيمة الأولية... النوتات الموسيقية... تسلسل النوتات الموسيقية... مدة النوتات الموسيقية…

Coding: Define and Create …

int buzzerPin = 10;

int potPin = 0;

float potValue = 0.0;

float newSpeed = 1.0;

#define N_C4 262 //DO

#define N_D4 294 //RE

#define N_E4 330 //MI

#define N_F4 349 //FA

#define N_G4 392 //SOL

#define N_A4 440 //LA

#define N_B4 494 //SI

#define N_C5 523 //DO

#define N_D5 587 //RE

#define N_E5 659 //MI

#define N_F5 698 //FA

#define N_G5 784 //SOL

#define N_A5 880 //LA

#define N_B5 988 //SI

Buzzer Pin

Potentiometer Pin

Create 2 variables to hold the pot and new speed values

Those are the musical notes frequencies that will be played in Arduino as tones!

Each note has a Name and a Value (frequency)

هذه هي ترددات النوتات الموسيقية التي سيتم تشغيلها في Arduino كنغمات!

كل نغمة لها اسم وقيمة (تردد)

31 of 39

Now we have to create 2 arrays:

  • Array 1: musical notes FREQUENCIES sequence of Happy Birthday
  • Array 2: musical notes DURATION sequence of Happy Birthday

الآن يتعين علينا إنشاء مصفوفتين:

المصفوفة 1: تسلسل النوتات الموسيقية FREQUENCIES لأغنية Happy Birthday

المصفوفة 2: تسلسل النوتات الموسيقية DURATION لأغنية Happy Birthday

Coding: Define and Create …

This is the array of the musical notes frequencies that will be played

هذه هي ترددات النوتات الموسيقية التي سيتم تشغيلها

Each musical note will have a different specific duration in this array

كل نغمة موسيقية سيكون لها مدة محددة مختلفة في هذه المجموعة

// G G A G C B --- SOL SOL LA SOL DO SI

// G G A G D C --- SOL SOL LA SOL RE DO

// G G G E C B A --- SOL SOL SOL MI DO SI LA

// F F E C D C --- FA FA MI DO RE DO

int b_day_notes[] = {

N_G4, 0, N_G4, N_A4, N_G4, 0, N_C5, N_B4, 0,

N_G4, 0, N_G4, N_A4, N_G4, 0, N_D5, N_C5, 0,

N_G4, 0, N_G4, N_G5, N_E5, N_C5, N_B4, N_A4, 0,

N_F5, 0, N_F5, N_E5, N_C5, N_D5, N_C5, 0

};

int note_duration[] = {

250, 125, 125, 500, 500, 25, 500, 500, 500,

250, 125, 125, 500, 500, 25, 500, 500, 500,

250, 125, 125, 500, 500, 500, 500, 500, 500,

250, 125, 125, 500, 500, 500, 500, 500

};

32 of 39

void setup()is where you initialize, assign and link PINs to Variables

هو المكان الذي يمكنك فيه تهيئة الدبابيس وتعيينها وربطها بالمتغيرات void setup()

Coding: SETUP() function

potValue will store the potPin value

سيقوم potValue بتخزين قيمة potPin

Mapfloat will map the potentiometer value on a smaller scale and store it in songSpeed

سيتم رسم قيمة مقياس الجهد على نطاق أصغر باستخدام mapFloat وتخزينها في songSpeed

void setup()

{

potValue = analogRead(potPin);

songSpeed = mapfloat(potValue , 1, 1023, 0.7, 1.5);

}

33 of 39

void loop()

{

int totalNotes = sizeof(b_day_notes);

for (int i = 0; i < totalNotes; i++)

{ int currentNote = b_day_notes[i];

float wait = note_duration[i] / songSpeed;

potValue = analogRead(potPin);

songSpeed= mapfloat(potValue , 1, 1023, 0.7, 1.5);

if (currentNote != 0) // Play tone if current Note is not 0 HZ

{ // tone(pin, frequency, duration)

tone(buzzerPin, b_day_notes[i], wait); }

else

{ noTone(buzzerPin); }

delay(wait); // delay between tones

}

}

void loop()is where all the fun happens

هذا هو المكان الذي يحدث فيه كل المرح void loop()

Coding: LOOP() function

Get the total notes count to use inside the FOR LOOP from the array

CurrentNote is retrieving notes from the array following “i” value

Keep reading the Potentiometer value to modify the song speed accordingly

If the note is not ZERO, play it on the buzzer and wait

34 of 39

CODING CELEBRATION FOR ARDUINO full code (part 1)

int buzzerPin = 10;

int potPin = 0;

float potValue = 0.0;

float songSpeed = 1.0;

#define N_C4 262 //DO

#define N_D4 294 //RE

#define N_E4 330 //MI

#define N_F4 349 //FA

#define N_G4 392 //SOL

#define N_A4 440 //LA

#define N_B4 494 //SI

#define N_C5 523 //DO

#define N_D5 587 //RE

#define N_E5 659 //MI

#define N_F5 698 //FA

#define N_G5 784 //SOL

#define N_A5 880 //LA

#define N_B5 988 //SI

// G G A G C B --- SOL SOL LA SOL DO SI

// G G A G D C --- SOL SOL LA SOL RE DO

// G G G E C B A --- SOL SOL SOL MI DO SI LA

// F F E C D C --- FA FA MI DO RE DO

int b_day_notes[] = {

N_G4, 0, N_G4, N_A4, N_G4, 0, N_C5, N_B4, 0,

N_G4, 0, N_G4, N_A4, N_G4, 0, N_D5, N_C5, 0,

N_G4, 0, N_G4, N_G5, N_E5, N_C5, N_B4, N_A4, 0,

N_F5, 0, N_F5, N_E5, N_C5, N_D5, N_C5, 0

};

int note_duration[] = {

250, 125, 125, 500, 500, 25, 500, 500, 500,

250, 125, 125, 500, 500, 25, 500, 500, 500,

250, 125, 125, 500, 500, 500, 500, 500, 500,

250, 125, 125, 500, 500, 500, 500, 500

};

35 of 39

CODING CELEBRATION FOR ARDUINO full code (part 2)

void setup()

{ potValue = analogRead(potPin);

songSpeed = mapfloat(potValue , 1, 1023, 0.7, 1.5);

}

void loop()

{

int totalNotes = sizeof(b_day_notes) / sizeof(int);

for (int i = 0; i < totalNotes; i++)

{ int currentNote = b_day_notes[i];

float wait = note_duration[i] / songSpeed;

potValue = analogRead(potPin);

songSpeed= mapfloat(potValue , 1, 1023, 0.7, 1.5);

if (currentNote != 0) // Play tone if current Note is not 0 HZ

{ // tone(pin, frequency, duration)

tone(buzzerPin, b_day_notes[i], wait); }

else

{ noTone(buzzerPin); }

delay(wait); // delay between tones

}

}

MAPFLOAT function is the same as MAP function, but it also deals with Decimals.

It is the procedure of getting the new value on a new scale for a given old value on an older scale

دالة MAPFLOAT هي نفس دالة MAP، ولكنها تتعامل أيضًا مع الأعداد العشرية. إنها عملية الحصول على القيمة الجديدة على مقياس جديد لقيمة قديمة معينة من مقياس أقدم

float mapfloat(float in_sensor, float in_min, float in_max, float out_min, float out_max)

{ return (in_sensor - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;}

36 of 39

37 of 39

38 of 39

39 of 39