Projeto 1: “Olá mundo!” int val;// define variable val void setup() { Serial.begin(9600);// set the baud rate at 9600 to match the software settings. When connected to a specific device, (e.g. Bluetooth), the baud rate needs to be the same with it. } void loop() { val=Serial.read();// read the instruction or character from PC to Arduino, and assign them to Val. if(val=='R')// determine if the instruction or character received is “R” { // if it’s “R” Serial.println("Hello World!");// display “Hello World!” } } Projeto 2: “Quem está a piscar?” int ledPin = 11; // define digital pin 11 void setup() { pinMode(ledPin, OUTPUT);// define LED pin as output } void loop() { analogWrite(ledPin,255); //set the LED on, regulate light brightness, ranging from 0-255, 255 is the brightest delay(1000); // wait for a second digitalWrite(ledPin, LOW); // set the LED off delay(1000); // wait for a second } Projeto 3: Respiração visível int ledPin = 11; // define digital pin 11 void setup() { pinMode(ledPin, OUTPUT);// define LED pin as output } void loop() { for (int a=0; a<=255;a++)// set the LED to be brighter gradually { analogWrite(ledPin,a); // turn on LED, regulate light brightness, ranging from 0-255, 255 is the brightest delay(10); // wait for 0.01S } for (int a=255; a>=0;a--) // set LED to be dimming gradually { analogWrite(ledPin,a); // turn on LED, regulate light brightness, ranging from 0-255, 255 is the brightest delay(10); // wait for 0.01S } delay(1000);// wait for 1S } Projeto 4: Luz a fluir int BASE = 9 ; // the I/O pin for the first LED int NUM = 3; // number of LEDs void setup() { for (int i = BASE; i < BASE + NUM; i ++) { pinMode(i, OUTPUT); // set I/O pins as output } } void loop() { for (int i = BASE; i < BASE + NUM; i ++) { digitalWrite(i, HIGH); //set I/O pins as “high”, turn on LEDs one by one delay(200); // wait 0.2S } for (int i = BASE; i < BASE + NUM; i ++) { digitalWrite(i, HIGH); // set I/O pins as “low”, turn off LEDs one by one delay(200); // wait 0.2S } } Projeto 5: Fazer um som int buzzPin = 10; // Connect Buzzer to D10 void setup() { pinMode(buzzPin, OUTPUT); // set I/O pin as “output” } void loop() { digitalWrite(buzzPin, HIGH);// set digital I/O output as “high”, the buzzer will sound delay(500);// wait for 0.5S digitalWrite(buzzPin, LOW);// set digital I/O output as “low”, the buzzer will stop making sound delay(500); // wait for 0.5S } Projeto 6: “Quem está a cantar?” #define D0 -1 #define D1 262 #define D2 293 #define D3 329 #define D4 349 #define D5 392 #define D6 440 #define D7 494 #define M1 523 #define M2 586 #define M3 658 #define M4 697 #define M5 783 #define M6 879 #define M7 987 #define H1 1045 #define H2 1171 #define H3 1316 #define H4 1393 #define H5 1563 #define H6 1755 #define H7 1971 // List all D tune frequency #define WHOLE 1 #define HALF 0.5 #define QUARTER 0.25 #define EIGHTH 0.25 #define SIXTEENTH 0.625 // list all tempos int tune[]= // List each frequency according to numbered musical notation { M3,M3,M4,M5, M5,M4,M3,M2, M1,M1,M2,M3, M3,M2,M2, M3,M3,M4,M5, M5,M4,M3,M2, M1,M1,M2,M3, M2,M1,M1, M2,M2,M3,M1, M2,M3,M4,M3,M1, M2,M3,M4,M3,M2, M1,M2,D5,D0, M3,M3,M4,M5, M5,M4,M3,M4,M2, M1,M1,M2,M3, M2,M1,M1 }; float durt[]= // list all tempo according to numbered musical notation { 1,1,1,1, 1,1,1,1, 1,1,1,1, 1+0.5,0.5,1+1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1+0.5,0.5,1+1, 1,1,1,1, 1,0.5,0.5,1,1, 1,0.5,0.5,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,0.5,0.5, 1,1,1,1, 1+0.5,0.5,1+1, }; int length; int tonepin=8; // set module signal pin to D8 void setup() { pinMode(tonepin,OUTPUT); length=sizeof(tune)/sizeof(tune[0]); // calculate length } void loop() { for(int x=0;x170) { digitalWrite(ledpin, HIGH); // turn LED ON } else { digitalWrite(ledpin, LOW); // turn LED OFF } delay(100); } Projeto 9: Faça uma lâmpada controlada por luz int photopin=0;// set photocell sensor to A0 int ledpin=11;// set pin11 LED as PWM output to adjust the LED brightness int val=0;// define variable val void setup() { pinMode(ledpin,OUTPUT);// set digital pin 11 as output Serial.begin(9600);// set baud rate to 9600 } void loop() { val=analogRead(photopin);// read the analog value of the sensor and assign it to val Serial.println(val);// display val value analogWrite(ledpin,val/4);// turn on LED and set to maximum brightness(PWM output is 255) delay(10);// wait 0.01S } Projeto 10: Alarme de nível de água int analogPin = 1; // connect water sensor to analog interface 1 int buzzPin= 11; // buzzer to digital interface 11 int val = 0; // define the initial value of variable ‘val’ as 0 int data = 0; // define the initial value of variable ‘data’ as 0 void setup() { pinMode(buzzPin, OUTPUT); // define buzzer as output pin Serial.begin(9600); // set baud rate at 9600 } void loop() { val = analogRead(analogPin); // read and assign analog value to variable ’val’ if(val>400) { // decide whether variable ‘val’ is over 400 digitalWrite(buzzPin,HIGH); // turn on buzzer when variable ‘val’ is over 400 } else{ digitalWrite(buzzPin,LOW); // turn off buzzer when variable ‘val’ is under 400 } data = val; // variable ’val’ assigns value to variable ‘data’ Serial.println(data); // print variable ‘data’ by Serial.print delay(100); } Projeto 11:”Estou com sede” int analogPin = 1; // connect soil humidity sensor to analog interface 1 int buzzer= 11; // buzzer to digital interface 11 int val ; void setup() { pinMode(buzzer, OUTPUT); // define buzzer as output pin Serial.begin(9600); // set baud rate at 9600 } void loop() { val = analogRead(analogPin); // read and assign analog value to variable ’val’ Serial.print(val); // print variable ‘val’ by Serial.print if(val<=300) { { digitalWrite(buzzer,HIGH); } Serial.println(" dry soil"); delay(50); } if((val>300)&&(val<500)) { { digitalWrite(buzzer,LOW); } Serial.println(" humid soil"); delay(50); } if(val>=500) { { digitalWrite(buzzer,HIGH); } Serial.println(" in water"); delay(50); } delay(100); } Projeto 12: Valor analógico visível int rotatepin=0;// set rotation sensor to A0 int ledpin=11;// set pin11 LED as PWM output to adjust the LED brightness int val=0;// define variable val void setup() { pinMode(ledpin,OUTPUT);// set digital pin 11 as output Serial.begin(9600);// set baud rate to 9600 } void loop() { val=analogRead(rotatepin);// read the analog value of the sensor and assign it to val Serial.println(val);// display val value analogWrite(ledpin,val/4);// turn on LED and set to maximum brightness(PWM output is 255) delay(10);// wait 0.01S } Projeto 13: Deteção de campo magnético int rotatepin=0;// set rotation sensor to A0 int ledpin=11;// set pin11 LED as PWM output to adjust the LED brightness int val=0;// define variable val void setup() { pinMode(ledpin,OUTPUT);// set digital pin 11 as output Serial.begin(9600);// set baud rate to 9600 } void loop() { val=analogRead(rotatepin);// read the analog value of the sensor and assign it to val Serial.println(val);// display val value analogWrite(ledpin,val/4);// turn on LED and set to maximum brightness(PWM output is 255) delay(10);// wait 0.01S } Projeto 14: Deteção de colisão int ledpin=11;// set LED to D11 int inpin=9;// set sensor to D9 int val;// define variable val void setup() { pinMode(ledpin,OUTPUT);// set pin LED as output pinMode(inpin,INPUT);// set collision sensor as input } void loop() { val=digitalRead(inpin);// read value on pin 9 and assign it to val if(val==HIGH)// check if the switch on the module if in closed state; if Yes, turn on LED { digitalWrite(ledpin,LOW);} else { digitalWrite(ledpin,HIGH);} } Projeto 15: Lâmpada controlada por botão int ledpin=11;// set LED to pin D11 int inpin=9;// set button to pin D9 int val;// define variable val void setup() { pinMode(ledpin,OUTPUT);// set LED pin as “output” pinMode(inpin,INPUT);// set button pin as “input” } void loop() { val=digitalRead(inpin);// read the level value of pin 9 and assign it to val if(val==HIGH)// check if the button is pressed, if yes, turn on the LED { digitalWrite(ledpin,LOW);} else { digitalWrite(ledpin,HIGH);} } Projeto 16: Sensor Touch Ligação Easy int buzzPin = 11; //Connect Buzzer to Digital Pin11 int inputPin = 9; // Connect Touch sensor to Digital Pin 9 void setup() { pinMode(buzzPin, OUTPUT); // declare buzzer as output pinMode(inputPin, INPUT); // declare Touch sensor as input } void loop(){ int val = digitalRead(inputPin); // read input value if (val == HIGH) { // check if the input is HIGH digitalWrite(buzzPin, HIGH); // turn buzzer ON } else { digitalWrite(buzzPin, LOW); // turn buzzer OFF } } Projeto 17: Sensor Knock Ligação Easy int Led=11;//define LED interface int knock=9;//define knock sensor interface; int val;//define digital variable val void setup() { pinMode(Led,OUTPUT);//define LED pin to be output pinMode(knock,INPUT);//define knock sensor pin to be input } void loop() { val=digitalRead(knock);// read the value of interface9 and assign it to val if(val==HIGH)// when the knock sensor detect a signal, LED will turn on { digitalWrite(Led,LOW); } else { digitalWrite(Led,HIGH); } } Projeto 18: Sensor de Inclinação Digital Ligação Easy int ledPin = 11; // Connect LED to pin 11 int tilt = 9; // Connect Tilt sensor to Pin9 void setup() { pinMode(ledPin, OUTPUT); // Set digital pin 11 as output pinMode(tilt, INPUT); // Set digital pin 9 as input } void loop() { if(digitalRead(tilt)==HIGH) //Read sensor value { digitalWrite(ledPin, HIGH); // Turn on LED when the sensor is triggered } else { digitalWrite(ledPin, LOW); // Turn off LED when the sensor is not triggered } } Projeto 19: Alarme de Incêndio const int flamePin = 3; // the number of the flame pin const int buzzPin = 11; // the number of the buzzer pin // variables will change: int State = 0; // variable for reading status void setup() { // initialize the buzzer pin as an output: pinMode(buzzPin, OUTPUT); // initialize the flame pin as an input: pinMode(flamePin, INPUT); } void loop(){ // read the state of the value: State = digitalRead(flamePin); if (State == HIGH) { // turn buzzer on: digitalWrite(buzzPin, HIGH); } else { // turn buzzer off: digitalWrite(buzzPin, LOW); } } Projeto 20: Alarme de vibração #define buzzPin 11 #define SensorINPUT 3 //Connect the sensor to digital Pin 3 which is Interrupt 1. unsigned char state = 0; void setup() { pinMode(buzzPin, OUTPUT); pinMode(SensorINPUT, INPUT); attachInterrupt(1, blink, FALLING);// Trigger the blink function when the falling edge is detected } void loop() { if(state!=0) { state = 0; digitalWrite(buzzPin,HIGH); delay(500); } else digitalWrite(buzzPin,LOW); } void blink()//Interrupts function { state++; } Projeto 21: Detector de campo magnético int buzzPin = 11; // Connect Buzzer on Digital Pin11 int reedpin= 3; // define reed switch sensor interface int val;// define digital variable val void setup() { pinMode(buzzPin,OUTPUT);// define buzzer as output interface pinMode(buttonpin,INPUT);// define reed switch sensor as output interface } void loop() { val=digitalRead(reedpin);// read and assign the value of digital interface 3 to val if(val==HIGH)// When a signal is detected by reed switch sensor,Buzzer will on { digitalWrite(buzzPin,LOW); } else { digitalWrite(buzzPin,HIGH); } } Projeto 22: Alarme da temperatura int buzzPin = 10; int ledpin= 11; void setup() { Serial.begin(9600);// Set Baud Rate to 9600 bps pinMode(ledpin,OUTPUT);// define LED as output pinMode(buzzPin,OUTPUT);// define buzzer as output } void loop() { int val; int dat; val=analogRead(0);// Connect LM35 on Analog 0 dat=(500 * val) /1024; Serial.print("Temp:"); // Display the temperature on Serial monitor Serial.print(dat); Serial.println("C"); if (dat>25) // when temperature is higher than 25℃, LED will be turned on, and buzzer will ring { digitalWrite(buzzPin, HIGH); // turn buzzer ON digitalWrite(ledpin, HIGH); // turn LED ON } else { digitalWrite(buzzPin, LOW); // turn buzzer OFF digitalWrite(ledpin, LOW); // turn LED OFF } delay(500); }