Posts

Lesson 10: Piezo Buzzer controlled with Potentiometer

Image
Here we are. Now we are going to connect previous lesson device and this week device. Here is the scheme: Yeah, the connection is very simple. Code a bit different than in Lesson 6 . Find out what we have to change from previous Lesson 6? #define bz 3 #define pot A0 void setup(){ pinMode(bz, OUTPUT); pinMode(pot, INPUT); } int x; void loop(){ // read value of Potentiometer // as you remember A0-A5 pins working in range of 0-1023 // but analog TONE range is 31-4900 // to get correct result we will multiply result to 4 x = analogRead(pot) * 4; // set tone to new value tone(bz, x); } Self study: Give to students 2 set of buttons (with 10K Ohm resistor). And ask to do kind of piano with 2 buttons. Good luck! For the help about Buttons you may look to previous lesson: Lesson 4 .

Lesson 9: Piezo Buzzer

Image
Hello folks. We continue to our Arduino basics, and today on this lesson we will learn about Piezo Buzzer. This is a kind of a speaker but much simple. It has membrane with "tone()" command and "noTone()" commands. We can control its tone. As you see on the picture Buzzer has + side and it means another side is for GND (-) ground. + side is connected to any analog outputs like ~3, ~5, ~6, ~9, ~10, ~11. Tone range for this Piezo Buzzer is between 31 and 4900. Let's make a scheme. Here is basic connection. But I've also seen a connection with 100 Ohm resistor on + side. Code: void setup() {   pinMode(3, OUTPUT); } void loop() {   tone(3,500); //put tone to 500 Hz   delay(500); //wait 1 second   noTone(3); //stop tone   delay(200); } By the way, there will be difference in tone sound for different Piezo Buzzers, even in your kit. And at the last you may see on different melody examples on Piezo Buzzer in Internet. Here is some of the

Lesson 8: Servo plus (+) Potentiometer. Let's rock it!!!

Image
This is a practice lesson. Let's look back in Potentiometer lesson and find out how to make a connection with controlled rotation of Servo motor. Please, be kind and do not forget that Servo is OUTPUT device, and Potentiometer is INPUT device. Which means we use Potentiometer to control Servo, not wise versa. Before you write or copy the code, please look to "float x" value and explain why do we divide value of A0 to 5.6? Explain what is "int(x)" operation do. #include <Servo.h> Servo s; void setup() {   s.attach(3);   pinMode(A0, INPUT); } float x; void loop() {   x = analogRead(A0)/5.6;   s.write(int(x)); }

Lesson 7: Working with Servo

Image
In this lesson we will work with basic Servo motor. Model Tower Pro SG90. This is angle rotation controlled motor. Which rotation angle is between 0 and 180 degrees. Connection consist of 3 pins: Brown wire is for GND (-), Red wire is for 5V (+), and Orange wire is for signal input. Ok, let's make simple connection Servo motor to Arduino. When you connect this scheme. You need to write a program. But before writing or copying this program, I want you to make notice about <Servo.h> library. Instead of "pinMode()" command we will use "attach()" command. #include <Servo.h> Servo s1; void setup() {   // here is like pinMode command, but we firstly attach 3rd pin to Servo   s1.attach(3); } void loop() {   // put your main code here, to run repeatedly:   s1.write(0); //put Servo to 0 angle degrees   delay(2000);   s1.write(180); //put Servo to 180 angle degrees   delay(2000); } Self study::: Now, please try to add 2 buttons.

Lesson 6: Potentionmeter & LED

Image
This lesson is about a Controlled LED brightness using   Potentiometer .  In our model, the brightness of the LED will depend on the rotation of the  potentiometer  knob. This is also one of the basic schemes. Link to original lesson: http://edurobots.ru/2014/04/arduino-potenciometr/ Hardware parts for this lesson: Arduino board Breadboard LED 220 Ohm resistor Jumpers (wires) Potentiometer Scheme on breadboard: Program code for this project: #define led 9 #define pot A0 void setup(){ pinMode(led, OUTPUT); pinMode(pot, INPUT);         Serial.begin(9600); } void loop(){ int x; // read value of Potentiometer // as you remember A0-A5 pins working in range of 0-1023 // but analog INPUT/OUTPUT pins range is 0-255 // to get correct result we will divide result to 4 x = analogRead(pot) / 4;         Serial.print("X=");         Serial.println(x); // show result on LED analogWrite(led, x); } Task for Advanced students: Giv

Lesson 5: Potentiometer

Image
A  potentiometer  is a variable resistor with adjustable resistance.  Potentiometers  are used in robotics as regulators of various parameters - volume of sound, power, voltage, etc.  In this lesson we will connect potentiometer to Arduino, and look to its signal values through 'Serial monitor'. Scheme on breadboard: Upload this code, and open 'Serial Monitor' in Arduino IDE application. Then rotate Potentiometer to see changes: void setup() {   //initialize A0 port as INPUT   pinMode(A0, INPUT);   //initialize Serial port to 9600   Serial.begin(9600); } void loop() {   //print the result of Potentiometer in Serial monitor   Serial.println(analogRead(A0));   //wait 2 seconds   delay(2000); }

Lesson 4: Traffic light control

Image
Like in Lesson 2 you'll need to make Traffic light project. But there will be one small difference: we need to add 3 buttons, to control lights (red, yellow, green). Hardware parts for this lesson: Arduino board Breadboard LED, 3 pieces 220 Ohm Resistors, 3 pieces Jumpers Buttons, 3 pieces 10K Ohm Resistors, 3 pieces Give time to students to write a code. After construction of the model, you give 10 minutes to finish the code. And in the end show your version of code: int b1 = 2; int b2 = 3; int b3 = 4; int led1 = 11; int led2 = 12; int led3 = 13; void setup() {     pinMode(led1, OUTPUT);     pinMode(led2, OUTPUT);   pinMode(led3, OUTPUT);     pinMode(b1, INPUT);   pinMode(b2, INPUT);   pinMode(b3, INPUT); } void loop(){     if (digitalRead(b1) == HIGH) {             digitalWrite(led1, HIGH);     }     else if(digitalRead(b2) == HIGH){             digitalWrite(led2, HIGH);     }   else if(digitalRead(b3)