Program
Program
program # 4: buzzer
Equipment: Buzzer,Arduino UNO,Breadboard,
Code:
int buzzer=7;//set buzzer’s digital pin IO in control
void setup()
{
pinMode(buzzer,OUTPUT);//set digital pin IO OUTPUT
}
void loop()
{
unsigned char i,j;//define i j
while(1)
{
for(i=0;i<80;i++)// Output a frequency of sound }
program # 6: potentiometer
Equipment: Arduino UNO, Potentiometer, Breadboard, LED, Wires
Code:
int potpin = 0 ; //define analog pin0
int ledpin = 13 ; //define analog pin13
int val = 0 ; //set val is0.
void setup()
{
pinMode(ledpin,OUTPUT);//set analog pin13 output
Serial.begin(9600);//set baud rate 9600
}
void loop()
{
digitalWrite(ledpin,HIGH);//light up led in pin13
delay(50);//delay 0.05s
digitalWrite(ledpin,LOW);//go out led in pin13
delay(50);//delay 0.05s
val = analogRead(potpin);//give the value of pin0 to val
Serial.println(val) ; //print val’s value }
Program # 7 : Lcd
Equipment: LCD1602, Arduino UNO, Breadboard, Pot, Wires
Code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("hello, world!");
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis()/1000);
}
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
digitalWrite(9, HIGH);
}
void loop() {
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
delay(6000);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
delay(2000);
digitalWrite(10, LOW);
digitalWrite(11, HIGH);}